Skip to main content

A simple client library to connect to any MCP server and interact with LLMs.

Project description

UniMCP

A simple client library to connect to any MCP server and interact with tools seamlessly via code or through an LLM.

Installation

pip install unimcp

(Note: While in development, you can install it locally using pip install -e .)

Features

  • Simple MCP Client: Connect to any MCP server, list available tools, and call them directly with just a few lines of Python.
  • LLM Integration: Built-in wrapper to hook your MCP server tools directly into OpenAI (or any OpenAI-compatible API), enabling an LLM agent out-of-the-box.

Usage

1. Using only the MCP Client (No LLM)

import asyncio
from unimcp import UniClient

async def main():
    # Connect to your MCP server
    async with UniClient("http://localhost:8000/sse") as client:
        # 1. Get available tools
        tools = await client.get_tools()
        print("Available tools:", [t.name for t in tools])

        # 2. Call a specific tool manually
        result = await client.call_tool("my_tool_name", {"arg1": "value"})
        print("Tool Result:", result)

if __name__ == "__main__":
    asyncio.run(main())

2. Using the LLM Client

This utilizes OpenAI's python library under the hood. You can configure it using environment variables (OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MODEL) or pass them directly.

import asyncio
from unimcp import UniClient, UniLLM

async def main():
    async with UniClient("http://localhost:8000/sse") as client:
        
        # Initialize the LLM with the MCP client
        # It automatically detects OPENAI_API_KEY from environment variables
        llm = UniLLM(client, model_name="gpt-4o")
        
        # Optionally set a system prompt
        llm.set_system_prompt("You are a helpful assistant with access to MCP tools.")

        # Chat with the LLM (it will automatically use the tools if needed)
        response = await llm.chat("Can you perform an action using your tools?")
        print("AI:", response)

if __name__ == "__main__":
    asyncio.run(main())

Environment Variables

The UniLLM automatically respects the following standard environment variables:

  • OPENAI_API_KEY: Your API key.
  • OPENAI_BASE_URL: For connecting to local LLMs (like LMStudio, Ollama) or other providers.
  • OPENAI_MODEL: Default model to use (fallback is gpt-4o).

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

unimcp-0.2.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

unimcp-0.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unimcp-0.2.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for unimcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6ada2f5747d1d7233c32646b53e946791041e8bf49f3a544723100d892abd568
MD5 e0e6e521f45fde3c9d9a33679ff967cb
BLAKE2b-256 cfbe4a6ac03f0554c2971717d1db3bdb510a9965ea160216e9c2767fd3a54afe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unimcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for unimcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22f134661d6a82ef4299873d7021de9082a191906b7d9232d3b40feb768e0090
MD5 c9b1b0d5d6fe48a761e46a882f77a74f
BLAKE2b-256 feb6bf2e389728584c511c37da90e688a1eed432222a4f80e931c3d93a283f56

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