Multiple s-Using-FastAPI-and-Testing-with-Inspector
This project provides a framework for running multiple Model Context Protocol (MCP) servers using different transport mechanisms: FastAPI-based HTTP servers, standalone streamable-http servers, and stdio-based servers.
claude mcp add --transport stdio ahmad-act-multiple-mcp-servers-using-fastapi-and-testing-with-inspector python src/mcp-server-with-stdio.py
How to use
This MCP server package provides three Python-based implementations to run multiple MCP servers using different transports. You can run a standalone stdio MCP server for Inspector-driven communication, a standalone streamable-http MCP server for HTTP-based testing, or a FastAPI-based server hosting two MCP instances accessible under distinct endpoints. All servers implement a simple echo tool to demonstrate tool interactions via the MCP Inspector. To test using the Inspector, run the Inspector against the desired server type and interact with the echo tool to validate request/response flow and transport behavior.
How to install
Prerequisites:
- Python 3.8+ installed
- Node.js and npx (for MCP Inspector testing)
- uv (Python package manager) for dependency management
Installation steps:
-
Clone the repository: git clone https://github.com/ahmad-act/Multiple-MCP-Servers-Using-FastAPI-and-Testing-with-Inspector.git cd Multiple-MCP-Servers-Using-FastAPI-and-Testing-with-Inspector
-
(Optional) Create and activate a virtual environment: python -m venv venv
macOS/Linux
source venv/bin/activate
Windows
venv\Scripts\activate
-
Install dependencies via uv or pip:
Using uv (preferred in README):
uv sync
Or install explicitly:
uv add mcp[cli] fastapi uvicorn python-dotenv
-
Set up environment variables (example): PORT=10000 LOG_DIR=logs
Create a .env file with these values in the project root if needed
-
Run any of the MCP servers (examples): python src/mcp-server-with-stdio.py python src/mcp-server-with-streamable-http.py python src/mcp-server-fastapi.py
-
(Optional) Start MCP Inspector for testing against stdio or streamable-http servers using npx: npx @modelcontextprotocol/inspector uv --directory "<your-src-directory>" run mcp-server-with-stdio.py --debug
Note: The exact commands assume you are running from the project root and that Python scripts are accessible at the specified paths. Adjust paths if you clone the repository in a different layout.
Additional notes
Tips and notes:
- The framework provides three transport options: stdio (Inspector-driven), streamable-http (HTTP-based), and a FastAPI server hosting multiple MCP instances. Choose the transport that fits your testing scenario.
- Environment configuration is centralized via .env, enabling PORT and LOG_DIR customization. Ensure your log directory exists or is creatable by the app.
- The MCP Inspector is compatible with these servers; use the Inspector to interactively test the echo tool and observe MCP session lifecycles.
- For FastAPI-based usage, you get two MCP instances exposed at distinct endpoints (e.g., /echo1/mcp/ and /echo2/mcp/) with streamable-http transport.
- Ensure that your Python environment has the required packages: mcp[cli], fastapi, uvicorn, and python-dotenv.
- Graceful shutdown handling is implemented; monitor SIGINT/SIGTERM to verify clean termination of servers.
Related MCP Servers
mcp-vegalite
MCP server from isaacwasserman/mcp-vegalite-server
github-chat
A Model Context Protocol (MCP) for analyzing and querying GitHub repositories using the GitHub Chat API.
nautex
MCP server for guiding Coding Agents via end-to-end requirements to implementation plan pipeline
pagerduty
PagerDuty's official local MCP (Model Context Protocol) server which provides tools to interact with your PagerDuty account directly from your MCP-enabled client.
futu-stock
mcp server for futuniuniu stock
mcp -boilerplate
Boilerplate using one of the 'better' ways to build MCP Servers. Written using FastMCP