FastMCP Demo Server
A demonstration server showcasing MCP capabilities with basic tools including addition calculations and weather API integration for fetching city weather data.
README
FastMCP Demo Server
A demonstration server built with FastMCP framework that showcases how to create Model Context Protocol (MCP) servers with custom tools.
What is MCP?
Model Context Protocol (MCP) is an open protocol that enables AI assistants and applications to securely access external data sources and tools. It provides a standardized way for AI models to:
- Access external APIs and services
- Interact with databases and file systems
- Execute custom functions and tools
- Retrieve context from various sources
- Perform actions on behalf of users
MCP acts as a bridge between AI applications and external resources, allowing models to extend their capabilities beyond their training data.
Why is MCP Useful?
MCP solves several critical problems in AI application development:
- Standardization: Provides a common protocol for AI-to-external-service communication
- Security: Enables secure, controlled access to external resources
- Extensibility: Allows developers to add custom capabilities without modifying core AI models
- Separation of Concerns: Keeps AI logic separate from external service integrations
- Real-time Data: Enables AI models to access up-to-date information from external sources
- Tool Execution: Allows AI models to perform actions (not just retrieve information)
Architecture of MCP
MCP follows a client-server architecture:
┌─────────────┐ MCP Protocol ┌─────────────┐
│ │ ◄──────────────────────────► │ │
│ MCP Client │ (JSON-RPC over stdio) │ MCP Server │
│ (AI App) │ │ (This App) │
│ │ │ │
└─────────────┘ └─────────────┘
│
│
┌───────┴───────┐
│ │
External APIs Databases
File Systems Services
Key Components:
- MCP Client: The AI application (e.g., Claude Desktop, custom AI app) that makes requests
- MCP Server: This application that exposes tools and resources
- Transport Layer: JSON-RPC 2.0 protocol over stdio (standard input/output)
- Tools: Functions exposed by the server that the client can call
- Resources: Data sources that can be accessed by the client
- Prompts: Pre-defined prompt templates
Communication Flow:
- Client sends a JSON-RPC request to the server
- Server processes the request (calls tools, fetches resources)
- Server sends a JSON-RPC response back to the client
- Client uses the response in its AI context
Lifecycle of MCP
The MCP server lifecycle follows these stages:
1. Initialization
- Server starts and listens on stdio
- Server registers available tools, resources, and prompts
- Server sends initialization message to client
2. Handshake
- Client and server exchange capabilities
- Client requests server information (name, version, available tools)
- Server responds with its capabilities
3. Operation
- Client sends tool execution requests
- Server processes requests and executes tools
- Server returns results to client
- This cycle repeats for each interaction
4. Shutdown
- Client sends shutdown signal
- Server cleans up resources
- Server terminates gracefully
Example Lifecycle Flow:
Start Server → Initialize FastMCP → Register Tools → Listen on stdio
│
▼
Client Connects → Handshake → Request Tool → Execute Tool → Return Result
│
▼
Continue Listening...
How to Use This Demo Server
Prerequisites
- Python 3.12 or higher
uvpackage manager (or pip)
Installation
- Install dependencies:
uv sync
# or
pip install fastmcp>=2.14.0 requests
Running the Server
Using uv (Recommended)
uv provides a fast and reliable way to manage dependencies and run Python projects:
# Install dependencies (creates virtual environment automatically)
uv sync
# Run the server using uv
uv run python main.py
# Or activate the virtual environment first
source .venv/bin/activate # On macOS/Linux
# or
.venv\Scripts\activate # On Windows
python main.py
Using Standard Python
python main.py
The server will start and listen on standard input/output for MCP protocol messages.
Available Tools
This demo server exposes two tools:
-
add: Simple addition function- Parameters:
a(int),b(int) - Returns: Sum of a and b
- Example:
add(5, 3)returns8
- Parameters:
-
weather_api: Fetches weather data for a city- Parameters:
city(str) - Name of the city - Returns: Weather data as text
- Note: Requires a weather API running at
http://127.0.0.1:8080
- Parameters:
Connecting from an MCP Client
To use this server with an MCP client (like Claude Desktop):
- Configure the client to use this server
- The client will communicate via stdio using JSON-RPC
- The client can call
addorweather_apitools as needed
What are the Business or Real Pain Points MCP Server Resolves?
MCP servers address several real-world challenges:
1. Data Freshness
- Problem: AI models have training cutoffs and can't access real-time data
- Solution: MCP servers provide access to live APIs, databases, and services
2. Custom Business Logic
- Problem: Generic AI models don't know your specific business processes
- Solution: MCP servers can expose domain-specific tools and workflows
3. Security & Access Control
- Problem: Direct API access from AI models raises security concerns
- Solution: MCP servers act as a controlled gateway with proper authentication
4. Integration Complexity
- Problem: Each AI application needs custom integration code
- Solution: Standardized MCP protocol works across different AI applications
5. Resource Management
- Problem: AI models need access to files, databases, and services
- Solution: MCP servers provide unified access to various resources
6. Action Execution
- Problem: AI models can only generate text, not perform actions
- Solution: MCP servers execute tools on behalf of the AI model
Can We Build Something Useful?
Absolutely! Here are practical MCP server ideas:
1. Database Query Server
- Expose SQL queries as tools
- Allow AI to query databases safely
- Use case: Business intelligence, data analysis
2. API Integration Server
- Connect to multiple third-party APIs
- Provide unified interface for AI
- Use case: CRM integration, payment processing
3. File Management Server
- Read/write files securely
- Search and organize documents
- Use case: Document management, code editing
4. Workflow Automation Server
- Execute business processes
- Trigger actions in other systems
- Use case: Task automation, notifications
5. Knowledge Base Server
- Access internal documentation
- Search company wikis
- Use case: Internal support, onboarding
6. Development Tools Server
- Run tests, deploy code
- Check logs, monitor systems
- Use case: DevOps automation, debugging
Project Structure
fastmcp-demo-server/
├── main.py # Main server file with tool definitions
├── pyproject.toml # Project dependencies and metadata
├── README.md # This file
└── uv.lock # Dependency lock file
Code Overview
The server uses FastMCP framework which simplifies MCP server creation:
@mcp.tooldecorator registers functions as MCP tools- Tools automatically get type hints and documentation
- Server handles JSON-RPC protocol automatically
mcp.run()starts the server and listens for requests
Next Steps
- Add more tools to extend functionality
- Implement error handling and validation
- Add logging for debugging
- Create resources and prompts (MCP features)
- Deploy the server for production use
- Integrate with real APIs and services
Resources
How to seyup an mcp server using uv which is a package manager
create a folder -->fastmcp-demo-server uv init . uv add fastmcp
create asimple server run the sever uv run main.py
tio run the mcp server in dev
uv run fastmcp dev main.py
to run the server
uv run fastmcp run main.py
to install server to claude desktop
uv run fastmcp install claude-desktop main.py
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
E2B
Using MCP to run code via e2b.