AI AgentsMCP ServersWorkflowsBlogSubmit

MCP TypeScript SDK: Build AI Tool Servers with Node.js

Master the MCP TypeScript SDK for building AI tool servers. Complete guide with examples for tools, resources, and transport configuration.

The MCP TypeScript SDK is the official library for building MCP servers and clients in the JavaScript/TypeScript ecosystem. It handles protocol compliance, transport management, and serialization, letting you focus on building great tools.

Overview

The SDK provides both server and client implementations, supporting stdio and HTTP/SSE transports. It includes TypeScript-first APIs with full type safety, making it easy to build reliable MCP integrations.

Key Features

  • Full TypeScript Support — Type-safe APIs for servers and clients
  • Multiple Transports — stdio, HTTP/SSE out of the box
  • Schema Validation — Automatic JSON Schema validation for tool inputs
  • Streaming Support — Handle long-running operations with progress updates
  • Express Integration — Mount MCP servers in Express.js applications

Getting Started

npm install @modelcontextprotocol/sdk

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = new McpServer({ name: "my-server", version: "1.0.0" });
const transport = new StdioServerTransport();
await server.connect(transport);

Use Cases

  • Node.js Tool Servers — Build tools that leverage the npm ecosystem
  • Web API Bridges — Connect web APIs to AI agents via MCP
  • Full-Stack Integration — MCP servers as part of Express/Next.js apps
  • Browser Tools — Puppeteer/Playwright-based web interaction tools

Best Practices

  • Use Zod for validation — Leverage Zod schemas for runtime type checking
  • Implement graceful shutdown — Handle SIGINT/SIGTERM for clean cleanup
  • Log structured data — Use JSON logging for production debugging
  • Bundle for distribution — Use esbuild/tsup for single-file distribution

Frequently Asked Questions

Do I need TypeScript?

You can use plain JavaScript, but TypeScript is recommended for better development experience and type safety.

Can I use Express.js with MCP?

Yes, the SDK includes Express middleware for mounting MCP servers alongside your existing API routes.

Conclusion

Stay ahead of the curve by exploring our comprehensive directories. Browse the AI Agent directory with 400+ agents and the MCP Server directory with 2,300+ servers to find the perfect tools for your workflow.

Related Articles & Resources