Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/clients/sse/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
22 changes: 22 additions & 0 deletions examples/clients/sse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# MCP Client with SSE stream servers

This example demonstrates how to use the MCP client to connect to and work with
servers that serve their content in `data: ` streams (i.e., SSE).
This calls the GitHub MCP server `get_me` tool to demonstrate this.

## Running the Example

```bash
npm install
npm run build

# Provide a GitHub token in the env for the Auth header
# to the GitHub MCP server
AUTH_TOKEN="ghp_..." npm start
```

## Supported env

```env
AUTH_TOKEN="ghp_..."
```
35 changes: 35 additions & 0 deletions examples/clients/sse/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions examples/clients/sse/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@zuplo/mcp-example-client-sse",
"private": true,
"type": "module",
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"clean": "rm -rf ./dist/ && rm -rf ./node_modules/"
},
"dependencies": {
"@zuplo/mcp": "file:../../../"
}
}
44 changes: 44 additions & 0 deletions examples/clients/sse/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { MCPClient } from "@zuplo/mcp/client";
import { ConsoleLogger } from "@zuplo/mcp/logger";
import { HTTPClientTransport } from "@zuplo/mcp/transport/httpclient";

const logger = new ConsoleLogger();
const client = new MCPClient({
name: "GitHub SSE client",
version: "0.0.0",
logger,
});

const url = "https://api.githubcopilot.com/mcp/";
const authToken = process.env.AUTH_TOKEN;

if (!authToken) {
throw Error(
"no AUTH_TOKEN env var provided. Please provide a GitHub PAT for use with the GitHub MCP server."
);
}

try {
const transport = new HTTPClientTransport({
url,
logger,
headers: {
Authorization: `Bearer ${authToken}`,
},
});

await client.connect(transport);
const initResult = await client.initialize();

logger.info("Connected successfully!", {
serverInfo: initResult.serverInfo,
protocolVersion: initResult.protocolVersion,
});

const userResult = await client.callTool("get_me", {});
logger.info("GitHub user:", userResult);
} catch (error) {
logger.error("Error running client example:", error);
} finally {
await client.disconnect();
}
9 changes: 9 additions & 0 deletions examples/clients/sse/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["./src/**/*"],
"references": [{ "path": "../../../" }]
}