Get the FREE Ultimate OpenClaw Setup Guide →

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.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. 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

  2. (Optional) Create and activate a virtual environment: python -m venv venv

    macOS/Linux

    source venv/bin/activate

    Windows

    venv\Scripts\activate

  3. Install dependencies via uv or pip:

    Using uv (preferred in README):

    uv sync

    Or install explicitly:

    uv add mcp[cli] fastapi uvicorn python-dotenv

  4. Set up environment variables (example): PORT=10000 LOG_DIR=logs

    Create a .env file with these values in the project root if needed

  5. 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

  6. (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

Sponsor this space

Reach thousands of developers