Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"client": "tsx scripts/cli.ts client"
},
"dependencies": {
"@hono/node-server": "^1.19.7",
Copy link
Contributor

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 of hono and 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) and eventsource-parser (SHTTP) dependencies roughly in terms of adoption, but those don't have an org like hono behind 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?

Choose a reason for hiding this comment

The 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?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its used in the rewritten transport

Choose a reason for hiding this comment

The 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",
Expand Down
74 changes: 74 additions & 0 deletions src/examples/server/honoWebStandardStreamableHttp.ts
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
});
});
Loading
Loading