feat: add github mcp server example and support mcp connection headers

pull/722/head
Travis Fischer 2025-07-08 17:53:07 -07:00
rodzic d38622d388
commit f273c5a483
15 zmienionych plików z 104 dodań i 8 usunięć

Wyświetl plik

@ -32,6 +32,7 @@ for (const [i, fixtureSuite] of fixtureSuites.entries()) {
version: '0.0.0'
})
// TODO: add origin requestInit headers
const transport = new StreamableHTTPClientTransport(
new URL(fixtureSuite.path, env.AGENTIC_GATEWAY_BASE_URL)
)

Wyświetl plik

@ -11,6 +11,7 @@ export type DurableMcpClientInfo = {
url: string
name: string
version: string
headers?: Record<string, string>
}
// TODO: not sure if there's a better way to handle re-using client connections
@ -60,7 +61,15 @@ export class DurableMcpClientBase extends DurableObject<RawEnv> {
version
})
const transport = new StreamableHTTPClientTransport(new URL(url))
// console.log('DurableMcpClient.ensureClientConnection', {
// url,
// headers: mcpClientInfo.headers
// })
const transport = new StreamableHTTPClientTransport(new URL(url), {
requestInit: {
headers: mcpClientInfo.headers
}
})
this.clientConnectionP = this.client.connect(transport)
await this.clientConnectionP
}

Wyświetl plik

@ -260,7 +260,8 @@ export async function resolveOriginToolCall({
await originMcpClient.init({
url: deployment.origin.url,
name: origin.serverInfo.name,
version: origin.serverInfo.version
version: origin.serverInfo.version,
headers: origin.headers
})
const originMcpRequestMetadata = {

Wyświetl plik

@ -82,6 +82,12 @@
"type": {
"type": "string",
"const": "mcp"
},
"headers": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"required": [

Wyświetl plik

@ -6,7 +6,7 @@
"repository": {
"type": "git",
"url": "git+https://github.com/transitive-bullshit/agentic.git",
"directory": "examples/search"
"directory": "examples/mcp-servers/context7"
},
"type": "module",
"source": "./src/worker.ts",

Wyświetl plik

@ -0,0 +1,26 @@
import 'dotenv/config'
import { defineConfig } from '@agentic/platform'
if (!process.env.GITHUB_TOKEN) {
throw new Error('GITHUB_TOKEN is not set')
}
export default defineConfig({
name: 'GitHub',
slug: 'github',
description:
'The GitHub MCP Server is a Model Context Protocol (MCP) server that provides seamless integration with GitHub APIs, enabling advanced automation and interaction capabilities for developers and tools.',
origin: {
type: 'mcp',
url: 'https://api.githubcopilot.com/mcp/',
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`
}
},
icon: './github-mark.svg',
readme:
'https://raw.githubusercontent.com/github/github-mcp-server/refs/heads/main/README.md',
sourceUrl: 'https://github.com/github/github-mcp-server',
homepageUrl: 'https://github.com'
})

Wyświetl plik

@ -0,0 +1 @@
<svg width="98" height="96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#24292f"/></svg>

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 963 B

Wyświetl plik

@ -0,0 +1,21 @@
{
"name": "@agentic/examples-mcps-github",
"private": true,
"author": "Travis Fischer <travis@transitivebullsh.it>",
"license": "UNLICENSED",
"repository": {
"type": "git",
"url": "git+https://github.com/transitive-bullshit/agentic.git",
"directory": "examples/mcp-servers/github"
},
"type": "module",
"source": "./src/worker.ts",
"scripts": {
"test": "run-s test:*",
"test:typecheck": "tsc --noEmit"
},
"dependencies": {
"@agentic/platform": "workspace:*",
"dotenv": "catalog:"
}
}

Wyświetl plik

@ -0,0 +1,5 @@
{
"extends": "@fisch0920/config/tsconfig-node",
"include": ["agentic.config.ts"],
"exclude": ["node_modules"]
}

Wyświetl plik

@ -6,7 +6,7 @@
"repository": {
"type": "git",
"url": "git+https://github.com/transitive-bullshit/agentic.git",
"directory": "examples/search"
"directory": "examples/mcp-servers/search"
},
"type": "module",
"source": "./src/worker.ts",

Wyświetl plik

@ -26,8 +26,13 @@ export async function resolveMCPOriginAdapter({
400,
`Invalid origin adapter type "${origin.type}" for ${label}`
)
const transport = new StreamableHTTPClientTransport(new URL(origin.url))
const transport = new StreamableHTTPClientTransport(new URL(origin.url), {
requestInit: {
headers: origin.headers
}
})
const client = new McpClient({ name, version })
try {
await client.connect(transport)
} catch (err: any) {

Wyświetl plik

@ -930,6 +930,9 @@ export interface components {
url: string;
/** @enum {string} */
type: "mcp";
headers?: {
[key: string]: string;
};
} | {
/**
* @default external
@ -1018,6 +1021,9 @@ export interface components {
url: string;
/** @enum {string} */
type: "mcp";
headers?: {
[key: string]: string;
};
serverInfo: {
name: string;
version: string;

Wyświetl plik

@ -69,7 +69,10 @@ export const mcpOriginAdapterConfigSchema = commonOriginAdapterSchema.merge(
/**
* MCP server.
*/
type: z.literal('mcp')
type: z.literal('mcp'),
// Optional headers to pass to the origin API server
headers: z.record(z.string(), z.string()).optional()
})
)
export type MCPOriginAdapterConfig = z.infer<
@ -201,6 +204,9 @@ export const mcpOriginAdapterSchema = commonOriginAdapterSchema.merge(
*/
type: z.literal('mcp'),
// Optional headers to pass to the origin API server
headers: z.record(z.string(), z.string()).optional(),
/**
* MCP server info: name, version, capabilities, instructions, etc.
*/

Wyświetl plik

@ -244,7 +244,7 @@ catalogs:
specifier: ^6.0.0
version: 6.0.0
dotenv:
specifier: ^17.0.1
specifier: 17.0.1
version: 17.0.1
drizzle-kit:
specifier: ^0.31.4
@ -973,6 +973,15 @@ importers:
specifier: workspace:*
version: link:../../../packages/platform
examples/mcp-servers/github:
dependencies:
'@agentic/platform':
specifier: workspace:*
version: link:../../../packages/platform
dotenv:
specifier: 'catalog:'
version: 17.0.1
examples/mcp-servers/search:
dependencies:
'@agentic/platform':

Wyświetl plik

@ -93,7 +93,7 @@ catalog:
dedent: ^1.6.0
del-cli: ^6.0.0
delay: ^6.0.0
dotenv: ^17.0.1
dotenv: 17.0.1
drizzle-kit: ^0.31.4
drizzle-orm: ^0.44.2
duck-duck-scrape: ^2.2.7