Skip to content
Back to search

hono-mcp-server

Expose your Hono API endpoints as MCP tools.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/mattzcarey--hono-mcp-server/badge.svg)](/listings/mattzcarey--hono-mcp-server)

HTML

<a href="/listings/mattzcarey--hono-mcp-server"><img src="/api/listings/mattzcarey--hono-mcp-server/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 97 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # MCP Server for Hono
  2. Expose your [Hono](https://hono.dev) API endpoints as [MCP](https://modelcontextprotocol.io) tools.
  3. ## Usage
  4. ```ts
  5. import { Hono } from "hono";
  6. import { z } from "zod";
  7. import { mcp, registerTool } from "hono-mcp-server";
  8. const app = new Hono()
  9. .get("/users", registerTool("List all users"), (c) => c.json([{ id: 1, name: "Alice" }]))
  10. .get("/users/:id", registerTool("Get user by ID"), (c) => c.json({ id: c.req.param("id") }))
  11. .post(
  12. "/users",
  13. registerTool({
  14. description: "Create a new user",
  15. inputSchema: {
  16. name: z.string().describe("User's full name"),
  17. email: z.string().email().describe("User's email address"),
  18. },
  19. }),
  20. async (c) => {
  21. const { name } = c.req.valid("json"); // typed!
  22. return c.json({ id: 1, name });
  23. },
  24. );
  25. export default mcp(app, {
  26. name: "Users API",
  27. version: "1.0.0",
  28. });
  29. ```
  30. This adds an `/mcp` endpoint that exposes your routes as MCP tools.
  31. ## Input & Output Schemas
  32. Use `registerTool()` with `inputSchema` for validated, typed input. Access validated data with `c.req.valid('json')`:
  33. ```ts
  34. import { z } from "zod";
  35. import { registerTool } from "hono-mcp-server";
  36. app.post(
  37. "/search",
  38. registerTool({
  39. description: "Search for items",
  40. inputSchema: {
  41. query: z.string().describe("Search query"),
  42. limit: z.number().optional().describe("Max results"),
  43. },
  44. outputSchema: {
  45. results: z.array(z.object({ id: z.string(), title: z.string() })),
  46. },
  47. }),
  48. async (c) => {
  49. const { query, limit } = c.req.valid("json"); // typed!
  50. return c.json({ results: [] });
  51. },
  52. );
  53. ```
  54. When `outputSchema` is defined, the tool returns structured content that MCP clients can parse.
  55. ## Options
  56. ```ts
  57. mcp(app, {
  58. name: "API Name", // required
  59. version: "1.0.0", // required
  60. description: "...", // optional
  61. instructions: "...", // optional
  62. mcpPath: "/mcp", // optional, default: "/mcp"
  63. codemode: false, // optional, see below
  64. });
  65. ```
  66. ## Codemode
  67. Instead of exposing individual routes as tools, codemode exposes `search` and `execute` tools for dynamic API interaction. Requires [Cloudflare Worker Loader](https://developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/).
  68. ```ts
  69. export default mcp(app, {
  70. name: "API",
  71. version: "1.0.0",
  72. codemode: true,
  73. });
  74. ```
  75. ```jsonc
  76. // wrangler.jsonc
  77. {
  78. "worker_loaders": [{ "binding": "LOADER" }],
  79. }
  80. ```

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.