Skip to main content

The Zen of Hanzo MCP: One server to rule them all. The ultimate MCP that orchestrates all others.

Project description

Hanzo Model Context Protocol (MCP)

PyPI Python Version

Model Context Protocol implementation for advanced tool use and context management.

Installation

pip install hanzo-mcp

Features

  • Tool Management: Register and manage AI tools
  • File Operations: Read, write, edit files
  • Code Intelligence: AST analysis, symbol search
  • Shell Execution: Run commands safely
  • Agent Delegation: Recursive agent capabilities
  • Memory Integration: Persistent context storage
  • Batch Operations: Execute multiple tools efficiently

Quick Start

Basic Usage

from hanzo_mcp import create_mcp_server

# Create MCP server
server = create_mcp_server()

# Register tools
server.register_filesystem_tools()
server.register_shell_tools()
server.register_agent_tools()

# Start server
await server.start()

Tool Categories

Filesystem Tools

# Read file
content = await server.tools.read(file_path="/path/to/file.py")

# Write file
await server.tools.write(
    file_path="/path/to/new.py",
    content="print('Hello')"
)

# Edit file
await server.tools.edit(
    file_path="/path/to/file.py",
    old_string="old code",
    new_string="new code"
)

# Multi-edit
await server.tools.multi_edit(
    file_path="/path/to/file.py",
    edits=[
        {"old_string": "foo", "new_string": "bar"},
        {"old_string": "baz", "new_string": "qux"}
    ]
)

Search Tools

# Unified search (grep + AST + semantic)
results = await server.tools.search(
    pattern="function_name",
    path="/project"
)

# AST-aware search
results = await server.tools.grep_ast(
    pattern="class.*Service",
    path="/src"
)

# Symbol search
symbols = await server.tools.symbols(
    pattern="def test_",
    path="/tests"
)

Shell Tools

# Run command
result = await server.tools.bash(
    command="ls -la",
    cwd="/project"
)

# Run with auto-backgrounding
result = await server.tools.bash(
    command="python server.py",
    timeout=120000  # Auto-backgrounds after 2 min
)

# Manage processes
processes = await server.tools.process(action="list")
logs = await server.tools.process(
    action="logs",
    id="bash_abc123"
)

Agent Tools

# Dispatch agent for complex tasks
result = await server.tools.dispatch_agent(
    prompt="Analyze the codebase architecture",
    path="/project"
)

# Network of agents
result = await server.tools.network(
    task="Implement user authentication",
    agents=["architect", "developer", "tester"]
)

# CLI tool integration
result = await server.tools.claude(
    args=["--analyze", "main.py"]
)

Batch Operations

# Execute multiple tools in parallel
results = await server.tools.batch(
    description="Read multiple files",
    invocations=[
        {"tool_name": "read", "input": {"file_path": "file1.py"}},
        {"tool_name": "read", "input": {"file_path": "file2.py"}},
        {"tool_name": "grep", "input": {"pattern": "TODO"}}
    ]
)

Advanced Features

Custom Tools

from hanzo_mcp import Tool

class MyCustomTool(Tool):
    name = "my_tool"
    description = "Custom tool"
    
    async def call(self, ctx, **params):
        # Tool implementation
        return "Result"

# Register custom tool
server.register_tool(MyCustomTool())

Permission Management

from hanzo_mcp import PermissionManager

# Create permission manager
pm = PermissionManager()

# Set permission mode
pm.set_mode("review")  # review, auto_approve, auto_deny

# Check permission
allowed = await pm.check_permission(
    tool="write",
    params={"file_path": "/etc/passwd"}
)

Context Management

from hanzo_mcp import ToolContext

# Create context
ctx = ToolContext(
    cwd="/project",
    env={"API_KEY": "secret"},
    timeout=30000
)

# Use with tools
result = await tool.call(ctx, **params)

Configuration

Environment Variables

# API keys for agent tools
ANTHROPIC_API_KEY=sk-ant-...
OPENAI_API_KEY=sk-...

# Tool settings
MCP_PERMISSION_MODE=review
MCP_MAX_FILE_SIZE=10485760
MCP_TIMEOUT=120000

# Search settings
MCP_SEARCH_IGNORE=node_modules,*.pyc
MCP_SEARCH_MAX_RESULTS=100

Configuration File

tools:
  filesystem:
    enabled: true
    max_file_size: 10MB
    allowed_paths:
      - /home/user/projects
      - /tmp
    
  shell:
    enabled: true
    timeout: 120000
    auto_background: true
    
  agent:
    enabled: true
    models:
      - claude-3-opus
      - gpt-4
    
  search:
    ignore_patterns:
      - node_modules
      - "*.pyc"
      - .git
    max_results: 100

permissions:
  mode: review  # review, auto_approve, auto_deny
  whitelist:
    - read
    - grep
    - search
  blacklist:
    - rm
    - sudo

CLI Usage

Installation to Claude Desktop

# Install to Claude Desktop
hanzo-mcp install-desktop

# Serve MCP
hanzo-mcp serve --port 3000

Standalone Server

# Start MCP server
hanzo-mcp serve

# With custom config
hanzo-mcp serve --config mcp-config.yaml

# With specific tools
hanzo-mcp serve --tools filesystem,shell,agent

Development

Setup

cd pkg/hanzo-mcp
uv sync --all-extras

Testing

# Unit tests
pytest tests/ -v

# Integration tests
pytest tests/ -m integration

# With coverage
pytest tests/ --cov=hanzo_mcp

Building

uv build

Architecture

Tool Categories

  • Filesystem: File operations (read, write, edit)
  • Search: Code search (grep, AST, semantic)
  • Shell: Command execution and process management
  • Agent: AI agent delegation and orchestration
  • Memory: Context and knowledge persistence
  • Config: Configuration management
  • LLM: Direct LLM interactions

Security

  • Permission system for dangerous operations
  • Path validation and sandboxing
  • Command injection protection
  • Rate limiting on operations
  • Audit logging

License

Apache License 2.0

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hanzo_mcp-0.10.18.tar.gz (211.1 kB view details)

Uploaded Source

Built Distribution

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

hanzo_mcp-0.10.18-py3-none-any.whl (143.8 kB view details)

Uploaded Python 3

File details

Details for the file hanzo_mcp-0.10.18.tar.gz.

File metadata

  • Download URL: hanzo_mcp-0.10.18.tar.gz
  • Upload date:
  • Size: 211.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for hanzo_mcp-0.10.18.tar.gz
Algorithm Hash digest
SHA256 731a7aec3984b5770fc6198e28088e21ba3035b695530a4aa828133b1411a70b
MD5 00e9eda62faad7d749b93846aa37fce3
BLAKE2b-256 6020e37905b41ff92a8d96bc2399c8de3d1b651e9e9fbe4eb761d1f0c846b708

See more details on using hashes here.

File details

Details for the file hanzo_mcp-0.10.18-py3-none-any.whl.

File metadata

  • Download URL: hanzo_mcp-0.10.18-py3-none-any.whl
  • Upload date:
  • Size: 143.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for hanzo_mcp-0.10.18-py3-none-any.whl
Algorithm Hash digest
SHA256 09b10ad96ca5d61b7cc58583beaefee80bb7a49e18250ee5e89b3f8c03046045
MD5 933627bbb67156cc0cf58fb77c4d85a1
BLAKE2b-256 b35d76cc4f2237f92d8d841fa0477348762e186ccc2d4a00cf456a299b391ff1

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