MCP

MCP Spec

Roles

  • Host
    • Environment where code agent runs
    • Claude Code, Codex, GitHub Copilot
  • Client
    • Protocol handlers inside host to communicate with MCP Servers
    • It is built inside the agent’s runtime
  • Server
    • It exposes capabilities through MCP

Capabilities

  • Tools
    • Callable functions to perform actions or retrieve data
    • Each tool has:
      • name
      • description
      • JSON schema for function definition
      • function implementation
  • Resources
    • Read only data sources to retrieve information
    • Each resource has
      • URI, example: doc://api/overview
      • Human readable name
      • description
      • MIME type
      • Content
  • Prompts
    • Instruction Templates that agent can request
    • help guide agent behavior for specific context/domain
    • Each prompt has:
      • name
      • description
      • optional arguments
      • template text

Communication Protocols

  • https://modelcontextprotocol.io/specification/latest/basic/transports
  • JSON-RPC 2.0
    • transport agnostic
  • Transport Mechanisms
    • Stdio
    • Streamable HTTP
  • Stdio
    • No Network required
    • Client launches the MCP server as a subprocess
    • uses stdin and stdout
    • uses Anonymous Pipes IPC internally
  • Streamable HTTP
    • Defined as in spec
    • uses POST and GET
    • utilizes application/json and text/event-stream (SSE)
    • Supports multiple connections, sessions, retry, protocol versioning

Implementation

  • Python: FastMCP (lightweight server), Gradio (server + web UI)
  • Nodejs: MCP SDK
  • Example using FastMCP
from mcp.server.fastmcp import FastMCP
 
mcp = FastMCP("calculator")
 
@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers together."""
    return a + b
 
@mcp.tool()
def multiply(a: int, b: int) -> int:
    """Multiply two numbers together."""
    return a * b
 
if __name__ == "__main__":
    mcp.run()

Adding MCP to Agent

  • Claude CLI
    • Scopes:
      • Local: ~/.claude.json
      • Project: .mcp.json
      • User: ~/.claude.json
claude mcp add --transport http --scope user my-api https://api.example.com/mcp
  • Github Copilot CLI
    • Config: ~/.config/github-copilot/intellij/mcp.json
$ copilot
/mcp add 

Debugging MCP Server

  • Use MCP inspector
# Syntax
npx @modelcontextprotocol/inspector <command-to-launch-mcp> 
 
# Example
npx @modelcontextprotocol/inspector python calculator-mcp-server.py