Skip to main content
Glama
Acharya-Arvind

Multi-MCP Server

Multi-MCP Server

A distributed Model Context Protocol (MCP) server setup featuring multiple independent MCP servers and a master aggregator server. This project demonstrates how to build and orchestrate MCP-based services for tool calling and result aggregation.

๐Ÿš€ Features

  • Multiple MCP Servers: Three specialized MCP servers running on separate ports

    • Server 1: Greeting service

    • Server 2: Mathematical operations

    • Server 3: Text manipulation

  • Master Aggregator: A central MCP server that orchestrates calls to all three servers

  • HTTP Transport: Stateless HTTP-based communication using JSON-RPC 2.0

  • Async Support: Fully asynchronous implementation for high performance

  • Easy Deployment: Simple setup with virtual environment and uvicorn

๐Ÿ“‹ Prerequisites

  • Python 3.8+

  • Virtual environment (recommended)

๐Ÿ› ๏ธ Installation

  1. Clone the repository (if applicable) or navigate to the project directory:

    cd /path/to/Multi-MCPServer
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt

๐Ÿƒโ€โ™‚๏ธ Running the Servers

Start Individual MCP Servers

Run each server in separate terminals or background processes:

# Server 1 (Port 8001)
PORT=8001 uvicorn mcp_server1:app --host 0.0.0.0 --port 8001

# Server 2 (Port 8002)
PORT=8002 uvicorn mcp_server2:app --host 0.0.0.0 --port 8002

# Server 3 (Port 8003)
PORT=8003 uvicorn mcp_server3:app --host 0.0.0.0 --port 8003

Start Master Aggregator Server

uvicorn master_mcp:app --host 0.0.0.0 --port 8000

๐Ÿ“– Usage

Available Tools

Server 1 Tools

  • greet(name: str): Returns a personalized greeting message

Server 2 Tools

  • add(a: float, b: float): Returns the sum of two numbers

Server 3 Tools

  • reverse_text(text: str): Returns the reversed text

Master Server Tools

  • aggregate_results(input_text: str): Calls all three servers and aggregates their results

Example API Calls

Direct Server Calls

# Greet
curl -X POST http://localhost:8001/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "greet", "arguments": {"name": "World"}}, "id": 1}'

# Add numbers
curl -X POST http://localhost:8002/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "add", "arguments": {"a": 10, "b": 20}}, "id": 1}'

# Reverse text
curl -X POST http://localhost:8003/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "reverse_text", "arguments": {"text": "hello"}}, "id": 1}'

Aggregated Results

# Aggregate all results
curl -X POST http://localhost:8000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "aggregate_results", "arguments": {"input_text": "test"}}, "id": 1}'

Response:

{
  "greet_result": "Hello, test! โ€” from MCP Server 1",
  "add_result": "30.0",
  "reverse_text_result": "tset"
}

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Master MCP    โ”‚โ”€โ”€โ”€โ”€โ”‚   Server 1      โ”‚
โ”‚   (Port 8000)   โ”‚    โ”‚   (Port 8001)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                 โ”‚                       โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Server 2      โ”‚    โ”‚   Server 3      โ”‚
                    โ”‚   (Port 8002)   โ”‚    โ”‚   (Port 8003)   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  • Master Server: Orchestrates calls to individual servers

  • Individual Servers: Specialized MCP servers with unique tools

  • HTTP Transport: All communication uses HTTP with JSON-RPC 2.0 over Server-Sent Events

๐Ÿ”ง Configuration

  • Ports: Configurable via PORT environment variable (defaults: 8001, 8002, 8003)

  • Host: Default 0.0.0.0 for external access

  • Transport Security: Configurable via TransportSecuritySettings

๐Ÿงช Testing

Run the servers and use the provided curl examples to test functionality.

๐Ÿ“ฆ Dependencies

  • fastmcp: MCP server framework

  • httpx: Async HTTP client

  • uvicorn: ASGI server

  • fastapi: Web framework

See requirements.txt for full list.

๐Ÿค Contributing

  1. Fork the repository

  2. Create a feature branch

  3. Make your changes

  4. Add tests if applicable

  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Troubleshooting

Common Issues

  1. Port already in use: Change the PORT environment variable

  2. Connection refused: Ensure all servers are running

  3. JSON parsing errors: Check request format matches JSON-RPC 2.0 specification

Logs

Check server logs for detailed error information. Enable debug logging by setting LOG_LEVEL=DEBUG.

๐Ÿ“š Additional Resources

-
security - not tested
F
license - not found
-
quality - not tested

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Acharya-Arvind/Aggregate-MCP-server-sample'

If you have feedback or need assistance with the MCP directory API, please join our Discord server