Skip to main content

An easy mcp deployment framework

Project description

khivemcp

khivemcp simplifies building complex, configuration-driven MCP (Model-Context Protocol) services in Python. It acts as a smart wrapper around the high-performance FastMCP server, enabling you to define your service's tools and structure using simple Python classes, decorators, and configuration files.

License: MIT PyPI - Version PyPI - Downloads Python Version

Note:

This project is in its early stages. Currently,

  • it can only be used in a virtual environment, for example if you are using uv venv in a VSCode environment, (e.g. roo, cursor, Github CodeSpace etc.)
  • it does NOT support Claude Desktop due to python path issues. If you figure out how to make it work, please open an issue or PR.

What is khivemcp?

Building services that implement the Model-Context Protocol (MCP) often requires handling server setup, tool registration according to the protocol, configuration management, and context passing. khivemcp streamlines this:

  1. Define Logic: Implement your tools or model interactions as methods within standard Python classes (Service Groups).
  2. Decorate Tools: Mark methods you want to expose as MCP tools using the simple @khivemcp.operation decorator. khivemcp handles registering them correctly with the underlying server.
  3. Configure Structure: Define which group classes to load and how to name their toolsets (operations in MCP terms) using YAML or JSON files.
  4. Run: Use the khivemcp command-line tool to load your configuration and instantly run a fully featured FastMCP server implementing MCP, with all your tools registered and ready to interact.

khivemcp manages the dynamic loading, instantiation, correct MCP tool registration, and server lifecycle, letting you focus on implementing the specific tools and logic your MCP service needs to provide.

Features

  • 🚀 Configuration-Driven: Define service structure, group instances, and MCP tool naming declaratively via YAML or JSON.
  • Decorator-Based Tools: Expose async methods as MCP tools/operations using the intuitive @khivemcp.operation decorator.
  • 📦 Dynamic Loading: Service group classes are loaded dynamically based on your configuration (class_path), promoting modularity for different toolsets.
  • 🛡️ Schema Validation: Leverage Pydantic schemas (@operation(schema=...)) for automatic validation of MCP operation inputs and clearer tool interfaces.
  • ⚙️ FastMCP Integration: Built directly on top of the efficient FastMCP library, which handles the core MCP server logic and protocol communication.
  • 📄 Stateful Tool Groups: Group classes are instantiated, allowing tools (operations) within a group instance to maintain state across calls if needed.
  • 🔧 Configurable Instances: Optionally pass custom configuration dictionaries from your config file to your group class instances during initialization.

Installation

Ensure you have Python 3.10+ and uv (or pip) installed.

uv venv
source .venv/bin/activate
uv pip install khivemcp

Quick Start

Let's create a very simple "Greeter" service and configure a client for it. An operation decorated function must be async and must only take one parameter: request (which can be None if no input is needed)

  1. Create a Service Group Class (greeter.py):

    # file: greeter.py
    from khivemcp import operation, ServiceGroup
    from pydantic import BaseModel
    
    # Optional: Define an input schema using Pydantic
    class GreetInput(BaseModel):
        name: str
    
    class GreeterGroup(ServiceGroup):
        """A very simple group that offers greetings."""
    
        @operation(name="hello", description="Says hello to the provided name.", schema=GreetInput)
        async def say_hello(self, *, request: GreetInput) -> dict:
            """Returns a personalized greeting."""
            return {"message": f"Hello, {request.name}!"}
    
        @operation(name="wave") # Takes no input
        async def wave_hand(self, *, request=None) -> dict:
             """Returns a simple wave message."""
             return {"action": "*waves*"}
    
  2. Create an khivemcp Configuration File (greeter.json):

    {
      "name": "greeter",
      "class_path": "greeter:GreeterGroup",
      "description": "A simple greeting service."
    }
    

    (This tells khivemcp to load the GreeterGroup class from greeter.py and give its tools the prefix greeter.)

  3. Add the khivemcp Server to MCP client:

    {
      "mcpServers": {
        "data-processor": {
          "command": "uv",
          "args": [
            "run",
            "python",
            "-m",
            "khivemcp.cli",
            "absolute/path/to/your_group.json"
          ]
        }
      }
    }
    

(The server starts, listening via stdio by default, and makes the greeter.hello and greeter.wave MCP operations available.)

This quick start now shows the full loop: defining the service with khivemcp, running it, configuring a standard MCP client to connect to it, and interacting.

Configuration

khivemcp uses configuration files (YAML or JSON) to define services.

  • GroupConfig: Defines a single group instance (like greeter.json above). Requires name (MCP tool prefix) and class_path.
  • ServiceConfig: Defines a service composed of multiple GroupConfig instances (using YAML is often clearer for this). Allows building complex services.

(Refer to the docs/ directory for detailed configuration options.)

Creating Service Groups

Implement logic in Python classes and use @khivemcp.operation on async def methods to expose them as MCP tools (operations). Optionally use Pydantic schemas for input validation.

(Refer to the docs/ directory for guides on creating groups, using schemas, and accessing configuration.)

Examples

Under examples

Search Group Example

To use the search group example, you must have EXA_API_KEY and PERPLEXITY_API_KEY environment variables set, in your .env file or in your environment.

DO NOT EVER SAVE API KEY IN CONFIG FILE

if you haven't already, install the required dependencies

uv pip install "khivemcp[examples]"

then add the following to your mcpServers in your MCP client configuration:

{
  "mcpServers": {
    "search-service": {
      "command": "uv",
      "args": [
        "run",
        "python",
        "-m",
        "khivemcp.cli",
        "absolute_path_to/examples/config/search_group_config.json"
      ],
      "timeout": 300,
      "alwaysAllow": []
    }
  }
}

Contributing

Contributions to the core khivemcp library are welcome! Please read the Development Style Guide (dev_style.md) before starting. It contains essential information on coding standards, testing, and the contribution workflow.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

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

khivemcp-0.1.3.tar.gz (125.0 kB view details)

Uploaded Source

Built Distribution

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

khivemcp-0.1.3-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file khivemcp-0.1.3.tar.gz.

File metadata

  • Download URL: khivemcp-0.1.3.tar.gz
  • Upload date:
  • Size: 125.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for khivemcp-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0a97d8e0eb367a94aa5e930b85f84e0eac594ab30b923c4af510bd2d825bdebb
MD5 5ae0fc27a6b1d18db383876d3d9eb828
BLAKE2b-256 b3bdc55e7b3e2017585dac6612bd969f56a7545fc37c06f86aabecb3946c1299

See more details on using hashes here.

File details

Details for the file khivemcp-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: khivemcp-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for khivemcp-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e5f0ac6c8fc05b21fd314fa5f90be243abcf70287b68d815944e989f732cd1a3
MD5 541fe4200f9923be373ee8e27d877578
BLAKE2b-256 68312a70c0a59d99d3ff60bcc537baa4f7f8f63d92a2f8002affa375ec1c5cce

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