MCP explained from first principles, spelled out in code (www.leonidasr.com)

🤖 AI Summary
The article walks through Model Context Protocol (MCP) “from first principles,” showing working code that moves from plain LLM function-calling to a full MCP client/server implementation. Using a simple OpenAI function-calling example (greet and calculate), it demonstrates the pain of hardcoded tool schemas and then shows how MCP standardizes tool/context exposure across three layers—Host (your app), Client (one connection to a server), and Server (exposes tools/resources/prompts). MCP uses a small set of transports (stdio for subprocess-bundled servers, HTTP with an /mcp endpoint and optional SSE for cloud servers) and a JSON-RPC wire format so messages are identical regardless of transport. Technically, the post demos FastMCP (a Python framework) and then strips the library away to show raw JSON-RPC: the initialize handshake, notifications/initialized, tools/list, tools/call, and function_call_output with call_id. It also ties MCP back into LLM function-calling, explains parallel tool calls, and highlights extra primitives (sampling, elicitation). The practical implication is a USB-like ecosystem for AI tools—less glue code, easier reuse, and clearer subprocess/auth/streaming semantics—enabling interoperable, composable agents across local and cloud deployments.
Loading comments...
loading comments...