Mcp module starts a stdio MCP server that exposes CLI commands as tools, enabling AI agents to discover and call your commands through the Model Context Protocol.
Functions
serve
Starts a stdio MCP server that exposes commands as tools.string
required
The MCP server name
string
required
Server version
Map<string, any>
required
Map of commands to expose as tools
serve.Options
Server configuration options
Promise<void>
Promise that resolves when the server connects and starts
Example
Types
serve.Options
Options for the MCP server.Readable
Override input stream. Defaults to
process.stdin.Writable
Override output stream. Defaults to
process.stdout.How It Works
The MCP server:- Flattens command hierarchy - Nested commands become flat tools with underscore-separated names (e.g.,
db_migrate) - Merges schemas - Combines
argsandoptionsinto a singleinputSchemafor each tool - Handles streaming - Supports async generator commands with progress notifications
- Error handling - Returns structured errors using
context.error()or catches exceptions
Tool Naming
Commands are converted to tool names by joining the command path with underscores:Input Schema
The tool’sinputSchema merges both positional arguments and options into a flat object:
Streaming Commands
Async generator commands send progress notifications:Related
- SyncMcp - Register CLI as MCP server with AI agents
- Model Context Protocol - Official MCP documentation

