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.
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:
- Define Logic: Implement your tools or model interactions as methods within standard Python classes (Service Groups).
- Decorate Tools: Mark methods you want to expose as MCP tools using the
simple
@khivemcp.operationdecorator. khivemcp handles registering them correctly with the underlying server. - Configure Structure: Define which group classes to load and how to name their toolsets (operations in MCP terms) using YAML or JSON files.
- Run: Use the
khivemcpcommand-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
asyncmethods as MCP tools/operations using the intuitive@khivemcp.operationdecorator. - 📦 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. - 📝 TypeScript-Style Schema Notation: Research-backed schema format achieving 78.9% token reduction vs JSON Schema, making tool definitions more efficient and readable for LLM consumption.
- 🎯 Function Call Syntax: Natural Python function call syntax for tool
invocation (
tool_name(arg1, arg2, key=value)) with 52% token reduction vs JSON, enabling more intuitive API interactions. - ⚡ Parallel Execution: Built-in support for batch and parallel tool
execution using the
parallelizable=Trueflag, allowing concurrent operations for improved performance. - 🔀 Union Schema Support: Define multiple input types per operation with automatic validation, enabling flexible tool interfaces that accept different request formats.
- ⚙️ FastMCP Integration: Built directly on top of the efficient
FastMCPlibrary, 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)
-
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*"}
-
Create an khivemcp Configuration File (
greeter.json):{ "name": "greeter", "class_path": "greeter:GreeterGroup", "description": "A simple greeting service." }
(This tells khivemcp to load the
GreeterGroupclass fromgreeter.pyand give its tools the prefixgreeter.) -
Add the khivemcp Server to MCP client:
{ "mcpServers": { "greeter": { "command": "uv", "args": [ "run", "python", "-m", "khivemcp.cli", "absolute/path/to/greeter.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 (likegreeter.jsonabove). Requiresname(MCP tool prefix) andclass_path.ServiceConfig: Defines a service composed of multipleGroupConfiginstances (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": "absolute_path_to/.venv/bin/python",
"args": [
"-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 Apache License 2.0 - see the LICENSE file for details.
Acknowledgements
Metadata
Release files for khivemcp 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| khivemcp-1.2.0.tar.gz | 196.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| khivemcp-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 231.7 kB
Release files / khivemcp-1.2.0.tar.gz
| Download URL | khivemcp-1.2.0.tar.gz |
|---|---|
| Size | 196.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea216c00bdd4ee17ffa45667b4986af7e507184f964d8f3e3f2631ea77aad2a9
|
|
BLAKE2b-256 checksum How to use checksums |
e0bdef9f4ff2a8321317ef960ce29ce7ef02529e22eb39620cc7578b221b5155
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / khivemcp-1.2.0-py3-none-any.whl
| Download URL | khivemcp-1.2.0-py3-none-any.whl |
|---|---|
| Size | 35.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bcb1181094e6de1dbd4a85ed88f93470a62e78c7dc7ea9867320e5343f8bde17
|
|
BLAKE2b-256 checksum How to use checksums |
285e174c6910d7ae6b6e79a4ec057dfababe1db5c0afd4296635a75932c4eb5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for khivemcp 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.