Skip to main content

hexastack-mcp

hexastack-mcp

Model Context Protocol (MCP) adapter and AI agent tool integration for Hexastack.

PyPI: hexastack-mcp Python 3.13+ Coverage Part of Hexastack Governed by Hexaqual License: Apache 2.0

Part of the Hexastack Framework · Governed by Hexaqual.


1. Overview & Capabilities

hexastack-mcp exposes Hexastack application services directly to AI agents (Claude Desktop, Cursor, Antigravity, custom LLM agents) via the official Anthropic Model Context Protocol:

  • Automatic CQRS Tool Generation (@mcp_tool): Decorates CQRS Command and Query models, converting them into structured LLM tools with JSON Schema validation.
  • Resource URI Providers (@mcp_resource): Exposes read endpoints and system diagnostics as readable MCP resources (hexastack://schema, hexastack://info).
  • Prompt Templates (@mcp_prompt): Configures reusable workflow prompts for LLM clients.
  • Multiple Transports:
    • Standard I/O (stdio): Local process communication for desktop assistants and subprocess agents.
    • Server-Sent Events (sse): HTTP SSE transport via FastAPI for remote agent networks.
  • Metrics & Observability (McpMetricsMiddleware): Tracks tool, resource, and prompt execution throughput and duration metrics against MetricsPort.
  • Single-Pass Reflection: Discovers decorated tools and resources in Phase 3 module scanning via create_mcp_visitor.

2. Package Anatomy & Key Components

hexastack_mcp/
├── domain/          # McpToolMetadata, McpResourceMetadata, McpPromptMetadata, McpError
├── adapters/        # stdio runner, sse/FastAPI router, FastMCP server wrapper
└── infra/
    ├── bootstrap.py # McpBootstrapper (order=40)
    ├── config.py    # HexastackMcpConfig
    ├── decorators.py# @mcp_tool, @mcp_resource, @mcp_prompt
    ├── autodiscovery.py # create_mcp_visitor
    └── registries/  # server.py (McpServerRegistry)

Key Exports

Category Exports
Adapters run_stdio_server, create_sse_router, mount_mcp_sse
Bootstrap McpBootstrapper (order=40), HexastackMcpConfig
Decorators @mcp_tool, @mcp_resource, @mcp_prompt
Registries McpServerRegistry, get_mcp_registry

3. Monorepo & Sibling Relationships

graph TD
    subgraph Agents ["AI Agent Clients (Claude, Cursor, Antigravity)"]
        STDIO_CLIENT["Local Desktop / Subprocess (stdio)"]
        SSE_CLIENT["Remote Agent Network (SSE / HTTP)"]
    end

    subgraph McpAdapter ["hexastack-mcp"]
        SERVER["FastMCP / MCP Server"]
        REG["McpServerRegistry (Tools, Resources, Prompts)"]
        DISPATCH["CQRS Tool Dispatcher"]
    end

    subgraph CQRSExecution ["hexastack-cqrs"]
        CBUS["CommandBusPort"]
        QBUS["QueryBusPort"]
    end

    subgraph WebIntegration ["hexastack-fastapi (Optional)"]
        FASTAPI_APP["FastAPI Application (SSE Endpoint)"]
    end

    STDIO_CLIENT --> SERVER
    SSE_CLIENT --> FASTAPI_APP
    FASTAPI_APP --> SERVER
    SERVER --> REG
    REG --> DISPATCH
    DISPATCH -->|dispatches commands| CBUS
    DISPATCH -->|dispatches queries| QBUS

Explicit Dependencies (Direct)

  • hexastack-core: DI container, configuration registry, base exceptions.
  • hexastack-cqrs: CommandBusPort and QueryBusPort for message dispatching.
  • mcp>=1.3.0: Official Anthropic Model Context Protocol SDK.

Implied / Behavioral Relationships (DI-Mediated)

  • FastAPI SSE Integration: McpBootstrapper (order=40) attaches SSE endpoints to the active FastAPI instance when hexastack-fastapi is present and auto_mount_fastapi=true.
  • CQRS Dispatching: When an LLM executes an MCP tool, the adapter resolves CommandBusPort or QueryBusPort to run the command through the full middleware pipeline.

Optional Integrations (Extras)

  • [fastapi]: Installs hexastack-fastapi and fastapi>=0.141.1 for remote SSE transport over HTTP.

4. Installation

# Standalone stdio transport
pip install hexastack-mcp

# With FastAPI remote SSE transport
pip install "hexastack-mcp[fastapi]"

# Via umbrella package
pip install "hexastack[mcp]"

5. Configuration Reference

[hexastack.mcp]
server_name = "Hexastack MCP Server"
server_version = "0.1.0"
sse_path = "/sse" # Route prefix for SSE transport
auto_mount_fastapi = true # Auto-mount SSE router into FastAPI on bootstrap

6. Quickstart Example

from dataclasses import dataclass
from hexastack_core.infra.bootstrap import bootstrap
from hexastack_cqrs.domain.query import Query
from hexastack_cqrs.infra.decorators import query_handler
from hexastack_mcp.infra.decorators import mcp_tool


# 1. Define CQRS Query & Handler
@dataclass(frozen=True)
class CheckSystemStatusQuery(Query):
    service: str = "database"


@query_handler(CheckSystemStatusQuery)
class CheckSystemStatusHandler:
    def __call__(self, qry: CheckSystemStatusQuery) -> dict[str, str]:
        return {"service": qry.service, "status": "HEALTHY"}


# 2. Expose as MCP Tool for AI Agents
mcp_tool(
    name="check_status",
    description="Check the real-time operational status of internal subsystems.",
)(CheckSystemStatusQuery)

# 3. Bootstrap Runtime and Run MCP Server
runtime = bootstrap(packages_to_scan=[__name__])
mcp_server = runtime.get("mcp_server")

Metadata

Release files for hexastack-mcp 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hexastack-mcp 0.7.0
File Size Uploaded
hexastack_mcp-0.7.0.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hexastack-mcp 0.7.0
File Interpreter ABI Platform
hexastack_mcp-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.7 kB

Release files / hexastack_mcp-0.7.0.tar.gz

Download URL hexastack_mcp-0.7.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
74a2d2100d9510a53ecb78f764211647944841c01ed177998c892d2f2aae3ae3
BLAKE2b-256 checksum
How to use checksums
1d046e1fbfc1da62ddf36bc0d9892acedbd3295d32d8ddf37c92c75e5c7bcd0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / hexastack_mcp-0.7.0-py3-none-any.whl

Download URL hexastack_mcp-0.7.0-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce9015f2c62e568d89e94413e46d2ac50c4d0315a3934c9ce42e97d8cbbb78d5
BLAKE2b-256 checksum
How to use checksums
a8c4e9a400bbaeacd25554dbe2a5534230f9933d5410c78301735ee769c10727
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.8.0

2 release files

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page