typescript-sdk/packages/middleware/hono
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jonathan Hefner 2b620d794e
fix: resolve TypeDoc warnings from directory-pointing relative links (#1546)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-17 23:25:54 +00:00
..
src Add code reference links and backticks to JSDoc comments (#1484) 2026-02-11 16:40:32 -06:00
test eslint fixes in tests (#1418) 2026-01-22 12:26:48 +00:00
eslint.config.mjs [v2] Decouple server from express and hono - http framework-agnostic MCP server (#1326) 2026-01-16 12:13:25 +02:00
package.json feat: auto-select JSON Schema validator based on runtime (#1456) 2026-02-03 19:22:39 +00:00
README.md fix: resolve TypeDoc warnings from directory-pointing relative links (#1546) 2026-02-17 23:25:54 +00:00
tsconfig.json feat: auto-select JSON Schema validator based on runtime (#1456) 2026-02-03 19:22:39 +00:00
tsdown.config.ts [v2] Decouple server from express and hono - http framework-agnostic MCP server (#1326) 2026-01-16 12:13:25 +02:00
typedoc.json Add API documentation with GitHub Pages deployment (#1109) 2026-01-20 17:22:24 +02:00
vitest.config.js [v2] Decouple server from express and hono - http framework-agnostic MCP server (#1326) 2026-01-16 12:13:25 +02:00

@modelcontextprotocol/hono

Hono adapters for the MCP TypeScript server SDK.

This package is a thin Hono integration layer for @modelcontextprotocol/server.

It does not implement MCP itself. Instead, it helps you:

  • create a Hono app with sensible defaults for MCP servers
  • parse JSON request bodies and expose them as c.get('parsedBody') for Streamable HTTP transports
  • add DNS rebinding protection via Host header validation (recommended for localhost servers)

Install

npm install @modelcontextprotocol/server @modelcontextprotocol/hono hono

Exports

  • createMcpHonoApp(options?)
  • hostHeaderValidation(allowedHostnames)
  • localhostHostValidation()

Usage

Streamable HTTP endpoint (Hono)

import { McpServer, WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/server';
import { createMcpHonoApp } from '@modelcontextprotocol/hono';

const server = new McpServer({ name: 'my-server', version: '1.0.0' });
const transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: undefined });
await server.connect(transport);

const app = createMcpHonoApp();
app.all('/mcp', c => transport.handleRequest(c.req.raw, { parsedBody: c.get('parsedBody') }));

Host header validation (DNS rebinding protection)

import { localhostHostValidation } from '@modelcontextprotocol/hono';

const app = createMcpHonoApp();
app.use('*', localhostHostValidation());