Skip to main content

Wrap a call to any remote LLM model and expose it as an MCP server tool to allow your main model to communicate with other models.

Project description

LLM Wrapper MCP Server

"Allow any MCP-capable LLM agent to communicate with or delegate tasks to any other LLM available through the OpenRouter.ai API."

A Model Context Protocol (MCP) server wrapper designed to facilitate seamless interaction with various Large Language Models (LLMs) through a standardized interface. This project enables developers to integrate LLM capabilities into their applications by providing a robust and flexible server that handles LLM calls, tool execution, and result processing.

Features

  • Implements the Model Context Protocol (MCP) specification for standardized LLM interactions.
  • Provides a FastAPI-based server for handling LLM requests and responses.
  • Supports advanced features like tool calls and results through the MCP protocol.
  • Configurable to use various LLM providers (e.g., OpenRouter, local models).
  • Designed for extensibility, allowing easy integration of new LLM backends.
  • Integrates with llm-accounting for robust logging, rate limiting, and audit functionalities, enabling monitoring of remote LLM usage, inference costs, and inspection of queries/responses for debugging or legal purposes.

Installation

  1. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install the package:
pip install -e .

Configuration

Create a .env file in the project root with the following variables:

OPENROUTER_API_KEY=your_openrouter_api_key_here
# Optional: Override default model
OPENROUTER_MODEL=your_preferred_model

The server is configured to use OpenRouter by default with the following settings:

Usage

Running the Server

To run the server, execute the following command:

python -m llm_wrapper_mcp_server

The server will start on http://localhost:8000 by default.

API Endpoints

  • POST /ask: Main endpoint for LLM requests
  • GET /health: Health check endpoint

Client Code Examples

The llm-wrapper-mcp-server package can be used by client applications to create their own MCP servers and interact with remote LLM models. Here's an example of how to set up a basic client:

from llm_wrapper_mcp_server.llm_mcp_server import LLMMCPWrapperServer
from llm_wrapper_mcp_server.llm_client import LLMClient

# Initialize the LLM MCP Wrapper Server
# This server will handle communication with the actual LLM provider
llm_server = LLMMCPWrapperServer()

# Initialize the LLM Client
# This client can be used by your application to send requests to the LLM server
llm_client = LLMClient(server_url="http://localhost:8000") # Assuming your server is running locally

async def main():
    # Example: Ask the LLM a question
    response = await llm_client.ask("What is the capital of France?")
    print(f"LLM Response: {response}")

    # Example: Use a tool (if supported by the LLM and configured)
    # This is a simplified example, actual tool usage depends on your MCP server's capabilities
    tool_response = await llm_client.use_tool("calculator", {"expression": "2+2"})
    print(f"Tool Response: {tool_response}")

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

CLI Mode Usage

The llm-wrapper-mcp-server can also be used directly from the command line for quick interactions or testing.

Basic Query:

python -m llm_wrapper_mcp_server --query "Tell me a short story about a robot."

Query with Model Specification:

python -m llm_wrapper_mcp_server --query "What is the square root of 144?" --model "perplexity/llama-3.1-sonar-small-128k-online"

Query with Tool Call (if configured):

python -m llm_wrapper_mcp_server --query "Calculate 15 * 3." --tool "calculator" --tool-args '{"expression": "15 * 3"}'

Development

Install development dependencies:

pip install -e ".[dev]"

License

MIT License

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

llm_wrapper_mcp_server-0.1.1.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

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

llm_wrapper_mcp_server-0.1.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file llm_wrapper_mcp_server-0.1.1.tar.gz.

File metadata

  • Download URL: llm_wrapper_mcp_server-0.1.1.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for llm_wrapper_mcp_server-0.1.1.tar.gz
Algorithm Hash digest
SHA256 adce34820311292c049290365ea4b1946bac2c43a34b6410d39721aba61fcff6
MD5 7de2527e498e7e8961bc8c7ab050fb9d
BLAKE2b-256 1276e03b102594db895f910c2ccfd300cf2c25016232de8cc69ebb0ed216fd6e

See more details on using hashes here.

File details

Details for the file llm_wrapper_mcp_server-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_wrapper_mcp_server-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1d13f70ba9d4815b0cd2eea295ade6d83773593fc13da65aae215ea6f2955770
MD5 3fc9c4994f2395d836ff40c03dac601c
BLAKE2b-256 71fb8fa4d7f61a4f0601b6e186d65e86425d3cefb381f9af47da8c3d86c9fb6e

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