MCP Learning Server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Learning ServerGive me a random quote"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
🔌 MCP Learning Project
A complete educational project demonstrating the Model Context Protocol (MCP) end-to-end.
This project is designed for developers who are completely new to MCP and want to understand:
What an MCP Server is
What an MCP Client is
How they communicate
How tools are registered and discovered
How requests flow and responses return
📋 Table of Contents
Related MCP server: MCP Server Basic Example
🎯 Project Overview
This project implements:
Component | Description |
MCP Server | A FastMCP server exposing 5 tools via stdio transport |
Interactive Client | A Rich-powered CLI that discovers and calls tools |
Chat Interface | A natural language chatbot that maps queries to tools |
Pydantic Validation | Type-safe input validation with friendly errors |
Logging | Structured logs with INFO/WARNING/ERROR levels |
Architecture Diagrams | Mermaid diagrams explaining every component |
Tech Stack
Python 3.11+
uvpackage managerOfficial MCP Python SDK (
mcp[cli]with FastMCP)asyncio
Pydantic v2
Rich library
🏗️ Architecture
High-Level Architecture
┌─────────────────────┐ ┌─────────────────────┐
│ MCP Client │ stdio │ MCP Server │
│ │◄────────►│ │
│ • Rich CLI/Chat │ JSON- │ • FastMCP Router │
│ • ClientSession │ RPC 2.0 │ • 5 Registered │
│ • Tool Discovery │ │ Tools │
└─────────────────────┘ └─────────────────────┘Request Flow
User
↓
Client UI (Rich terminal)
↓
ClientSession.call_tool(name, arguments)
↓
JSON-RPC 2.0 Request (serialized)
↓
stdio Transport (stdin pipe to server subprocess)
↓
FastMCP Server (deserializes, routes by tool name)
↓
@mcp.tool() Function → Pydantic validation → Business logic
↓
JSON Response (consistent format)
↓
stdio Transport (stdout pipe back to client)
↓
ClientSession (deserializes response)
↓
Rich UI (pretty-prints with syntax highlighting)
↓
User sees the result ✅Tool Discovery Flow
Client Server
| |
|──── initialize() ───────────►|
|◄──── capabilities ──────────|
| |
|──── list_tools() ───────────►|
|◄──── tool schemas ──────────|
| (name, description, |
| inputSchema) |
| |
| Client now knows all tools! |📌 Key MCP advantage: The client doesn't need hardcoded endpoints. It discovers tools dynamically!
📁 Folder Structure
mcp-learning-project/
│
├── server/ # MCP Server (the "backend")
│ ├── __init__.py # Package marker
│ ├── server.py # FastMCP setup + tool registration
│ ├── tools.py # Pure business logic (no MCP dependency)
│ ├── models.py # Pydantic validation models
│ └── quotes.py # Hardcoded quote data
│
├── client/ # MCP Client (the "frontend")
│ ├── __init__.py # Package marker
│ ├── client.py # Interactive CLI client
│ ├── chat.py # Natural language chat interface
│ └── ui.py # Rich terminal UI helpers
│
├── diagrams/ # Documentation
│ └── architecture.md # Mermaid architecture diagrams
│
├── logs/ # Generated at runtime
│ └── app.log # Structured application logs
│
├── screenshots/ # Screenshots placeholder
│
├── README.md # This file
├── pyproject.toml # Project configuration
├── uv.lock # Dependency lock file (auto-generated)
└── .gitignore # Git ignore rulesWhy Each File Exists
File | Purpose |
| MCP registration layer — connects business logic to the MCP protocol using |
| Business logic — pure Python functions that can be tested without MCP |
| Validation — Pydantic models that enforce type safety at the input boundary |
| Data — separates data from logic for clean architecture |
| Interactive client — demonstrates the full MCP client workflow |
| Chat interface — shows how natural language maps to tool calls |
| Presentation — all Rich formatting in one place |
🚀 Installation
Prerequisites
Python 3.11 or higher
uv package manager
Setup
# 1. Clone the repository
git clone <repository-url>
cd mcp-learning-project
# 2. Create a virtual environment and install dependencies
uv sync
# This will:
# - Create a .venv/ directory
# - Install mcp[cli], pydantic, and rich
# - Generate uv.lock for reproducibility▶️ Running the Project
Option 1: Interactive Client (Recommended)
The client automatically starts the server as a subprocess — you only need one terminal:
uv run python -m client.clientOption 2: Chat Interface
uv run python -m client.chatOption 3: Server Only (for debugging)
If you want to run the server independently (e.g., to test with MCP Inspector):
uv run python -m server.server⚠️ The server uses stdio transport, so it reads from stdin and writes to stdout. Running it directly will wait for JSON-RPC input — this is expected behavior.
Testing with MCP Inspector
The MCP Inspector is a visual debugging tool:
npx -y @modelcontextprotocol/inspector uv run python -m server.server🧰 Available Tools
1. current_time
Returns the current UTC time in ISO 8601 format.
Input | None |
Output |
|
2. calculator
Performs arithmetic operations on two numbers.
Input |
|
Operations |
|
Output |
|
Division by zero |
|
3. random_quote
Returns a random inspirational quote from an internal list of 25 quotes.
Input | None |
Output |
|
4. weather
Returns mock weather data for Indian cities.
Input |
|
Supported Cities | Jaipur, Delhi, Mumbai, Bangalore, Chennai, Kolkata, Hyderabad, Pune |
Output |
|
Unknown city |
|
5. uuid_generator
Generates a random UUID (version 4).
Input | None |
Output |
|
💻 Example Execution
Interactive Client
╭─────────────────────────────────────────────╮
│ 🔌 MCP Learning Client │
│ Connected to MCP Server via stdio │
╰─────────────────────────────────────────────╯
┌──────────────────────────────────────────────┐
│ 📋 Available Tools │
├────┬────────────────┬────────────────────────┤
│ # │ Tool Name │ Description │
├────┼────────────────┼────────────────────────┤
│ 1 │ current_time │ Get the current UTC │
│ │ │ time in ISO 8601 │
├────┼────────────────┼────────────────────────┤
│ 2 │ calculator │ Perform arithmetic │
│ │ │ operations │
├────┼────────────────┼────────────────────────┤
│ 3 │ random_quote │ Get a random │
│ │ │ inspirational quote │
├────┼────────────────┼────────────────────────┤
│ 4 │ weather │ Get mock weather data │
├────┼────────────────┼────────────────────────┤
│ 5 │ uuid_generator │ Generate a random UUID │
└────┴────────────────┴────────────────────────┘
>>> 2
Enter calculator inputs:
First number (a): 45
Second number (b): 87
Operation (add/subtract/multiply/divide): multiply
⏳ Calling calculator...
╭─── ✅ Success ───╮
│ { │
│ "result": 3915 │
│ } │
╰──────────────────╯
⏱ Completed in 0.023s
>>> info weather
📌 weather
Get mock weather data for an Indian city.
📥 Input Schema:
{
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
>>> exit
👋 Goodbye!Chat Interface
🤖 MCP Chat Interface
Ask me about weather, calculations, time, quotes, or UUIDs.
Type 'exit' to quit.
You: What is the weather in Jaipur?
⏳ Calling weather tool...
╭─── 🤖 Assistant ───╮
│ 🌤️ Weather in │
│ Jaipur: 35°C, Sunny │
╰─────────────────────╯
You: Multiply 45 and 87
⏳ Calling calculator tool...
╭─── 🤖 Assistant ───╮
│ 🔢 The answer is: │
│ 3915.0 │
╰─────────────────────╯
You: Give me an inspirational quote
⏳ Calling random_quote tool...
╭───── 🤖 Assistant ─────╮
│ 💬 "Stay hungry, stay │
│ foolish. — Steve Jobs" │
╰─────────────────────────╯Example Log Output (logs/app.log)
2026-07-08 10:30:15 | INFO | mcp.server | FastMCP server instance created: 'MCP Learning Server'
2026-07-08 10:30:15 | INFO | mcp.server | Starting MCP Learning Server (stdio transport)...
2026-07-08 10:30:16 | INFO | mcp.client | Client starting — connecting to MCP server...
2026-07-08 10:30:16 | INFO | mcp.client | stdio transport established
2026-07-08 10:30:16 | INFO | mcp.client | MCP session initialized
2026-07-08 10:30:16 | INFO | mcp.client | Discovered 5 tools: ['current_time', 'calculator', ...]
2026-07-08 10:30:20 | INFO | mcp.client | Calling tool: calculator with args: {'a': 45, 'b': 87, 'operation': 'multiply'}
2026-07-08 10:30:20 | INFO | mcp.server | Tool called: calculator(a=45.0, b=87.0, op=multiply)
2026-07-08 10:30:20 | INFO | mcp.server | Tool result: calculator → {'success': True, 'data': {'result': 3915.0}}
2026-07-08 10:30:20 | INFO | mcp.client | Tool calculator completed in 0.023s📚 MCP Learning Notes
What is MCP?
The Model Context Protocol (MCP) is a standardized protocol for connecting AI models to external tools and data sources. Think of it as a "USB-C for AI" — a universal interface that lets any AI assistant use any tool without custom integrations.
How MCP Registers Tools
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("My Server")
@mcp.tool(
name="calculator",
description="Perform arithmetic operations"
)
def calculator(a: float, b: float, operation: str) -> str:
# FastMCP auto-generates a JSON Schema from the function signature:
# {
# "type": "object",
# "properties": {
# "a": {"type": "number"},
# "b": {"type": "number"},
# "operation": {"type": "string"}
# },
# "required": ["a", "b", "operation"]
# }
...When @mcp.tool() is called:
FastMCP inspects the function's type hints
Generates a JSON Schema for the inputs
Stores the tool in an internal registry
When
list_tools()is called, returns all registered schemas
How the Client Discovers Tools
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
# 1. Define how to launch the server
server_params = StdioServerParameters(
command="uv",
args=["run", "python", "-m", "server.server"]
)
# 2. Connect via stdio
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# 3. Initialize the session (handshake)
await session.initialize()
# 4. Discover all tools
tools = await session.list_tools()
# tools.tools → list of Tool objects with name, description, inputSchema
# 5. Call a specific tool
result = await session.call_tool("calculator", {"a": 10, "b": 20, "operation": "add"})How Requests are Serialized
MCP uses JSON-RPC 2.0 over the stdio transport:
// Client → Server (request)
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "calculator",
"arguments": {"a": 10, "b": 20, "operation": "add"}
}
}
// Server → Client (response)
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [
{
"type": "text",
"text": "{\"success\": true, \"data\": {\"result\": 30.0}}"
}
]
}
}How Transport Works
This project uses stdio transport:
The client spawns the server as a subprocess
JSON-RPC messages flow through the subprocess's stdin (requests) and stdout (responses)
This is why we never
print()to stdout in the server — it would corrupt the protocol!
Other MCP transports include:
SSE (Server-Sent Events): HTTP-based, good for remote servers
Streamable HTTP: Newer HTTP transport for production use
How MCP Differs from REST
Aspect | REST API | MCP |
Discovery | You need documentation/OpenAPI spec |
|
Protocol | HTTP request/response | JSON-RPC 2.0 (bidirectional) |
Schema | OpenAPI (optional) | JSON Schema (built-in) |
Transport | Always HTTP | stdio, SSE, Streamable HTTP |
Standardization | Varies per API | One protocol for all tools |
AI Integration | Custom per model | Universal — any model, any tool |
How to Add a New Tool
Adding a tool takes 3 steps:
Business logic — Add a function to
server/tools.py:
def my_tool(input_param: str) -> dict[str, Any]:
"""Do something useful."""
return ToolResponse.ok(result="Hello!")Validation (optional) — Add a Pydantic model to
server/models.py:
class MyToolInput(BaseModel):
input_param: str = Field(..., min_length=1)Registration — Add a
@mcp.tool()decorator inserver/server.py:
@mcp.tool(name="my_tool", description="Does something useful")
def tool_my_tool(input_param: str) -> str:
return json.dumps(my_tool(input_param))That's it! The client will auto-discover the new tool on next connection.
⚠️ Common Errors
Error | Cause | Solution |
| Running from wrong directory |
|
| Missing | Run |
| Server failed to start | Check |
| Typo in operation name | Use: add, subtract, multiply, divide |
| b=0 with divide operation | Expected — handled gracefully |
| City not in mock data | Use: Jaipur, Delhi, Mumbai, Bangalore, Chennai, Kolkata |
| Printing to stdout in server | Always use logging or stderr |
🔮 Future Improvements
Add LLM integration for intelligent intent parsing
Implement SSE transport for remote server access
Add tool caching and rate limiting
Build a web-based UI alongside the CLI
Add unit tests for each tool
Implement MCP Resources and Prompts (beyond Tools)
Add authentication and authorization
Create a tool that chains multiple other tools
📄 License
MIT License — Feel free to use this for learning and education.
Built as an educational project to understand the Model Context Protocol (MCP).
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/somyabhadada/mcp_server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server