docs/publishing/guides/ts-openapi-hono.mdx
Hono is a popular open source TypeScript framework for building HTTP servers, and @hono/zod-openapi is an excellent solution for creating an auto-generated OpenAPI spec from your Hono routes.
npm add hono @hono/node-server @hono/zod-openapi zod
pnpm add hono @hono/node-server @hono/zod-openapi zod
bun add hono @hono/node-server @hono/zod-openapi zod
yarn add hono @hono/node-server @hono/zod-openapi zod
import { serve } from '@hono/node-server'
import { createRoute, OpenAPIHono, z } from '@hono/zod-openapi'
import { logger } from 'hono/logger'
const app = new OpenAPIHono()
app.use(logger())
const echoRoute = createRoute({
description: 'Echoes the request body',
// The OpenAPI `operationId` will be used as the tool name in Agentic
operationId: 'echo',
method: 'post',
path: '/echo',
request: {
body: {
content: {
'application/json': {
schema: z.object({}).passthrough()
}
}
}
},
responses: {
200: {
description: 'Echoed request body',
content: {
'application/json': {
schema: z.object({}).passthrough()
}
}
}
}
})
return app.openapi(echoRoute, async (c) => {
return c.json(c.req.valid('json'))
})
app.doc31('/docs', {
openapi: '3.1.0',
info: {
title: 'Example',
description: 'Example description',
version: '0.0.1'
}
})
serve({ fetch: app.fetch, port: 8787 })
Note that the auto-generated OpenAPI spec will be available at /docs in this example.
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 OpenAPI server guide to deploy it to Agentic.