Skip to content

Commit 4736621

Browse files
authored
Merge pull request #97 from jonathanhefner/running-all-examples
Add `examples/run-all.ts` script
2 parents 94d45a1 + d11b656 commit 4736621

File tree

8 files changed

+259
-158
lines changed

8 files changed

+259
-158
lines changed

examples/basic-host/serve.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const __dirname = dirname(__filename);
1818
const HOST_PORT = parseInt(process.env.HOST_PORT || "8080", 10);
1919
const SANDBOX_PORT = parseInt(process.env.SANDBOX_PORT || "8081", 10);
2020
const DIRECTORY = join(__dirname, "dist");
21+
const SERVERS: string[] = process.env.SERVERS ? JSON.parse(process.env.SERVERS) : [];
2122

2223
// ============ Host Server (port 8080) ============
2324
const hostApp = express();
@@ -34,6 +35,11 @@ hostApp.use((req, res, next) => {
3435

3536
hostApp.use(express.static(DIRECTORY));
3637

38+
// API endpoint to get configured server URLs
39+
hostApp.get("/api/servers", (_req, res) => {
40+
res.json(SERVERS);
41+
});
42+
3743
hostApp.get("/", (_req, res) => {
3844
res.redirect("/index.html");
3945
});
@@ -70,15 +76,15 @@ sandboxApp.use((_req, res) => {
7076
});
7177

7278
// ============ Start both servers ============
73-
hostApp.listen(HOST_PORT, err => {
79+
hostApp.listen(HOST_PORT, (err) => {
7480
if (err) {
7581
console.error("Error starting server:", err);
7682
process.exit(1);
7783
}
7884
console.log(`Host server: http://localhost:${HOST_PORT}`);
7985
});
8086

81-
sandboxApp.listen(SANDBOX_PORT, err => {
87+
sandboxApp.listen(SANDBOX_PORT, (err) => {
8288
if (err) {
8389
console.error("Error starting server:", err);
8490
process.exit(1);

examples/basic-host/src/implementation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const log = {
1717

1818

1919
export interface ServerInfo {
20+
name: string;
2021
client: Client;
2122
tools: Map<string, Tool>;
2223
appHtmlCache: Map<string, string>;
@@ -30,11 +31,13 @@ export async function connectToServer(serverUrl: URL): Promise<ServerInfo> {
3031
await client.connect(new StreamableHTTPClientTransport(serverUrl));
3132
log.info("Connection successful");
3233

34+
const name = client.getServerVersion()?.name ?? serverUrl.href;
35+
3336
const toolsList = await client.listTools();
3437
const tools = new Map(toolsList.tools.map((tool) => [tool.name, tool]));
3538
log.info("Server tools:", Array.from(tools.keys()));
3639

37-
return { client, tools, appHtmlCache: new Map() };
40+
return { name, client, tools, appHtmlCache: new Map() };
3841
}
3942

4043

examples/basic-host/src/index.module.css

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
.connecting {
2-
padding: 1rem 0;
3-
text-align: center;
4-
color: #666;
5-
}
6-
71
.callToolPanel, .toolCallInfoPanel {
82
margin: 0 auto;
93
padding: 1rem;
@@ -16,9 +10,6 @@
1610
}
1711

1812
.callToolPanel {
19-
display: flex;
20-
flex-direction: column;
21-
gap: 1rem;
2213
max-width: 480px;
2314

2415
form {
@@ -39,12 +30,16 @@
3930
padding: 0.5rem;
4031
border: 1px solid #ccc;
4132
border-radius: 4px;
42-
font-family: monospace;
4333
font-size: inherit;
4434
}
4535

46-
textarea {
36+
.toolSelect {
37+
font-family: monospace;
38+
}
39+
40+
.toolInput {
4741
min-height: 6rem;
42+
font-family: monospace;
4843
resize: vertical;
4944

5045
&[aria-invalid="true"] {
@@ -92,10 +87,15 @@
9287
gap: 0.5rem;
9388
min-width: 0;
9489

95-
.toolName {
90+
h2 {
91+
display: flex;
92+
flex-direction: column;
9693
margin: 0;
97-
font-family: monospace;
9894
font-size: 1.5rem;
95+
96+
.toolName {
97+
font-family: monospace;
98+
}
9999
}
100100
}
101101

0 commit comments

Comments
 (0)