Skip to content
Plugin
MCP logo
plugins: [pluginMcp()]
Officialv5.6.0kubb >=5.19.0node >=22.22

OpenAPI to MCP server generator

@kubb/plugin-mcp

Generates a Model Context Protocol server from your OpenAPI spec, so AI assistants can call each operation as a typed tool.

kubb add plugin-mcp
mcpmodel-context-protocolaiclaudellmcodegenopenapi

The MCP plugin turns each operation in your OpenAPI spec into a typed MCP tool that AI assistants can call, validated with @kubb/plugin-zod schemas.

Each tool handler calls the function a client plugin generates for that operation.

Next to the handlers, the plugin writes three files at the root of its output.path:

FileRole
server.tsRegisters one tool per operation and exports startServer().
start.tsCalls startServer() to serve the tools over stdio.
.mcp.jsonA server entry that runs start.ts, ready to copy into your MCP client config.

Installation

kubb add plugin-mcp

kubb add installs the version the Kubb registry pins and adds pluginMcp() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.

Setup

  • Add @kubb/plugin-zod, one client plugin (@kubb/plugin-fetch, @kubb/plugin-axios, @kubb/plugin-ky, or @kubb/plugin-client), and @kubb/plugin-ts. @kubb/plugin-ts is optional with pluginZod({ inferred: 'codec' }). Leave sdk unset on the client plugin.
  • Install @modelcontextprotocol/server v2 and zod 4.2 or a later v4 release in the app that runs the server. Add axios or ky too when you use @kubb/plugin-axios or @kubb/plugin-ky.
  • Install a TypeScript runner such as tsx. The generated .mcp.json runs npx tsx, which downloads tsx from npm when it is missing.

Options worth knowing

OptionDefaultWhat it does
clientDetectedPicks 'fetch', 'axios', 'ky', or 'client' when several client plugins are registered.
exclude[]Skips operations, such as one with a binary request body. An MCP client sends JSON and cannot send a file.
output.path'mcp'Must name a folder for server.ts, start.ts, and .mcp.json.

Operations that stream their response get no tool.

See Streaming operations.

Example

This config generates an MCP server whose tools call the Petstore API through @kubb/plugin-fetch. The .mcp.json names the server after the spec's info.title:

import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginZod } from '@kubb/plugin-zod'
import { pluginFetch } from '@kubb/plugin-fetch'
import { pluginMcp } from '@kubb/plugin-mcp'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [
    pluginTs(),
    pluginZod(),
    pluginFetch({ baseURL: 'https://petstore.swagger.io/v2' }),
    pluginMcp({ output: { path: 'mcp', mode: 'directory' } }),
  ],
})

Next, run the server and connect Claude Code or Claude Desktop.

Dependencies

Extensions that must be in the same config as MCP.

Optional dependencies

Extensions MCP works with when they are in the config.