muppet logo
OpenAPI

Using Hono OpenAPI

Reuse your hono-openapi validators to generate MCP servers

This requires hono-openapi@0.5.0 or later to work. You can checkout the project here

muppet and hono-openapi both uses a validator supporting Standard Schema to understand the structure of the request and response. Now with latest release of hono-openapi, you can use the same validator inplace of the one provided by muppet to generate the MCP server. This is useful if you are already using hono-openapi in your project and want to reuse the same validators for your MCP server.

import { Hono } from "hono";
import { describeRoute, uniqueSymbol } from "hono-openapi";
import { muppet, mValidator } from "muppet";
import z from "zod";
 
const app = new Hono();
 
app.get(
  "/products",
  describeRoute({
    summary: "Get all products",
    description: "This endpoint returns a list of all products.",
  }),
  // TODO: Change this with the hono-openapi validator
  mValidator("query", z.object({ page: z.number().optional() })),
  async (c) => {
    return c.json([
      {
        id: 1,
        name: "Product 1",
        price: 10.0,
      },
      {
        id: 2,
        name: "Product 2",
        price: 20.0,
      },
    ]);
  },
);
 
muppet(app, {
  name: "hono-openapi-mcp",
  version: "0.0.1",
  // By passing this, muppet will scan the hono-openapi middlewares too
  symbols: [uniqueSymbol],
});