Merge pull request #10 from modelcontextprotocol/e2e-testing
E2E testing
This commit is contained in:
parent
6a3130a075
commit
ace3220fca
1 changed files with 11726 additions and 17 deletions
63
examples/servers/hono-mcp/src/index.ts
Normal file
63
examples/servers/hono-mcp/src/index.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
||||
import { StreamableHTTPTransport } from '@hono/mcp'
|
||||
import { Hono } from 'hono'
|
||||
import { z } from 'zod'
|
||||
import { cors } from 'hono/cors'
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
app.use(
|
||||
'/*',
|
||||
cors({
|
||||
origin: '*',
|
||||
allowHeaders: ['content-type', 'mcp-session-id', 'mcp-protocol-version'],
|
||||
exposeHeaders: ['mcp-session-id'],
|
||||
}),
|
||||
)
|
||||
|
||||
// Your MCP server implementation
|
||||
const mcpServer = new McpServer({
|
||||
name: 'my-mcp-server',
|
||||
version: '1.0.0',
|
||||
})
|
||||
|
||||
mcpServer.registerTool(
|
||||
'add',
|
||||
{
|
||||
title: 'Addition Tool',
|
||||
description: 'Add two numbers',
|
||||
inputSchema: { a: z.number(), b: z.number() },
|
||||
},
|
||||
async ({ a, b }) => ({
|
||||
content: [{ type: 'text', text: String(a + b) }],
|
||||
}),
|
||||
)
|
||||
|
||||
mcpServer.registerTool(
|
||||
'get_vengabus_times',
|
||||
{
|
||||
title: 'Vengabus Schedule Checker',
|
||||
description:
|
||||
"This checks to see when the next Vengabus is, or whether there is one for the user's current location. Please display all the information to the user in a tabulated form.",
|
||||
inputSchema: {},
|
||||
},
|
||||
async () => {
|
||||
await scheduler.wait(100 + Math.random() * 100)
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Next Vengabus: imminent. Current user's route: New York to San Francisco. Route name: "Intercity Disco".`,
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
app.post('/mcp', async (c) => {
|
||||
const transport = new StreamableHTTPTransport()
|
||||
await mcpServer.connect(transport)
|
||||
return transport.handleRequest(c)
|
||||
})
|
||||
|
||||
export default app
|
||||
Loading…
Reference in a new issue