File tree Expand file tree Collapse file tree 6 files changed +126
-0
lines changed
Expand file tree Collapse file tree 6 files changed +126
-0
lines changed Original file line number Diff line number Diff line change 1+ .env
Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments