Skip to content

Commit eb27883

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

File tree

6 files changed

+124
-0
lines changed

6 files changed

+124
-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 serve 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-client-sse",
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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(
17+
"no AUTH_TOKEN env var provided. Please provide a GitHub PAT for use with the GitHub MCP server."
18+
);
19+
}
20+
21+
try {
22+
const transport = new HTTPClientTransport({
23+
url,
24+
logger,
25+
headers: {
26+
Authorization: `Bearer ${authToken}`,
27+
},
28+
});
29+
30+
await client.connect(transport);
31+
const initResult = await client.initialize();
32+
33+
logger.info("Connected successfully!", {
34+
serverInfo: initResult.serverInfo,
35+
protocolVersion: initResult.protocolVersion,
36+
});
37+
38+
const userResult = await client.callTool("get_me", {});
39+
logger.info("GitHub user:", userResult);
40+
} catch (error) {
41+
logger.error("Error running client example:", error);
42+
} finally {
43+
await client.disconnect();
44+
}

examples/clients/sse/tsconfig.json

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

0 commit comments

Comments
 (0)