MCP Server Development Guide (v2 Protocol)
Build robust, production-grade Model Context Protocol (MCP) servers implementing the 2026-07-28 protocol in Python (FastMCP) or TypeScript (@modelcontextprotocol/server v2).
When to Use
Use this skill when:
- Designing and implementing a custom MCP server to expose databases, internal microservices, or developer utilities to AI coding assistants.
- Authoring MCP tools, resources, and prompts in TypeScript using the official v2
@modelcontextprotocol/server API.
- Authoring fast Python MCP servers using the
fastmcp library.
- Implementing standard
stdio process transports or remote streamable HTTP / SSE endpoints.
- Structuring tool input schemas, validation handlers, and error boundaries for LLM tool calling.
Do not use this skill for:
- Configuring pre-built n8n MCP tools (use
n8n-mcp-tools-expert).
- Setting up Cedar policy authorization or signed receipt verification for MCP tools (use
protect-mcp-governance).
Prerequisites
- Python 3.10+ (for Python FastMCP) or Node.js 20+ / Bun / TypeScript (for TypeScript SDK v2).
- Clear specification of exposed tool names, descriptions, input schemas, and return structures.
Architecture & Transport Patterns
MCP servers communicate with client AI agents across two standard transport mechanisms:
stdio (Standard I/O): Spawns the MCP server as a local child process. Best for desktop IDEs, CLI tools, and local single-user development.
- Streamable HTTP / SSE: Runs as a standalone network service over HTTP/HTTPS. Best for multi-tenant services, cloud agents, and shared microservices.
Implementation Guide
Pattern A: Modern TypeScript Server (v2 @modelcontextprotocol/server)
The modern 2026-07-28 protocol separates server definitions from transport listeners. In v2, tools are registered using server.registerTool(name, config, callback) with a Zod schema object. The SDK derives JSON Schema specifications and type-safe handler arguments automatically. Pass a createServer factory function to serveStdio for process execution or createMcpHandler for HTTP endpoints.
import { McpServer } from "@modelcontextprotocol/server";
import { serveStdio } from "@modelcontextprotocol/server/stdio";
import * as z from "zod/v4";
function createServer(): McpServer {
const server = new McpServer({
name: "customer-tools-mcp",
version: "2.0.0",
});
server.registerTool(
"lookup_customer",
{
description: "Lookup customer account profile and status by email address.",
inputSchema: z.object({
email: z.string().email().describe("The customer email address"),
include_history: z.boolean().default(false).describe("Include recent order history"),
}),
},
async ({ email, include_history }) => {
// Perform database / API lookup
const customer = {
id: "CUST-4819",
email,
status: "active",
plan: "enterprise",
orders: include_history ? [{ id: "ORD-902", total: 450.0 }] : undefined,
};
return {
content: [
{
type: "text",
text: JSON.stringify(customer, null, 2),
},
],
};
}
);
return server;
}
// Serve over stdio transport using the official v2 listener factory
void serveStdio(createServer);
Pattern B: Python FastMCP Server
from fastmcp import FastMCP
from pydantic import BaseModel, Field
mcp = FastMCP(
name="DatabaseMCP",
dependencies=["pydantic"]
)
class QueryFilter(BaseModel):
table_name: str = Field(description="Target table name (e.g. 'users', 'invoices')")
limit: int = Field(default=10, ge=1, le=100, description="Max records to retrieve")
@mcp.tool(name="query_records", description="Execute structured read queries against database tables.")
def query_records(table_name: str, limit: int = 10) -> dict:
# Validate and sanitize table name
allowed_tables = {"users", "invoices", "products"}
if table_name not in allowed_tables:
return {"error": f"Table '{table_name}' is not in allowed query set."}
# Execute query logic
return {
"table": table_name,
"count": 1,
"records": [{"id": 1, "status": "active"}]
}
if __name__ == "__main__":
mcp.run(transport="stdio")
Progressive Disclosure & Reference
Tool Design Best Practices
- Explicit Parameter Descriptions: Models use property descriptions to construct arguments accurately.
- Deterministic Return Payload: Return JSON strings wrapped in
content: [{ type: "text", text: "..." }].
- Structured Errors in Content: Return informative error JSON within the text content rather than throwing unhandled transport errors.
Safety & Governance
- Sanitize all parameters before executing shell commands or database queries to prevent injection.
- Never write debug or logging statements directly to
stdout in stdio mode (use stderr or MCP logging notifications), as writing to stdout corrupts JSON-RPC framing.
- For fine-grained access control, integrate Cedar policy governance via
protect-mcp-governance.
Completion Evidence
- Server responds to
tools/list with complete JSON schemas and parameter descriptions.
tools/call invocations return valid content payloads conforming to the MCP specification.
1---2name: "mcp-builder-ms"3description: "Design, build, and package Model Context Protocol (MCP) servers in Python (FastMCP) or TypeScript (MCP SDK v2) across stdio and streamable HTTP transports. Use when exposing internal tools, data sources, and services to AI agents."4source: "community_canonical"5risk: "unknown"6license: "not_declared_upstream"7metadata:8 source: https://skillmd.com/skills/revrebel/mcp-builder-ms9---1011# MCP Server Development Guide (v2 Protocol)1213Build robust, production-grade Model Context Protocol (MCP) servers implementing the 2026-07-28 protocol in Python (FastMCP) or TypeScript (`@modelcontextprotocol/server` v2).1415## When to Use1617Use this skill when:18- Designing and implementing a custom MCP server to expose databases, internal microservices, or developer utilities to AI coding assistants.19- Authoring MCP tools, resources, and prompts in TypeScript using the official v2 `@modelcontextprotocol/server` API.20- Authoring fast Python MCP servers using the `fastmcp` library.21- Implementing standard `stdio` process transports or remote streamable HTTP / SSE endpoints.22- Structuring tool input schemas, validation handlers, and error boundaries for LLM tool calling.2324Do not use this skill for:25- Configuring pre-built n8n MCP tools (use `n8n-mcp-tools-expert`).26- Setting up Cedar policy authorization or signed receipt verification for MCP tools (use `protect-mcp-governance`).2728## Prerequisites2930- Python 3.10+ (for Python FastMCP) or Node.js 20+ / Bun / TypeScript (for TypeScript SDK v2).31- Clear specification of exposed tool names, descriptions, input schemas, and return structures.3233---3435## Architecture & Transport Patterns3637MCP servers communicate with client AI agents across two standard transport mechanisms:381. **`stdio` (Standard I/O)**: Spawns the MCP server as a local child process. Best for desktop IDEs, CLI tools, and local single-user development.392. **Streamable HTTP / SSE**: Runs as a standalone network service over HTTP/HTTPS. Best for multi-tenant services, cloud agents, and shared microservices.4041---4243## Implementation Guide4445### Pattern A: Modern TypeScript Server (v2 `@modelcontextprotocol/server`)4647The modern 2026-07-28 protocol separates server definitions from transport listeners. In v2, tools are registered using `server.registerTool(name, config, callback)` with a Zod schema object. The SDK derives JSON Schema specifications and type-safe handler arguments automatically. Pass a `createServer` factory function to `serveStdio` for process execution or `createMcpHandler` for HTTP endpoints.4849```typescript50import { McpServer } from "@modelcontextprotocol/server";51import { serveStdio } from "@modelcontextprotocol/server/stdio";52import * as z from "zod/v4";5354function createServer(): McpServer {55 const server = new McpServer({56 name: "customer-tools-mcp",57 version: "2.0.0",58 });5960 server.registerTool(61 "lookup_customer",62 {63 description: "Lookup customer account profile and status by email address.",64 inputSchema: z.object({65 email: z.string().email().describe("The customer email address"),66 include_history: z.boolean().default(false).describe("Include recent order history"),67 }),68 },69 async ({ email, include_history }) => {70 // Perform database / API lookup71 const customer = {72 id: "CUST-4819",73 email,74 status: "active",75 plan: "enterprise",76 orders: include_history ? [{ id: "ORD-902", total: 450.0 }] : undefined,77 };7879 return {80 content: [81 {82 type: "text",83 text: JSON.stringify(customer, null, 2),84 },85 ],86 };87 }88 );8990 return server;91}9293// Serve over stdio transport using the official v2 listener factory94void serveStdio(createServer);95```9697### Pattern B: Python FastMCP Server9899```python100from fastmcp import FastMCP101from pydantic import BaseModel, Field102103mcp = FastMCP(104 name="DatabaseMCP",105 dependencies=["pydantic"]106)107108class QueryFilter(BaseModel):109 table_name: str = Field(description="Target table name (e.g. 'users', 'invoices')")110 limit: int = Field(default=10, ge=1, le=100, description="Max records to retrieve")111112@mcp.tool(name="query_records", description="Execute structured read queries against database tables.")113def query_records(table_name: str, limit: int = 10) -> dict:114 # Validate and sanitize table name115 allowed_tables = {"users", "invoices", "products"}116 if table_name not in allowed_tables:117 return {"error": f"Table '{table_name}' is not in allowed query set."}118119 # Execute query logic120 return {121 "table": table_name,122 "count": 1,123 "records": [{"id": 1, "status": "active"}]124 }125126if __name__ == "__main__":127 mcp.run(transport="stdio")128```129130---131132## Progressive Disclosure & Reference133134- [Legacy v1 MCP Migration Guide](./references/LEGACY_V1_MIGRATION.md): Guide for upgrading 2025-era v1 `new Server(...)` and removed `.tool(...)` implementations to v2.135136---137138## Tool Design Best Practices1391401. **Explicit Parameter Descriptions**: Models use property descriptions to construct arguments accurately.1412. **Deterministic Return Payload**: Return JSON strings wrapped in `content: [{ type: "text", text: "..." }]`.1423. **Structured Errors in Content**: Return informative error JSON within the text content rather than throwing unhandled transport errors.143144## Safety & Governance145146- Sanitize all parameters before executing shell commands or database queries to prevent injection.147- Never write debug or logging statements directly to `stdout` in stdio mode (use `stderr` or MCP logging notifications), as writing to stdout corrupts JSON-RPC framing.148- For fine-grained access control, integrate Cedar policy governance via `protect-mcp-governance`.149150## Completion Evidence151152- Server responds to `tools/list` with complete JSON schemas and parameter descriptions.153- `tools/call` invocations return valid content payloads conforming to the MCP specification.