mcp-types
v1.0.2
Published
Zod schemas and static TypeScript types for Model Context Protocol (MCP) SDK.
Readme
MCP Types
Zod schemas and static TypeScript types for Model Context Protocol (MCP) SDK.
Usage
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";Migrating
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!
Key Differences
The exported schemas and types are identical to the ones available from @modelcontextprotocol/sdk, except for the following differences:
mcp-typesremovespassthrough()from all Zod schemas.mcp-typesuses thezod-to-typescriptlibrary to generate static types.
Motivation
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.
Last Compatible Commit
The contents of the repository are based on the following version of MCP:
- v1.15.0 (commit)
Contributing
To contribute an update:
- copy the contents of the types.ts from the original repository
- override Zod schemas in
src/schemas.tswith the copied contents - run
pnpm run formatto fix linting errors - run
pnpm run generateto generate the types - Update the
Last Compatible Commitsection in this README.md
That's it!
