FastAPI MCP Server

FastAPI MCP Server

A comprehensive MCP server providing 21+ tools for mathematical operations, string manipulation, file handling, utilities, and web requests via FastAPI and WebSocket.

Category
Visit Server

README

FastAPI MCP Server

A comprehensive FastAPI application with Model Context Protocol (MCP) server functionality, providing 21+ useful tools for mathematical operations, string manipulation, file handling, utilities, and web requests.

๐ŸŽฅ Demo Video

๐Ÿ“บ Watch the Demo

Direct Video Link: FastAPI MCP Server Demo Video

Click the link above to watch the demonstration video showing all 21+ tools in action!

๐ŸŽฌ Video Preview

The demo showcases:

  • โœ… Mathematical Operations - Addition, subtraction, multiplication, division, power, square root
  • โœ… String Manipulation - Uppercase, lowercase, reverse, length operations
  • โœ… File Operations - Reading, writing, and directory listing
  • โœ… Utility Functions - Time, random numbers, UUID generation, hashing
  • โœ… Web Utilities - URL validation and HTTP requests
  • โœ… MCP Protocol - WebSocket communication and tool calling

๐Ÿ“‹ Download Instructions:

  1. Click the video link above to view in GitHub
  2. Right-click on the video โ†’ "Save video as" to download
  3. Play locally for the best viewing experience

๐Ÿ”— Alternative Hosting Options:

Features

๐Ÿ”ข Mathematical Operations

  • add - Add two numbers together
  • subtract - Subtract second number from first number
  • multiply - Multiply two numbers
  • divide - Divide first number by second number (with zero-division protection)
  • power - Raise first number to the power of second number
  • sqrt - Calculate square root of a number

๐Ÿ“ String Operations

  • echo - Echo back the input text
  • uppercase - Convert text to uppercase
  • lowercase - Convert text to lowercase
  • reverse_string - Reverse a string
  • string_length - Get the length of a string

๐Ÿ“ File Operations

  • read_file - Read contents of a file
  • write_file - Write content to a file
  • list_directory - List files and directories in a path

๐Ÿ› ๏ธ Utility Functions

  • get_time - Get current server time
  • random_number - Generate a random number between min and max
  • generate_uuid - Generate a random UUID
  • hash_md5 - Generate MD5 hash of input text
  • hash_sha256 - Generate SHA256 hash of input text

๐ŸŒ Web Utilities

  • validate_url - Validate if a string is a valid URL
  • make_request - Make an HTTP request to a URL

Installation

  1. Clone the repository:
git clone https://github.com/moawizbinyamin/Fastapi-mcp-server-.git
cd Fastapi-mcp-server-
  1. Create a virtual environment:
python -m venv venv
  1. Activate the virtual environment:
# Windows
venv\Scripts\activate

# Linux/Mac
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt

Usage

Running the Server

python main.py

The server will start on http://localhost:8000

Available Endpoints

  • GET / - Root endpoint with server info
  • GET /health - Health check endpoint
  • GET /tools - List all available tools
  • POST /tools/call - Call tools via HTTP
  • WebSocket /mcp - MCP protocol endpoint
  • GET /docs - FastAPI automatic documentation

Testing Tools via HTTP

List all tools:

curl http://localhost:8000/tools

Call a tool:

curl -X POST http://localhost:8000/tools/call \
  -H "Content-Type: application/json" \
  -d '{"name": "add", "arguments": {"a": 5, "b": 3}}'

Example: Mathematical operations on 2 and 4:

# Addition: 2 + 4 = 6
curl -X POST http://localhost:8000/tools/call \
  -H "Content-Type: application/json" \
  -d '{"name": "add", "arguments": {"a": 2, "b": 4}}'

# Subtraction: 2 - 4 = -2
curl -X POST http://localhost:8000/tools/call \
  -H "Content-Type: application/json" \
  -d '{"name": "subtract", "arguments": {"a": 2, "b": 4}}'

# Multiplication: 2 ร— 4 = 8
curl -X POST http://localhost:8000/tools/call \
  -H "Content-Type: application/json" \
  -d '{"name": "multiply", "arguments": {"a": 2, "b": 4}}'

# Division: 2 รท 4 = 0.5
curl -X POST http://localhost:8000/tools/call \
  -H "Content-Type: application/json" \
  -d '{"name": "divide", "arguments": {"a": 2, "b": 4}}'

# Power: 2^4 = 16
curl -X POST http://localhost:8000/tools/call \
  -H "Content-Type: application/json" \
  -d '{"name": "power", "arguments": {"base": 2, "exponent": 4}}'

MCP Protocol Support

This server implements the Model Context Protocol (MCP) specification, allowing it to be used with MCP-compatible clients. The WebSocket endpoint /mcp handles MCP protocol communication.

MCP Configuration

For use with MCP clients, configure your MCP client with:

{
  "mcpServers": {
    "fastapi-mcp-server": {
      "command": "python",
      "args": ["main.py"],
      "cwd": "/path/to/Fastapi-mcp-server-",
      "env": {
        "PYTHONPATH": "/path/to/Fastapi-mcp-server-"
      }
    }
  }
}

Dependencies

  • FastAPI - Modern, fast web framework for building APIs
  • Uvicorn - ASGI server implementation
  • Pydantic - Data validation using Python type annotations
  • httpx - HTTP client for making web requests
  • websockets - WebSocket implementation

Error Handling

All tools include comprehensive error handling:

  • Division by zero protection
  • File not found handling
  • Invalid input validation
  • Network request error handling

Development

Project Structure

Fastapi-mcp-server-/
โ”œโ”€โ”€ main.py              # Main FastAPI application
โ”œโ”€โ”€ requirements.txt     # Python dependencies
โ”œโ”€โ”€ README.md           # This file
โ”œโ”€โ”€ .gitignore          # Git ignore rules
โ”œโ”€โ”€ start_server.bat    # Windows startup script
โ””โ”€โ”€ start_server.sh     # Linux/Mac startup script

Adding New Tools

To add a new tool:

  1. Add the tool definition to the tools dictionary in the MCPServer.__init__() method
  2. Add the tool implementation to the call_tool() method
  3. Test the tool via the HTTP endpoint

License

This project is open source and available under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For support, please open an issue on the GitHub repository.

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured