-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: fetch transport #1209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: fetch transport #1209
Changes from all commits
3014283
24e96ed
f5bbe02
d3e796a
e3e5af3
4dfa889
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,7 @@ | |
| "client": "tsx scripts/cli.ts client" | ||
| }, | ||
| "dependencies": { | ||
| "@hono/node-server": "^1.19.7", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is a dependency for the example only shouldn't this be a devDependency rather than a dependency (that would be installed with the library?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its used in the rewritten transport There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh...as usual, GitHub is very bad at showing diffs. |
||
| "ajv": "^8.17.1", | ||
| "ajv-formats": "^3.0.1", | ||
| "content-type": "^1.0.5", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /** | ||
| * Example MCP server using Hono with WebStandardStreamableHTTPServerTransport | ||
| * | ||
| * This example demonstrates using the Web Standard transport directly with Hono, | ||
| * which works on any runtime: Node.js, Cloudflare Workers, Deno, Bun, etc. | ||
| * | ||
| * Run with: npx tsx src/examples/server/honoWebStandardStreamableHttp.ts | ||
| */ | ||
|
|
||
| import { Hono } from 'hono'; | ||
| import { cors } from 'hono/cors'; | ||
| import { serve } from '@hono/node-server'; | ||
| import * as z from 'zod/v4'; | ||
| import { McpServer } from '../../server/mcp.js'; | ||
| import { WebStandardStreamableHTTPServerTransport } from '../../server/webStandardStreamableHttp.js'; | ||
| import { CallToolResult } from '../../types.js'; | ||
|
|
||
| // Create the MCP server | ||
| const server = new McpServer({ | ||
| name: 'hono-webstandard-mcp-server', | ||
| version: '1.0.0' | ||
| }); | ||
|
|
||
| // Register a simple greeting tool | ||
| server.registerTool( | ||
| 'greet', | ||
| { | ||
| title: 'Greeting Tool', | ||
| description: 'A simple greeting tool', | ||
| inputSchema: { name: z.string().describe('Name to greet') } | ||
| }, | ||
| async ({ name }): Promise<CallToolResult> => { | ||
| return { | ||
| content: [{ type: 'text', text: `Hello, ${name}! (from Hono + WebStandard transport)` }] | ||
| }; | ||
| } | ||
| ); | ||
|
|
||
| // Create a stateless transport (no options = no session management) | ||
| const transport = new WebStandardStreamableHTTPServerTransport(); | ||
|
|
||
| // Create the Hono app | ||
| const app = new Hono(); | ||
|
|
||
| // Enable CORS for all origins | ||
| app.use( | ||
| '*', | ||
| cors({ | ||
| origin: '*', | ||
| allowMethods: ['GET', 'POST', 'DELETE', 'OPTIONS'], | ||
| allowHeaders: ['Content-Type', 'mcp-session-id', 'Last-Event-ID', 'mcp-protocol-version'], | ||
| exposeHeaders: ['mcp-session-id', 'mcp-protocol-version'] | ||
| }) | ||
| ); | ||
|
|
||
| // Health check endpoint | ||
| app.get('/health', c => c.json({ status: 'ok' })); | ||
|
|
||
| // MCP endpoint | ||
| app.all('/mcp', c => transport.handleRequest(c.req.raw)); | ||
|
|
||
| // Start the server | ||
| const PORT = process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 3000; | ||
|
|
||
| server.connect(transport).then(() => { | ||
| console.log(`Starting Hono MCP server on port ${PORT}`); | ||
| console.log(`Health check: http://localhost:${PORT}/health`); | ||
| console.log(`MCP endpoint: http://localhost:${PORT}/mcp`); | ||
|
|
||
| serve({ | ||
| fetch: app.fetch, | ||
| port: PORT | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked into this library a bit https://github.com/honojs/hono
While it doesn't have a huge number of stars (~580), it's actually not a very big package - ~1.5k lines of code, mostly to convert between Node.js and WebStandards requests. 3.5M DLs on
npm(cf. ~10M for TypeScript SDK). The maintainer is also the creator ofhonoand the package has had a very regular release cadence.Compared to our other runtime dependencies it is a bit fresher / less mature. It's in the same ballpark as our
eventsource(SSE) andeventsource-parser(SHTTP) dependencies roughly in terms of adoption, but those don't have an org likehonobehind them, so arguably this new dependency has more backing than other ones we already depend on.So in all I think this is fine to achieve our goal of decoupling from Express. What's worth discussing is whether we ship this in v1 or wait for v2 with this for risk management in case this causes unexpected regressions.
@mattzcarey @KKonstantinov have either of you potentially used this in production before?