Sitemap
Vengadesa Boopathi

Vengadesa Boopathi

MODEL CONTEXT PROTOCOL

8 min readMar 5, 2026

--

2. The Problem Before MCP (How AI Agents Used Tools)

3. What is MCP?

4. MCP Components

5. How MCP Works — Step by Step

name — unique identifier
description - what the tool does (for the LLM)
inputSchema - JSON Schema describing expected arguments
json
{"jsonrpc":"2.0", "id":1, "method":"tools/list"}
json
{
"jsonrpc":"2.0", "id":1,
"result": {
"tools": [
{
"name": "get_weather",
"description": "Get current weather for a city",
"inputSchema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}}]}}
json{
"function_call": {
"name": "get_weather",
"arguments": "{\"city\": \"London\"}"
}
}
json
{
"jsonrpc":"2.0", "id":2,
"method":"tools/call",
"params": {
"name": "get_weather",
"arguments": {"city": "London"}
}
}
json
{
"jsonrpc":"2.0", "id":2,
"result": {
"content": [
{"type": "text", "text": "The temperature in London is 22°C."}
]}}

6. Example MCP Server in Python (Using Official SDK)

python
from mcp.server import Server, stdio_server
from mcp.types import TextContent, Tool, CallToolResult
app = Server("weather-server")
# Actual tool implementation
def get_weather(city: str) -> str:
# Replace with real API call
return f"The temperature in {city} is 22°C."
# Register tool discovery
@app.list_tools()
async def list_tools():
return [
Tool(
name="get_weather",
description="Get current weather for a city",
inputSchema={
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
)
]
# Register tool execution
@app.call_tool()
async def call_tool(name: str, arguments: dict) -> CallToolResult:
if name == "get_weather":
city = arguments["city"]
result_text = get_weather(city)
return CallToolResult(
content=[TextContent(type="text", text=result_text)]
)
raise ValueError(f"Unknown tool: {name}")
if __name__ == "__main__":
stdio_server.run(app)

7. How the Server Maps Tool Names to Functions

python
TOOL_FUNCTIONS = {
"get_weather": get_weather,
"calculator": lambda a,b: a+b,
# …
}
@app.call_tool()
async def call_tool(name: str, arguments: dict):
if name in TOOL_FUNCTIONS:
result = TOOL_FUNCTIONS[name](**arguments)
return CallToolResult(…)
…

8. Transport Options

Get Vengadesa Boopathi’s stories in your inbox

Join Medium for free to get updates from this writer.

9. Benefits of MCP

FastMCP

1. What is FastMCP?

2. Why FastMCP? The Problem It Solves

3. Core Concepts

python
from fastmcp import FastMCP
mcp = FastMCP("My Server Name")
python
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers together."""
return a + b
python
@mcp.resource("config://app")
def get_config() -> str:
"""Return the application configuration."""
return "debug=True\nport=8080"
python
@mcp.prompt()
def analyze_sentiment(text: str) -> str:
"""Create a prompt for sentiment analysis."""
return f"Analyze the sentiment of the following text: {text}"

4. How FastMCP Works Under the Hood

5. Example: A Complete FastMCP Server

python
from fastmcp import FastMCP
# Create the server
mcp = FastMCP("Demo Server")
# - Tools -
@mcp.tool()
def greet(name: str) -> str:
"""Greet a person by name."""
return f"Hello, {name}!"
@mcp.tool()
def add(a: float, b: float) -> float:
"""Add two numbers."""
return a + b
# - Resource -
@mcp.resource("info://version")
def get_version() -> str:
"""Return the server version."""
return "1.0.0"
# - Prompt -
@mcp.prompt()
def haiku(topic: str) -> str:
"""Create a haiku prompt."""
return f"Write a haiku about {topic}."
# Run the server (stdio by default)
if __name__ == "__main__":
mcp.run()

6. Running FastMCP Servers

python
mcp.run() # or mcp.run(transport="stdio")
python
mcp.run(transport="sse", host="0.0.0.0", port=8000)

7. Advanced Features

python
from fastmcp import FastMCP, Context
mcp = FastMCP("Context Demo")
@mcp.tool()
def long_task(ctx: Context, duration: int) -> str:
"""Simulate a long task with progress reporting."""
for i in range(duration):
ctx.report_progress(i, duration) # sends progress notifications
time.sleep(1)
return "Done"
python
from mcp.types import ImageContent
@mcp.tool()
def plot() -> list[ImageContent]:
# generate an image…
return [ImageContent(type="image", data=base64_data, mimeType="image/png")]
Press enter or click to view image in full size

9. Integration with MCP Clients

10. Benefits of Using FastMCP

--

--