Skip to content

Commit d0b62a1

Browse files
authored
Merge branch 'main' into ochafik/say-server
2 parents ffd6035 + f3b3c48 commit d0b62a1

40 files changed

Lines changed: 738 additions & 151 deletions

File tree

examples/basic-host/src/implementation.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RESOURCE_MIME_TYPE, getToolUiResourceUri, type McpUiSandboxProxyReadyNotification, AppBridge, PostMessageTransport, type McpUiResourceCsp, type McpUiResourcePermissions, buildAllowAttribute, type McpUiUpdateModelContextRequest, type McpUiMessageRequest } from "@modelcontextprotocol/ext-apps/app-bridge";
22
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
34
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
45
import type { CallToolResult, Tool } from "@modelcontextprotocol/sdk/types.js";
56

@@ -24,11 +25,8 @@ export interface ServerInfo {
2425

2526

2627
export async function connectToServer(serverUrl: URL): Promise<ServerInfo> {
27-
const client = new Client(IMPLEMENTATION);
28-
2928
log.info("Connecting to server:", serverUrl.href);
30-
await client.connect(new StreamableHTTPClientTransport(serverUrl));
31-
log.info("Connection successful");
29+
const client = await connectWithFallback(serverUrl);
3230

3331
const name = client.getServerVersion()?.name ?? serverUrl.href;
3432

@@ -39,6 +37,28 @@ export async function connectToServer(serverUrl: URL): Promise<ServerInfo> {
3937
return { name, client, tools, appHtmlCache: new Map() };
4038
}
4139

40+
async function connectWithFallback(serverUrl: URL): Promise<Client> {
41+
// Try Streamable HTTP first (modern transport)
42+
try {
43+
const client = new Client(IMPLEMENTATION);
44+
await client.connect(new StreamableHTTPClientTransport(serverUrl));
45+
log.info("Connected via Streamable HTTP transport");
46+
return client;
47+
} catch (streamableError) {
48+
log.info("Streamable HTTP failed:", streamableError);
49+
}
50+
51+
// Fall back to SSE (deprecated but needed for older servers)
52+
try {
53+
const client = new Client(IMPLEMENTATION);
54+
await client.connect(new SSEClientTransport(serverUrl));
55+
log.info("Connected via SSE transport");
56+
return client;
57+
} catch (sseError) {
58+
throw new Error(`Could not connect with any transport. SSE error: ${sseError}`);
59+
}
60+
}
61+
4262

4363
interface UiResourceData {
4464
html: string;

examples/basic-server-preact/src/global.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ html, body {
1010
code {
1111
font-size: 1em;
1212
}
13+
14+
/* Server time fills remaining width for consistent E2E screenshot masking */
15+
#server-time {
16+
flex: 1;
17+
min-width: 0;
18+
}

examples/basic-server-preact/src/mcp-app.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
margin-top: 0.5rem;
2929
}
3030

31+
/* Server time row: flex layout for consistent mask width in E2E tests */
32+
> p {
33+
display: flex;
34+
align-items: baseline;
35+
gap: 0.25em;
36+
}
37+
3138
/* Consistent font for form inputs (inherits from global.css) */
3239
textarea,
3340
input {

examples/basic-server-react/src/global.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ html, body {
1010
code {
1111
font-size: 1em;
1212
}
13+
14+
/* Server time fills remaining width for consistent E2E screenshot masking */
15+
#server-time {
16+
flex: 1;
17+
min-width: 0;
18+
}

examples/basic-server-react/src/mcp-app.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
margin-top: 0.5rem;
2929
}
3030

31+
/* Server time row: flex layout for consistent mask width in E2E tests */
32+
> p {
33+
display: flex;
34+
align-items: baseline;
35+
gap: 0.25em;
36+
}
37+
3138
/* Consistent font for form inputs (inherits from global.css) */
3239
textarea,
3340
input {

examples/basic-server-solid/src/global.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ html, body {
1010
code {
1111
font-size: 1em;
1212
}
13+
14+
/* Server time fills remaining width for consistent E2E screenshot masking */
15+
#server-time {
16+
flex: 1;
17+
min-width: 0;
18+
}

examples/basic-server-solid/src/mcp-app.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
margin-top: 0.5rem;
2929
}
3030

31+
/* Server time row: flex layout for consistent mask width in E2E tests */
32+
> p {
33+
display: flex;
34+
align-items: baseline;
35+
gap: 0.25em;
36+
}
37+
3138
/* Consistent font for form inputs (inherits from global.css) */
3239
textarea,
3340
input {

examples/basic-server-svelte/src/App.svelte

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ async function handleOpenLink() {
162162
margin-top: 0.5rem;
163163
}
164164
165+
/* Server time row: flex layout for consistent mask width in E2E tests */
166+
> p {
167+
display: flex;
168+
align-items: baseline;
169+
gap: 0.25em;
170+
}
171+
165172
textarea,
166173
input {
167174
font-family: inherit;
@@ -196,4 +203,10 @@ async function handleOpenLink() {
196203
font-style: normal;
197204
}
198205
}
206+
207+
/* Server time fills remaining width for consistent E2E screenshot masking */
208+
:global(#server-time) {
209+
flex: 1;
210+
min-width: 0;
211+
}
199212
</style>

examples/basic-server-vanillajs/src/global.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ html, body {
1010
code {
1111
font-size: 1em;
1212
}
13+
14+
/* Server time fills remaining width for consistent E2E screenshot masking */
15+
#server-time {
16+
flex: 1;
17+
min-width: 0;
18+
}

examples/basic-server-vanillajs/src/mcp-app.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
margin-top: 0.5rem;
2929
}
3030

31+
/* Server time row: flex layout for consistent mask width in E2E tests */
32+
> p {
33+
display: flex;
34+
align-items: baseline;
35+
gap: 0.25em;
36+
}
37+
3138
/* Consistent font for form inputs (inherits from global.css) */
3239
textarea,
3340
input {

0 commit comments

Comments
 (0)