Skip to main content

A middleware to provide an openAI compatible endpoint that can call MCP tools.

Project description

MCP-Bridge

Discord Static Badge

MCP-Bridge acts as a bridge between the OpenAI API and MCP (MCP) tools, allowing developers to leverage MCP tools through the OpenAI API interface.

Overview

MCP-Bridge is designed to facilitate the integration of MCP tools with the OpenAI API. It provides a set of endpoints that can be used to interact with MCP tools in a way that is compatible with the OpenAI API. This allows you to use any client with any MCP tool without explicit support for MCP. For example, see this example of using Open Web UI with the official MCP fetch tool.

open web ui example

Current Features

working features:

  • non streaming chat completions with MCP

  • streaming chat completions with MCP

  • non streaming completions without MCP

  • MCP tools

  • SSE Bridge for external clients

planned features:

  • streaming completions are not implemented yet

  • MCP resources are planned to be supported

Installation

The recommended way to install MCP-Bridge is to use Docker. See the example compose.yml file for an example of how to set up docker.

Note that this requires an inference engine with tool call support. I have tested this with vLLM with success, though ollama should also be compatible.

Docker installation

  1. Clone the repository

  2. Edit the compose.yml file

You will need to add a reference to the config.json file in the compose.yml file. Pick any of

  • add the config.json file to the same directory as the compose.yml file and use a volume mount (you will need to add the volume manually)
  • add a http url to the environment variables to download the config.json file from a url
  • add the config json directly as an environment variable

see below for an example of each option:

environment:
  - MCP_BRIDGE__CONFIG__FILE=config.json # mount the config file for this to work
  - MCP_BRIDGE__CONFIG__HTTP_URL=http://10.88.100.170:8888/config.json
  - MCP_BRIDGE__CONFIG__JSON={"inference_server":{"base_url":"http://example.com/v1","api_key":"None"},"mcp_servers":{"fetch":{"command":"uvx","args":["mcp-server-fetch"]}}}

The mount point for using the config file would look like:

    volumes:
      - ./config.json:/mcp_bridge/config.json
  1. run the service
docker-compose up --build -d

Manual installation (no docker)

If you want to run the application without docker, you will need to install the requirements and run the application manually.

  1. Clone the repository

  2. Set up a dependencies:

uv sync
  1. Create a config.json file in the root directory

Here is an example config.json file:

{
   "inference_server": {
      "base_url": "http://example.com/v1",
      "api_key": "None"
   },
   "mcp_servers": {
      "fetch": {
        "command": "uvx",
        "args": ["mcp-server-fetch"]
      }
   }
}
  1. Run the application:
uv run mcp_bridge/main.py

Usage

Once the application is running, you can interact with it using the OpenAI API.

View the documentation at http://yourserver:8000/docs. There is an endpoint to list all the MCP tools available on the server, which you can use to test the application configuration.

Rest API endpoints

MCP-Bridge exposes many rest api endpoints for interacting with all of the native MCP primatives. This lets you outsource the complexity of dealing with MCP servers to MCP-Bridge without comprimising on functionality. See the openapi docs for examples of how to use this functionality.

SSE Bridge

MCP-Bridge also provides an SSE bridge for external clients. This lets external chat apps with explicit MCP support use MCP-Bridge as a MCP server. Point your client at the SSE endpoint (http://yourserver:8000/mcp-server/sse) and you should be able to see all the MCP tools available on the server.

This also makes it easy to test if your configuration is working correctly. You can use wong2/mcp-cli to test your configuration. npx @wong2/mcp-cli --sse http://localhost:8000/mcp-server/sse

If you want to use the tools inside of claude desktop or other STDIO only MCP clients, you can do this with a tool such as lightconetech/mcp-gateway

Configuration

To add new MCP servers, edit the config.json file.

an example config.json file with most of the options explicitly set:

{
    "inference_server": {
        "base_url": "http://localhost:8000/v1",
        "api_key": "None"
    },
    "mcp_servers": {
        "fetch": {
            "command": "uvx",
            "args": [
                "mcp-server-fetch"
            ]
        }
    },
    "network": {
        "host": "0.0.0.0",
        "port": 9090
    },
    "logging": {
        "log_level": "DEBUG"
    }
}
Section Description
inference_server The inference server configuration
mcp_servers The MCP servers configuration
network uvicorn network configuration
logging The logging configuration

Support

If you encounter any issues please open an issue or join the discord.

How does it work

The application sits between the OpenAI API and the inference engine. An incoming request is modified to include tool definitions for all MCP tools available on the MCP servers. The request is then forwarded to the inference engine, which uses the tool definitions to create tool calls. MCP bridge then manage the calls to the tools. The request is then modified to include the tool call results, and is returned to the inference engine again so the LLM can create a response. Finally, the response is returned to the OpenAI API.

sequenceDiagram
    participant OpenWebUI as Open Web UI
    participant MCPProxy as MCP Proxy
    participant MCPserver as MCP Server
    participant InferenceEngine as Inference Engine

    OpenWebUI ->> MCPProxy: Request
    MCPProxy ->> MCPserver: list tools
    MCPserver ->> MCPProxy: list of tools
    MCPProxy ->> InferenceEngine: Forward Request
    InferenceEngine ->> MCPProxy: Response
    MCPProxy ->> MCPserver: call tool
    MCPserver ->> MCPProxy: tool response
    MCPProxy ->> InferenceEngine: llm uses tool response
    InferenceEngine ->> MCPProxy: Response
    MCPProxy ->> OpenWebUI: Return Response

Contribution Guidelines

Contributions to MCP-Bridge are welcome! To contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them.
  4. Push your changes to your fork.
  5. Create a pull request to the main repository.

License

MCP-Bridge is licensed under the MIT License. See the LICENSE file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_bridge-0.2.0.tar.gz (98.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_bridge-0.2.0-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file mcp_bridge-0.2.0.tar.gz.

File metadata

  • Download URL: mcp_bridge-0.2.0.tar.gz
  • Upload date:
  • Size: 98.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.16

File hashes

Hashes for mcp_bridge-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1200c1d891c9b0068d886a02f0d2606d012deba9683a9107d830072ba000d461
MD5 d8f59397ec16bf553bc9ff8e07521445
BLAKE2b-256 31d9b67e1cad35d4a6e83d169909e7aad7c4124ab2bc077f1d228b3cc438d701

See more details on using hashes here.

File details

Details for the file mcp_bridge-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_bridge-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.16

File hashes

Hashes for mcp_bridge-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3dbfaa839004a0bd4f482b7f59d5547b7f3c8bd463fea377c82024cd4422835
MD5 19e1fc41df887db21f18b3cbf923eb46
BLAKE2b-256 060cc7ccbfd8464b5dfc47f8f7cd90ed4274502a0529108667c17f8f06f14de2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page