Generate TypeScript types from MCP (Model Context Protocol) servers.
npm install -g mcp-to-typescript-codegenOr use with npx:
npx mcp-to-typescript-codegen --command "your-mcp-server"# Basic usage
mcp-to-typescript-codegen --command "mcp-server"
# With arguments
mcp-to-typescript-codegen --command "npx" --args "@modelcontextprotocol/server-filesystem,/tmp"
# Custom output file
mcp-to-typescript-codegen --command "mcp-server" --output "./types/mcp.ts"
# With namespace prefix (for multiple servers)
mcp-to-typescript-codegen --command "apollo-mcp" --name Apollo --output "./types/apollo.ts"mcp-to-typescript-codegen --server "http://localhost:3000/mcp"| Flag | Short | Description |
|---|---|---|
--command <cmd> |
-c |
Command to spawn MCP server (stdio transport) |
--args <args> |
-a |
Comma-separated arguments for the command |
--server <url> |
-s |
URL of HTTP MCP server (streamable HTTP transport) |
--output <file> |
-o |
Output file path (default: generated/mcp-tools.ts) |
--name <prefix> |
-n |
Prefix for generated type names (e.g., "Apollo") |
--debug |
-d |
Print raw tool schemas from server |
--help |
-h |
Show help |
// Auto-generated by mcp-to-typescript-codegen
// Do not edit manually
export type ReadFileParams = {
path: string;
};
export type ListDirectoryParams = {
path: string;
};
export type ToolName = "read_file" | "list_directory";
export const toolNames = ["read_file", "list_directory"] as const;With --name Apollo:
export type ApolloExecuteParams = {
query: string;
variables?: string;
};
export type ApolloToolName = "execute" | "introspect";
export const apolloToolNames = ["execute", "introspect"] as const;import { ReadFileParams, ToolName } from "./generated/mcp-tools";
// Type-safe params
const params: ReadFileParams = {
path: "/etc/hosts",
};
// Type-safe tool name
const toolName: ToolName = "read_file";Generate types for multiple servers with different prefixes:
# Apollo GraphQL MCP
mcp-to-typescript-codegen -c "apollo-mcp" -n Apollo -o "./types/apollo.ts"
# Filesystem MCP
mcp-to-typescript-codegen -c "npx" -a "@modelcontextprotocol/server-filesystem,/tmp" -n Filesystem -o "./types/filesystem.ts"Then import each:
import { ApolloExecuteParams, ApolloToolName } from "./types/apollo";
import { FilesystemReadFileParams, FilesystemToolName } from "./types/filesystem";MIT