{"type":"mcp_client","name":"mcp-openai","description":"This repository provides a minimal MCP client library, enabling LLM UIs to support the Model Context Protocol through an OpenAI-compatible API. It facilitates integration with locally runnable inference engines.","category":"AI","language":"Python","stars":53,"forks":2,"owner":"S1M0N38","github_url":"https://github.com/S1M0N38/mcp-openai","homepage":null,"setup":"## Setup\nIt is highly recommended to use [uv](https://docs.astral.sh/uv/) in your project based on mpc-openai.\nAdd mcp-openai to your project dependencies with:\n\n```\nuv add mcp-openai\n```\n\nor use classic pip install.\n\n### Create a MCP client\nNow you can create a MCP client by specifying your custom configuration.\n\n```python\nfrom mcp_openai import MCPClient\nfrom mcp_openai import config\n\nmcp_client_config = config.MCPClientConfig(\n    mcpServers={\n        \"the-name-of-the-server\": config.MCPServerConfig(\n            command=\"uv\",\n            args=[\"run\", \"path/to/server/scripts.py/or/github/raw\"],\n        )\n        # add here other servers ...\n    }\n)\n\nllm_client_config = config.LLMClientConfig(\n    api_key=\"api-key-for-auth\",\n    base_url=\"https://api.openai.com/v1\",\n)\n\nllm_request_config = config.LLMRequestConfig(model=os.environ[\"MODEL_NAME\"])\n\nclient = MCPClient(\n    mcp_client_config,\n    llm_client_config,\n    llm_request_config,\n)\n```\n\n### Connect and process messages with MCP client\n\n```python\nasync def main():\n\n    # Establish connection between the client and the server.\n    await client.connect_to_server(server_name)\n\n    # messages_in are coming from user interacting with the LLM\n    # e.g. UI making use of this MCP client.\n    messages_in = ...\n    messages_out = await client.process_messages(messages_in)\n\n    # messages_out contains the LLM response. If required, the LLM make use of\n    # the available tools offered by the connected servers.\n```","tools":"## Available Tools\n\n1.  MCP Client (library for building LLMs UI that support MCP through an OpenAI compatible API)\n2.  OpenAI compatible API (supports text generation, function calling, etc.)\n3.  `MCPClient` class (for creating a MCP client with custom configuration)\n4.  `connect_to_server` method (establishes connection between the client and the server)\n5.  `process_messages` method (processes messages and returns the LLM response)","faq":null,"created_at":"2024-12-25T00:16:10+00:00","updated_at":"2025-03-27T01:36:08+00:00","source_url":"https://model-context-protocol.com/clients/mcp-client-openai-compatible-api","related_articles":[]}