Home Blog Spatial Lab Disciplines Agentic Tools
Learn • AI Academy
IP Network Infrastructure About Connect

Model Context Protocol (MCP): JSON-RPC 2.0 & Schema Architecture

Deconstructing the open connectivity protocol: JSON-RPC 2.0 framing, tool discovery (tools/list), invocation (tools/call), resource subscriptions, and SSE vs. stdio transports.

Foundational Knowledge & Simpler Primers
Need a simpler explanation or feeling stuck?

To build solid intuition for this module, review these foundational primers:

Unsure of mathematical notation or technical terms on this page? Our 57-term AI Glossary breaks down every concept with plain-English analogies and rigorous engineering specs.
Open AI Glossary (57 Terms)

1. Theoretical Motivation & Foundations

Autonomous agents require a standardized, vendor-neutral protocol to securely interface with local filesystems, external databases, developer tooling, and third-party APIs. The Model Context Protocol (MCP), open-sourced by Anthropic, solves the M × N integration problem by establishing an open JSON-RPC 2.0 communication contract between LLM applications (clients) and capability providers (servers). This module explores the three core primitive abstractions of MCP: Tools (executable functions with JSON Schema parameter validation), Resources (read-only structured context like file contents or database rows), and Prompts (reusable parameterized prompt templates). We analyze the connection handshake lifecycle, Server-Sent Events (SSE) vs. stdio transport dynamics, progress notifications, and server capability negotiation.

2. Mathematical Formulations & Derivations

The governing analytical formulations and proof frameworks for this module:

JSON-RPC 2.0 Request Envelope: Request = {"jsonrpc": "2.0", "id": str|int, "method": str, "params": dict} Tool Schema Discovery Overhead: T_schema = ∑_{i=1}^M Tokens(ToolSchema_i) Multi-Turn Session Context Accumulation: C_session = T_system + T_schema + ∑_{t=1}^N (T_thought(t) + T_call(t) + T_obs(t)) Transport Framing: stdio newline-delimited JSON vs. SSE (text/event-stream event: message\ndata: {...}\n\n)

3. From-Scratch Reference Implementation

Executable, production-tested reference code without magic libraries:

# Asynchronous MCP Server & Client Simulator in Python import json class MCPServer: def __init__(self, name: str): self.name = name self.tools = {} def register_tool(self, name: str, description: str, handler): self.tools[name] = {'description': description, 'handler': handler} def handle_request(self, raw_json: str) -> str: req = json.loads(raw_json) req_id = req.get('id') method = req.get('method') if method == 'tools/list': tool_list = [{'name': k, 'description': v['description']} for k, v in self.tools.items()] return json.dumps({'jsonrpc': '2.0', 'id': req_id, 'result': {'tools': tool_list}}) elif method == 'tools/call': tool_name = req['params']['name'] args = req['params'].get('arguments', {}) if tool_name not in self.tools: return json.dumps({'jsonrpc': '2.0', 'id': req_id, 'error': {'code': -32601, 'message': 'Tool not found'}}) res = self.tools[tool_name]['handler'](**args) return json.dumps({'jsonrpc': '2.0', 'id': req_id, 'result': {'content': [{'type': 'text', 'text': str(res)}]}}) return json.dumps({'jsonrpc': '2.0', 'id': req_id, 'error': {'code': -32600, 'message': 'Invalid Request'}}) server = MCPServer('Database-MCP') server.register_tool('query_orders', 'Fetch user order status', lambda user_id: f'User {user_id} has 3 active orders.') req_call = json.dumps({'jsonrpc': '2.0', 'id': 'call-1', 'method': 'tools/call', 'params': {'name': 'query_orders', 'arguments': {'user_id': 'USR_42'}}}) print('MCP Server Response:', server.handle_request(req_call))

4. Systems Complexity & Memory Footprint

MCP is rapidly becoming the universal standard for LLM tool connectivity. By decoupling tools from vendor-specific agent frameworks, enterprises can write a single MCP server (e.g. for PostgreSQL, Jira, or AWS) that instantly works with Claude Desktop, Cursor, Gemini, and custom internal agents.

5. Canonical Literature & Primary Research

Original research papers and foundational texts recommended for advanced study:

  1. Anthropic. (2024). Model Context Protocol Specification & Architecture Guide.
  2. Schick, T., et al. (2023). Toolformer: Language Models Can Teach Themselves to Use Tools. NeurIPS.
  3. OpenAI. (2023). Function Calling and Structured Outputs Specification.
Next Page for Further Learning
Mastered this concept? Keep advancing

Explore the natural continuations in the curriculum: