What the TypeScript SDK provides
You can use the SDK to:- Create MCP servers
- Register tools, resources, and prompts
- Build MCP clients
- Connect through
stdioor Streamable HTTP - Handle protocol initialization and capabilities
- Send notifications and progress updates
- Add OAuth and other production controls
Install the stable v1 SDK
Create a TypeScript project and install the SDK with Zod:Build a minimal MCP server
Createsrc/server.ts:
Do not write ordinary logs to
stdout when using stdio. Use stderr so logs do not corrupt MCP messages.What the server code does
McpServercreates the high-level server.registerTooldefines the tool’s name, metadata, input schema, and handler.- Zod validates tool arguments at runtime.
- The handler returns MCP content.
StdioServerTransportcarries messages between the client and process.server.connectstarts protocol communication.
Add resources and prompts
The high-level server API can also register:- Static or templated resources
- Parameterized prompts
- Structured tool output
- Notifications when available items change
Build a minimal MCP client
Createsrc/client.ts:
add.
Choose a transport
For remote production servers, use the transport and HTTP adapter recommended by your installed SDK version. Add TLS, origin validation, authentication, authorization, rate limits, and request-size limits.
Read MCP transports before choosing.
Validate and handle errors
Tool handlers should:- Validate all model-provided input
- Authorize the exact operation
- Set timeouts for upstream requests
- Convert expected failures into actionable tool results
- Avoid exposing stack traces or credentials
- Support cancellation where applicable
- Return structured output for stable machine-readable data
Test the server
Run the server through MCP Inspector:- Unit tests for handlers
- Contract tests for API calls
- Integration tests for the transport
- Client compatibility tests
- Dependency and secret scanning