Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

I turned my Hono API into an MCP server by changing one import

说明与用途

通过更改一个导入,将 Hono API 转换为 MCP 服务器,使 AI 代理能够调用端点,而无需重复定义模式。

问题

Expose an existing Hono API to AI agents without duplicating endpoint definitions.

结果

The bridge turns a Hono app into an MCP server with a single import change, eliminating duplicate tool definitions and preserving existing validation and middleware.

工作流

  • Import mountMcp from hono-mcp-bridge and replace zValidator import.
  • Call mountMcp(app) to register every route as an MCP tool.
  • The bridge walks app.routes, extracts schemas via z.toJSONSchema, and exposes them as tools.
  • Agents invoke tools by sending JSON RPC requests to /mcp; the bridge forwards arguments as a real HTTP request to the original handler.
  • Validation, auth, logging, and rate limits are preserved.
  • Optional configuration (include, exclude, methods, describeTool, allowedOrigins) limits exposed tools and origins.

证据

Method, path, parameters, types, even descriptions: everything an agent needs is already there.

来源

mountMcp(app) // POST /mcp: every route is now a tool

来源

A tool call is a real request. Arguments become a Request passed to app.fetch()

来源

Agents act with the credentials of whoever connected them. Use include, exclude or methods: ['GET'] to limit what is exposed

来源

  • 记录日期: 2026-10-19T17:41:18.192Z