Multi-LLM API Gateway MCP server

Provides a unified FastAPI server for interacting with multiple language model APIs, enabling seamless switching between OpenAI and Anthropic models without changing integration code.
Back to servers
Provider
freedanfan
Release date
Mar 08, 2025
Language
Python
Stats
7 stars

This MCP Server provides a standardized interface for AI models to interact with development environments through the Model Context Protocol. It enables simplified model deployment and consistent I/O through a FastAPI-based implementation supporting JSON-RPC 2.0 and Server-Sent Events for real-time communication.

Installation

To set up the MCP server on your system:

  1. Clone the repository:
git clone https://github.com/freedanfan/mcp_server.git
cd mcp_server
  1. Install the required dependencies:
pip install -r requirements.txt

Running the Server

Start the MCP server with the default configuration:

python mcp_server.py

The server will run on 127.0.0.1:12000 by default.

Customizing Server Settings

You can customize the host and port using environment variables:

export MCP_SERVER_HOST=0.0.0.0
export MCP_SERVER_PORT=8000
python mcp_server.py

Testing with the Client

The package includes a test client to verify server functionality:

python mcp_client.py

If your server is running on a non-default address, specify it with:

export MCP_SERVER_URL="http://your-server-address:port"
python mcp_client.py

API Endpoints

The MCP server exposes the following endpoints:

  • / - Root path providing server information
  • /api - Main JSON-RPC endpoint for sending requests
  • /sse - Server-Sent Events endpoint for real-time notifications

Using the MCP Protocol

Connection Flow

  1. The client first connects to the server via the SSE endpoint
  2. The server provides the API endpoint URI
  3. The client sends an initialization request with version and capabilities
  4. The server responds with its capabilities

Sending Sample Requests

To interact with an AI model, send a sample request:

{
  "jsonrpc": "2.0",
  "id": "request-id",
  "method": "sample",
  "params": {
    "prompt": "Hello, please introduce yourself."
  }
}

The server will respond with:

{
  "jsonrpc": "2.0",
  "id": "request-id",
  "result": {
    "content": "This is a response to the prompt...",
    "usage": {
      "prompt_tokens": 10,
      "completion_tokens": 50,
      "total_tokens": 60
    }
  }
}

Ending a Session

To gracefully close your session:

{
  "jsonrpc": "2.0",
  "id": "request-id",
  "method": "shutdown",
  "params": {}
}

The server will acknowledge:

{
  "jsonrpc": "2.0",
  "id": "request-id",
  "result": {
    "status": "shutting_down"
  }
}

Troubleshooting

Common Issues

  • Connection Problems: Verify the server is running and accessible
  • Method Not Allowed (405): Check you're using the correct API endpoint
  • SSE Connection Failures: Check for firewall or network issues

Enabling Debug Logs

For more detailed logging:

export PYTHONPATH=.
python -m logging -v DEBUG -m mcp_server

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later