Skip to content

Commit 0f0bfe5

Browse files
committed
feat: SSE client example
Signed-off-by: John McBride <john@zuplo.com>
1 parent 2d9640e commit 0f0bfe5

File tree

6 files changed

+126
-0
lines changed

6 files changed

+126
-0
lines changed

examples/clients/sse/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

examples/clients/sse/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# MCP Client with SSE stream servers
2+
3+
This example demonstrates how to use the MCP client to connect to and work with
4+
servers that server their content in `data: ` streams (i.e., SSE).
5+
This calls the GitHub MCP server `get_me` tool to demonstrate this.
6+
7+
## Running the Example
8+
9+
```bash
10+
npm install
11+
npm run build
12+
13+
# Provide a GitHub token in the env for the Auth header
14+
# to the GitHub MCP server
15+
AUTH_TOKEN="ghp_..." npm start
16+
```
17+
18+
## Supported env
19+
20+
```env
21+
AUTH_TOKEN="ghp_..."
22+
```

examples/clients/sse/package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/clients/sse/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@zuplo/mcp-example-tool-call-client",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "tsc",
7+
"start": "node dist/index.js",
8+
"clean": "rm -rf ./dist/ && rm -rf ./node_modules/"
9+
},
10+
"dependencies": {
11+
"@zuplo/mcp": "file:../../../"
12+
}
13+
}

examples/clients/sse/src/index.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { MCPClient } from "@zuplo/mcp/client";
2+
import { ConsoleLogger } from "@zuplo/mcp/logger";
3+
import { HTTPClientTransport } from "@zuplo/mcp/transport/httpclient";
4+
5+
const logger = new ConsoleLogger();
6+
const client = new MCPClient({
7+
name: "GitHub SSE client",
8+
version: "0.0.0",
9+
logger,
10+
});
11+
12+
const url = "https://api.githubcopilot.com/mcp/";
13+
const authToken = process.env.AUTH_TOKEN;
14+
15+
if (authToken === "") {
16+
throw Error("no AUTH_TOKEN env var provided. Please provide a GitHub PAT for use with the GitHub MCP server.")
17+
}
18+
19+
try {
20+
const transport = new HTTPClientTransport({
21+
url,
22+
logger,
23+
headers: {
24+
Authorization: `Bearer ${authToken}`,
25+
},
26+
});
27+
28+
await client.connect(transport);
29+
const initResult = await client.initialize();
30+
31+
logger.info("Connected successfully!", {
32+
serverInfo: initResult.serverInfo,
33+
protocolVersion: initResult.protocolVersion,
34+
});
35+
36+
const userResult = await client.callTool("get_me", {});
37+
logger.info("GitHub user:", userResult);
38+
} catch (error) {
39+
logger.error("Error running client example:", error);
40+
} finally {
41+
await client.disconnect();
42+
}

examples/clients/sse/tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"outDir": "./dist",
5+
"rootDir": "./src"
6+
},
7+
"include": [
8+
"./src/**/*"
9+
],
10+
"references": [
11+
{ "path": "../../../" }
12+
]
13+
}

0 commit comments

Comments
 (0)