Literature: MCP Server Development
This literature note covers the technical implementation and conceptual framework for building Model Context Protocol (MCP) servers.
Core Capabilities
MCP servers provide functionality through three primary building blocks:
| Feature | Control | Description |
|---|---|---|
| Tools | Model | Executable functions with JSON schemas. Interrogated by LLMs to perform actions (API calls, DB writes). |
| Resources | Application | Passive, read-only data (file contents, DB schemas, API docs) exposed via unique URIs (file:///, travel://). |
| Prompts | User | Standardized templates for tasks (e.g., "Plan a vacation"), facilitating structured workflows. |
Implementation Patterns
1. FastMCP (Python)
- High-level Abstraction: Uses type hints and docstrings to auto-generate tool definitions.
- Entry Point:
FastMCP("server-name"). - Registration: Decorated functions via
@mcp.tool().
2. TypeScript SDK
- Type Safety: Utilizes
zodfor robust input schema validation. - Registration:
server.registerTool(name, schema, handler).
Critical Logging Rules (STDIO)
When using the Stdio transport, servers must follow strict logging hygiene to avoid corrupting the JSON-RPC message stream:
- ❌ DO NOT use
print()orconsole.log(): These write tostdout, which is reserved for protocol messages. - ✅ USE
sys.stderrorconsole.error(): Errors and logs must be directed tostderrto remain visible without breaking the connection.
Development Workflow
- Prerequisites: Python 3.10+ (uv) or Node.js 16+.
- Initialization: Handshake exchange defines protocol version and capabilities.
- Discovery: Host discovers server features via
tools/listandresources/list. - Notifications: Servers can emit
list_changedevents to trigger host-side refreshes.
See Also
- mcp-server-development (Permanent Note)
- mcp-moc
- lit-mcp-architecture
- mcp-best-practices