Skip to content
Official v5.0.0-beta.103 MIT kubb >=5.0.0 node >=22

@kubb/plugin-mcp

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

mcpmodel-context-protocolaiclaudellmcodegenopenapi
Downloads
30.7k / mo
Stars
5
Bundle size
211.2 kB
Updated
2d ago

@kubb/plugin-mcp

@kubb/plugin-mcp turns your OpenAPI spec into a Model Context Protocol server, with each operation becoming an MCP tool that AI assistants like Claude Desktop and Claude Code can call to reach your API. The plugin generates the tool handlers, a server.ts, and a .mcp.json, and validates each call with the schemas from @kubb/plugin-zod.

Each handler calls a registered client plugin, so add @kubb/plugin-axios or @kubb/plugin-fetch alongside @kubb/plugin-ts and @kubb/plugin-zod. Without a client plugin, the build stops with a setup error.

This plugin generates an MCP server from your spec, distinct from the built-in kubb mcp server that exposes the Kubb CLI itself, documented under AI / MCP.

The Connect Claude to a remote MCP server guide explains how to register the generated server with an assistant.

Installation

shell
bun add -d @kubb/plugin-mcp@beta
shell
pnpm add -D @kubb/plugin-mcp@beta
shell
npm install --save-dev @kubb/plugin-mcp@beta
shell
yarn add -D @kubb/plugin-mcp@beta

Dependencies

This plugin needs three other plugins. @kubb/plugin-ts and @kubb/plugin-zod are declared dependencies, so Kubb runs them before plugin-mcp and the handlers can import the generated types and Zod schemas. The client plugin is resolved separately at setup.

A client plugin is required, since the handlers call its generated functions. Register one of them and set client only when both are present.

Example

typescript
import { 
defineConfig
} from 'kubb'
import {
pluginTs
} from '@kubb/plugin-ts'
import {
pluginAxios
} from '@kubb/plugin-axios'
import {
pluginZod
} from '@kubb/plugin-zod'
import {
pluginMcp
} from '@kubb/plugin-mcp'
export default
defineConfig
({
input
: './petStore.yaml',
output
: {
path
: './src/gen' },
plugins
: [
pluginTs
(),
pluginAxios
({
baseURL
: 'https://petstore.swagger.io/v2' }),
pluginZod
(),
pluginMcp
({
output
: {
path
: 'mcp',
mode
: 'directory',
barrel
: {
type
: 'named' } },
group
: {
type
: 'tag',
name
: ({
group
}) => `${
group
}Handlers`,
}, }), ], })

See also