Skip to content

Commit 5662909

Browse files
committed
merge commit
2 parents ea2fc03 + 67ba7ad commit 5662909

File tree

11 files changed

+5834
-874
lines changed

11 files changed

+5834
-874
lines changed

package-lock.json

Lines changed: 4601 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/examples/server/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@
3232
"client": "tsx scripts/cli.ts client"
3333
},
3434
"dependencies": {
35-
"@modelcontextprotocol/sdk-server": "workspace:^",
35+
"@hono/node-server": "catalog:runtimeServerOnly",
36+
"hono": "catalog:runtimeServerOnly",
3637
"@modelcontextprotocol/sdk-examples-shared": "workspace:^",
37-
"zod": "catalog:runtimeShared",
38+
"@modelcontextprotocol/sdk-server": "workspace:^",
39+
"cors": "catalog:runtimeServerOnly",
3840
"express": "catalog:runtimeServerOnly",
39-
"cors": "catalog:runtimeServerOnly"
41+
"zod": "catalog:runtimeShared"
4042
},
4143
"devDependencies": {
42-
"@modelcontextprotocol/tsconfig": "workspace:^",
4344
"@modelcontextprotocol/eslint-config": "workspace:^",
45+
"@modelcontextprotocol/tsconfig": "workspace:^",
4446
"@modelcontextprotocol/vitest-config": "workspace:^",
45-
"@types/express": "catalog:devTools",
46-
"@types/cors": "catalog:devTools"
47+
"@types/cors": "catalog:devTools",
48+
"@types/express": "catalog:devTools"
4749
}
4850
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Example MCP server using Hono with WebStandardStreamableHTTPServerTransport
3+
*
4+
* This example demonstrates using the Web Standard transport directly with Hono,
5+
* which works on any runtime: Node.js, Cloudflare Workers, Deno, Bun, etc.
6+
*
7+
* Run with: npx tsx src/examples/server/honoWebStandardStreamableHttp.ts
8+
*/
9+
10+
import { serve } from '@hono/node-server';
11+
import type { CallToolResult } from '@modelcontextprotocol/sdk-server';
12+
import { McpServer, WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk-server';
13+
import { Hono } from 'hono';
14+
import { cors } from 'hono/cors';
15+
import * as z from 'zod/v4';
16+
17+
// Create the MCP server
18+
const server = new McpServer({
19+
name: 'hono-webstandard-mcp-server',
20+
version: '1.0.0'
21+
});
22+
23+
// Register a simple greeting tool
24+
server.registerTool(
25+
'greet',
26+
{
27+
title: 'Greeting Tool',
28+
description: 'A simple greeting tool',
29+
inputSchema: { name: z.string().describe('Name to greet') }
30+
},
31+
async ({ name }): Promise<CallToolResult> => {
32+
return {
33+
content: [{ type: 'text', text: `Hello, ${name}! (from Hono + WebStandard transport)` }]
34+
};
35+
}
36+
);
37+
38+
// Create a stateless transport (no options = no session management)
39+
const transport = new WebStandardStreamableHTTPServerTransport();
40+
41+
// Create the Hono app
42+
const app = new Hono();
43+
44+
// Enable CORS for all origins
45+
app.use(
46+
'*',
47+
cors({
48+
origin: '*',
49+
allowMethods: ['GET', 'POST', 'DELETE', 'OPTIONS'],
50+
allowHeaders: ['Content-Type', 'mcp-session-id', 'Last-Event-ID', 'mcp-protocol-version'],
51+
exposeHeaders: ['mcp-session-id', 'mcp-protocol-version']
52+
})
53+
);
54+
55+
// Health check endpoint
56+
app.get('/health', c => c.json({ status: 'ok' }));
57+
58+
// MCP endpoint
59+
app.all('/mcp', c => transport.handleRequest(c.req.raw));
60+
61+
// Start the server
62+
const PORT = process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 3000;
63+
64+
server.connect(transport).then(() => {
65+
console.log(`Starting Hono MCP server on port ${PORT}`);
66+
console.log(`Health check: http://localhost:${PORT}/health`);
67+
console.log(`MCP endpoint: http://localhost:${PORT}/mcp`);
68+
69+
serve({
70+
fetch: app.fetch,
71+
port: PORT
72+
});
73+
});

packages/server/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
"dependencies": {
4848
"content-type": "catalog:runtimeServerOnly",
4949
"cors": "catalog:runtimeServerOnly",
50+
"@hono/node-server": "catalog:runtimeServerOnly",
51+
"hono": "catalog:runtimeServerOnly",
5052
"express": "catalog:runtimeServerOnly",
5153
"express-rate-limit": "catalog:runtimeServerOnly",
5254
"raw-body": "catalog:runtimeServerOnly",

packages/server/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from './server/server.js';
66
export * from './server/sse.js';
77
export * from './server/stdio.js';
88
export * from './server/streamableHttp.js';
9+
export * from './server/webStandardStreamableHttp.js';
910

1011
// auth exports
1112
export * from './server/auth/index.js';

packages/server/src/server/inMemoryEventStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { JSONRPCMessage } from '@modelcontextprotocol/sdk-core';
22

3-
import type { EventStore } from './streamableHttp.js';
3+
import type { EventStore } from './webStandardStreamableHttp.js';
44

55
/**
66
* Simple in-memory implementation of the EventStore interface for resumability

0 commit comments

Comments
 (0)