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.1.0.tar.gz (9.0 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.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for unimcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 143ee88129fc9f9e9b63a0df36191a11b6b4bd58ec8c4e9de6e49b73f6ef734f
MD5 698e1fd12c2694db135f6f1bb17e439f
BLAKE2b-256 69d39d747cb33330d1d4db4e2420f1663b6396666d5fd4dc2fe67125957cfad8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unimcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6930c7913213927114ceb1603505e9ae16fbf485e80b8ce9b2186381ef824da4
MD5 34aa79b6d96642521855d792e6923e21
BLAKE2b-256 f34940f9cd2eaffaf1c4fa60b1208b6c1fa6ceafb5a10c2a6c6ce0e28e3a0f45

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