basic_mcp_server
If you are the rightful owner of basic_mcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This document provides a structured summary of a basic MCP server example implementing a weather service using FastMCP.
Basic MCP Example - Weather Service
This is a basic example demonstrating how to implement an MCP (Multi-Cloud Protocol) server using FastMCP. The example implements a simple weather service that showcases the three main MCP components: tools, resources, and prompts.
Purpose
This project serves as a learning example to demonstrate:
- How to create an MCP server using FastMCP
- How to implement MCP tools, resources, and prompts
- Basic MCP server structure and implementation
Implementation Details
The server implements three MCP components to demonstrate different interaction patterns:
-
Tool:
get_weather(location: str)
- Example of a simple MCP tool
- Shows how to define a tool with parameters
- Demonstrates tool return values
-
Resource:
weather://{location}
- Example of MCP resource usage
- Shows resource URL pattern matching
- Demonstrates resource parameter handling
-
Prompt:
weather_report(location: str)
- Example of MCP prompt implementation
- Shows how to create formatted prompts
- Demonstrates prompt parameter usage
Running the Example
To run this example:
- Install FastMCP library
- Run
server.py
directly
Requirements
- Python 3.13 or higher
- MCP library with CLI support (
mcp[cli]
)
Project Structure
server.py
: MCP server implementationmain.py
: Entry point that runs the serverpyproject.toml
: Project configuration.gitignore
: Git ignore rules
Running the Example
To run this example, follow these steps:
-
Install uv package manager:
# On macOS/Linux curl -fsSL https://uv.rs/install.sh | bash # On Windows winget install uv
-
Create and activate a virtual environment:
uv venv .venv source .venv/bin/activate # On Unix/macOS # or .venv\Scripts\activate # On Windows
-
Install the required dependencies:
uv pip install -r pyproject.toml
-
Run the server using mcp dev:
mcp dev main.py
-
The server will start and listen on:
- Host: localhost (127.0.0.1)
- Port: 8080
- Transport: Server-Sent Events (SSE)
-
Test the server using tiny agent client:
tiny-agents run agent.json
The server implements three endpoints:
- Tool:
get_weather(location: str)
- Resource:
weather://{location}
- Prompt:
weather_report(location: str)
- Tool:
-
To stop the server, press Ctrl+C in the terminal
Note
This is a basic example that returns static data. In a real application, you would:
- Connect to actual data sources
- Implement proper error handling
- Add authentication and authorization
- Implement proper logging
- Add comprehensive documentation
- Configure different transport methods beyond SSE
- Add proper server configuration options
- Implement production-ready error handling
- Add monitoring and metrics
- Configure proper port management
- Add environment variable support
- Handle edge cases and validation
This example is intentionally kept simple to focus on MCP concepts rather than production considerations.