Skip to main content

MCP server base framework for the ourochronos ecosystem

Reason this release was yanked:

Not ready for use

Project description

our-mcp-base

Base framework for building MCP (Model Context Protocol) servers in the ourochronos ecosystem.

Overview

our-mcp-base provides reusable patterns for MCP server implementations: an abstract base class with lifecycle hooks, a decorator-based tool router, and consistent response formatting. It reduces boilerplate and ensures all MCP servers in the ecosystem follow the same conventions.

Install

pip install our-mcp-base

Requires mcp>=1.0.

Usage

Basic Server

from mcp.types import Tool
from our_mcp_base import MCPServerBase

class MyServer(MCPServerBase):
    server_name = "my-server"

    def get_tools(self) -> list[Tool]:
        return [
            Tool(name="greet", description="Say hello", inputSchema={...}),
        ]

    def handle_tool(self, name: str, arguments: dict) -> dict:
        if name == "greet":
            return {"success": True, "message": f"Hello, {arguments['name']}!"}
        return {"success": False, "error": f"Unknown tool: {name}"}

if __name__ == "__main__":
    MyServer().run()

With Lifecycle Hooks

MyServer(
    startup_hook=lambda: init_database(),
    health_check=lambda: check_db_connection(),
).run()

Run with --health-check to execute the health check and exit, or --skip-startup-hook to skip initialization.

Tool Router

from our_mcp_base import ToolRouter

router = ToolRouter()

@router.register("greet")
def handle_greet(name: str, enthusiasm: int = 1) -> dict:
    return {"success": True, "message": f"Hello, {name}{'!' * enthusiasm}"}

# In handle_tool:
result = router.dispatch(name, arguments)

Response Helpers

from our_mcp_base import success_response, error_response, not_found_response

success_response(data="value", count=42)
# → {"success": True, "data": "value", "count": 42}

error_response("Invalid input", code=400)
# → {"success": False, "error": "Invalid input", "code": 400}

not_found_response("Belief", "belief-123")
# → {"success": False, "error": "Belief not found: belief-123"}

Custom Error Handling

def handle_db_error(exc: Exception, tool_name: str) -> list[TextContent]:
    return [TextContent(type="text", text=json.dumps({"success": False, "error": str(exc)}))]

server = MyServer(error_handlers=[(DatabaseError, handle_db_error)])

API

Symbol Description
MCPServerBase Abstract base class — implement get_tools() and handle_tool()
ToolRouter Decorator-based tool dispatch registry
success_response(**kwargs) Returns {success: True, ...}
error_response(error, **kwargs) Returns {success: False, error: str, ...}
not_found_response(type, id) Returns a 404-style error response

Development

# Install with dev dependencies
make dev

# Run linters
make lint

# Run tests
make test

# Run tests with coverage
make test-cov

# Auto-format
make format

State Ownership

None. This package provides base classes and utilities only. State is owned by the concrete MCP server implementations that inherit from MCPServerBase.

Part of Valence

This brick is part of the Valence knowledge substrate. See our-infra for ourochronos conventions.

License

MIT

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

our_mcp_base-0.1.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

our_mcp_base-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for our_mcp_base-0.1.0.tar.gz
Algorithm Hash digest
SHA256 844b4c2fb9c2dec7ee31456fe2534b94860f8a9b9af7efe5be9207911b944501
MD5 97546ce59f901dc58606491182bc2fb5
BLAKE2b-256 a2975341b6100285cd5a59435aa727850cb00117433b10cbe3621c7b03f15741

See more details on using hashes here.

File details

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

File metadata

  • Download URL: our_mcp_base-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for our_mcp_base-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7098ed2a06fa62225467a907a028d6904f8cddee88ba8c0845abc24a2c60bbb5
MD5 35a8b4b01822ca1b47928af42a802c05
BLAKE2b-256 a2dc8278b445fca93aaaf5aab78756f2c821433a0f30eee174a08e2ae1416e45

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