Zod schemas and static TypeScript types for Model Context Protocol (MCP) SDK.
Import types as you would from @modelcontextprotocol/sdk/types.js
:
import type { Prompt, Tool, Resource } from "mcp-types";
Zod schemas are also available:
import { PromptSchema, ToolSchema, ResourceSchema } from "mcp-types";
Replace all imports from '@modelcontextprotocol/sdk/types.js' to 'mcp-types'
with mcp-types
, e.g.,
- import type { Prompt, Tool, Resource } from "@modelcontextprotocol/sdk/types.js";
+ import type { Prompt, Tool, Resource } from "mcp-types";
- import { PromptSchema, ToolSchema, ResourceSchema } from "@modelcontextprotocol/sdk/types.js";
+ import { PromptSchema, ToolSchema, ResourceSchema } from "mcp-types";
That's it!
The exported schemas and types are identical to the ones available from @modelcontextprotocol/sdk
, except for the following differences:
mcp-types
removespassthrough()
from all Zod schemas.mcp-types
uses thezod-to-typescript
library to generate static types.
The main difference and motivation behind creating this repository is that the original Zod schemas excessively use the passthrough()
Zod feature (#182), which effectively allows arbitrary properties to pass through. This creates both an unsafe environment (since arbitrary properties will be passed through) and degrades the Developer Experience because you won't get type errors if you accidentally make a typo.
To fix this, mcp-types
effectively copied schema definitions from the original repository and removed passthrough()
from all schema definitions. Furthermore, we've used the zod-to-typescript
library to generate static types which are much easier to work with since your type inference will show you clean, readable types.
The contents of the repository are based on the following version of MCP:
- v1.15.0 (commit)
To contribute an update:
- copy the contents of the types.ts from the original repository
- override Zod schemas in
src/schemas.ts
with the copied contents - run
pnpm run format
to fix linting errors - run
pnpm run generate
to generate the types - Update the
Last Compatible Commit
section in this README.md
That's it!