Skip to main content

MCP Client with OpenAI compatible API

Project description

𝔐  mpc-openai  ✧

MCP Client with OpenAI compatible API

Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications.

https://modelcontextprotocol.io


[!WARNING] This project is still in the early stages of development. Support is not planned.

This is a MCP client (not a server). It is meant to be used as a library for building LLMs UI that support MCP through an OpenAI compatible API. This opens the door to locally runnable inference engines (vLLM, Ollama, TGI, llama.cpp, LMStudio, ...) that support providing support for the OpenAI API (text generation, function calling, etc.).

Usage

It is highly recommended to use uv in your project based on mpc-openai:

  • It manages python installation and virtual environment.
  • It is an executable that can run self-contained python scripts (in our case MCP server)
  • It is used for CI workflows.

Add mcp-openai to your project dependencies with:

uv add mcp-openai

or use classic pip install.

Create a MCP client

Now you can create a MCP client by specifying your custom configuration.

from mcp_openai import MCPClient
from mcp_openai import config

mcp_client_config = config.MCPClientConfig(
    mcpServers={
        "the-name-of-the-server": config.MCPServerConfig(
            command="uv",
            args=["run", "path/to/server/scripts.py/or/github/raw"],
        )
        # add here other servers ...
    }
)

llm_client_config = config.LLMClientConfig(
    api_key="api-key-for-auth",
    base_url="https://api.openai.com/v1",
)

llm_request_config = config.LLMRequestConfig(model=os.environ["MODEL_NAME"])

client = MCPClient(
    mcp_client_config,
    llm_client_config,
    llm_request_config,
)

Connect and process messages with MCP client

async def main():

    # Establish connection between the client and the server.
    await client.connect_to_server(server_name)

    # messages_in are coming from user interacting with the LLM
    # e.g. UI making use of this MCP client.
    messages_in = ...
    messages_out = await client.process_messages(messages_in)

    # messages_out contains the LLM response. If required, the LLM make use of
    # the available tools offered by the connected servers.

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_openai-0.2.0.tar.gz (24.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_openai-0.2.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mcp_openai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 56d7a726ea796ba25240a16b304b1ea1827c110f39c400cd083037d9c717061e
MD5 36d5e29408f99ba728127e36f46a9442
BLAKE2b-256 2b87149904ffeb5032af4144f9df7f58f60036daf01376178edb412f7d2d9629

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mcp_openai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8ae6717f315230fb09c8306523af3cc905198f5cefd2c911f4e132faac85396
MD5 358468c2cdd536d156ed0065e4cb9ec1
BLAKE2b-256 de278f4b0d9cb16a6e05155c549b7f48ba96476ab94d8ec4d7c31c58a093d3d2

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