MCP Server Development

MCP Server Development

Architecture

MCP uses JSON-RPC 2.0 with a three-layer model: Host (AI application) → Client (stateful session manager) → Server (exposes tools, resources, prompts).

Three server primitives

Primitive Direction Purpose
Tools Client → Server Executable functions the LLM can invoke
Resources Client → Server Read-only contextual data (URI-based)
Prompts Client → Server Reusable interaction templates

Building servers in Python (FastMCP 3.x)

from fastmcp import FastMCP
mcp = FastMCP("my-server")

@mcp.tool
def search(query: str) -> str:
    """Search the database."""
    return do_search(query)

@mcp.resource("config://app")
def get_config() -> str:
    """Application configuration."""
    return json.dumps(config)

Transport protocols

stdio

Streamable HTTP (introduced March 2026, replaces deprecated SSE)

Security: OAuth 2.1 + PKCE

Mandatory for public remote MCP servers since November 2025.

Best practices checklist