docs/publishing/guides/ts-mcp-hono.mdx
Hono is a popular open source TypeScript framework for building HTTP servers, and @hono/mcp is an excellent solution for exposing MCP servers.
npm add hono @hono/node-server @hono/mcp @modelcontextprotocol/sdk zod
pnpm add hono @hono/node-server @hono/mcp @modelcontextprotocol/sdk zod
bun add hono @hono/node-server @hono/mcp @modelcontextprotocol/sdk zod
yarn add hono @hono/node-server @hono/mcp @modelcontextprotocol/sdk zod
import { StreamableHTTPTransport } from '@hono/mcp'
import { serve } from '@hono/node-server'
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { Hono } from 'hono'
import { logger } from 'hono/logger'
import { z } from 'zod'
const app = new Hono()
app.use(logger())
const mcpServer = new McpServer({
name: 'Example',
version: '0.0.1'
})
mcpServer.registerTool(
'add',
{
description: 'Add two numbers',
inputSchema: z.object({
a: z.number(),
b: z.number()
})
},
async (args) => {
return {
content: [
{
type: 'text',
content: String(args.a + args.b)
}
]
}
}
)
app.all('/mcp', async (c) => {
const transport = new StreamableHTTPTransport()
await mcpServer.connect(transport)
return transport.handleRequest(c)
})
serve({ fetch: app.fetch, port: 8787 })
Deploy your server publicly or use a tool like ngrok to expose it to the internet.
<Warning> Tools like `ngrok` expose your unauthenticated server to the internet. Only run this command in a safe environment if you understand the risks. </Warning>We recommend deploying your server to a cloud provider like Cloudflare Workers, Vercel (for instance, using the Hono API template), Render, Porter, or Fly.io. Or one of the big boys AWS, GCP, or Azure.
Now that you have a publicly available MCP server, you can follow the existing MCP server guide to deploy it to Agentic.