koya-rama/mcp-server-test
If you are the rightful owner of mcp-server-test 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.
A comprehensive Model Context Protocol (MCP) server implementation with multiple tools including calculator, weather, and file operations.
calculator
Perform mathematical calculations with safe expression evaluation.
weather
Retrieve mock weather data including temperature, humidity, wind speed, and conditions.
file_operations
Manage files with operations like create, read, list, and delete.
MCP Server Test
A comprehensive Model Context Protocol (MCP) server implementation with multiple tools including calculator, weather, and file operations.
Features
š§® Calculator Tool
- Perform mathematical calculations
- Safe expression evaluation
- Support for basic math functions (sin, cos, sqrt, etc.)
š¤ļø Weather Tool
- Get weather information for any city
- Mock weather data for demonstration
- Includes temperature, humidity, wind speed, and conditions
š File Operations Tool
- Create, read, list, and delete files
- Directory operations
- Safe file handling with error management
Architecture
This project includes two implementations:
mcp_server.py
- Standard MCP protocol server using stdin/stdoutapp.py
- FastAPI-based REST API server for easier testing and deployment
Installation
Prerequisites
- Python 3.8+
- pip
Setup
- Clone the repository:
git clone <repository-url>
cd mcp-server-test
- Create and activate virtual environment:
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
Usage
Running the FastAPI Server
python app.py
The server will start on http://localhost:8000
Available Endpoints
GET /
- Server informationGET /tools
- List available toolsPOST /tools/call
- Call a specific toolPOST /mcp
- MCP protocol endpointGET /docs
- Interactive API documentation (Swagger UI)
Testing the Server
Run the test client to see all tools in action:
python test_client.py
Example API Calls
Calculator Tool
curl -X POST "http://localhost:8000/tools/call" \
-H "Content-Type: application/json" \
-d '{
"tool_name": "calculator",
"arguments": {"expression": "2 + 3 * 4"}
}'
Weather Tool
curl -X POST "http://localhost:8000/tools/call" \
-H "Content-Type: application/json" \
-d '{
"tool_name": "weather",
"arguments": {"city": "New York"}
}'
File Operations Tool
curl -X POST "http://localhost:8000/tools/call" \
-H "Content-Type: application/json" \
-d '{
"tool_name": "file_operations",
"arguments": {
"operation": "create",
"filename": "hello.txt",
"content": "Hello, World!"
}
}'
Running the Standard MCP Server
For the standard MCP protocol implementation:
python mcp_server.py
This version communicates via stdin/stdout and follows the MCP protocol specification.
Development
Project Structure
mcp-server-test/
āāā app.py # FastAPI server implementation
āāā mcp_server.py # Standard MCP protocol server
āāā test_client.py # Test client for demonstration
āāā requirements.txt # Python dependencies
āāā README.md # This file
āāā venv/ # Virtual environment
Adding New Tools
- Define the tool schema in the
TOOLS
dictionary - Implement the tool function
- Add the tool call handling in the appropriate endpoint
- Update tests in
test_client.py
Deployment
Local Development
uvicorn app:app --reload --host 0.0.0.0 --port 8000
Docker Deployment
Create a Dockerfile
:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
Cloud Deployment Options
Railway
- Connect your GitHub repository to Railway
- Railway will automatically detect the Python app
- Set the start command:
uvicorn app:app --host 0.0.0.0 --port $PORT
Render
- Connect your GitHub repository to Render
- Choose "Web Service"
- Set the start command:
uvicorn app:app --host 0.0.0.0 --port $PORT
Heroku
- Create a
Procfile
:
web: uvicorn app:app --host 0.0.0.0 --port $PORT
- Deploy using Heroku CLI or GitHub integration
API Documentation
When running the FastAPI server, visit http://localhost:8000/docs
for interactive API documentation.
MCP Protocol Compliance
This server implements the MCP (Model Context Protocol) specification:
- JSON-RPC 2.0 based communication
- Tool discovery and execution
- Error handling and response formatting
- Protocol version negotiation
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
License
This project is licensed under the MIT License.
Support
For issues and questions, please open an issue on the GitHub repository.
Note: The weather tool uses mock data for demonstration purposes. In a production environment, you would integrate with a real weather API service.