Skip to main content

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

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.15.15.tar.gz (278.7 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.15.15-py3-none-any.whl (214.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hanzo_mcp-0.15.15.tar.gz
  • Upload date:
  • Size: 278.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for hanzo_mcp-0.15.15.tar.gz
Algorithm Hash digest
SHA256 225af5152e40f7d9b7e3518c87a68a98dc114d73f7e3fc396f57a57659ec0c44
MD5 025e605f1a1a2d009320e4b552a59167
BLAKE2b-256 b4129af74aa960c92170e088648b3076ccee6e87ce61d46a0740b6a4978fcf77

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hanzo_mcp-0.15.15-py3-none-any.whl
  • Upload date:
  • Size: 214.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for hanzo_mcp-0.15.15-py3-none-any.whl
Algorithm Hash digest
SHA256 b3dc8252dbbecdd7d15e5ed0c5f146dfa597832c1063c0500c303077fea127c2
MD5 3c72785287d880cd7dd6073c594ab091
BLAKE2b-256 c310ce0d3e993e35596214e82b932b74791da99cf1fccce62fe0774fe13b9d12

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.15.15 This release

2 files

0.15.14

2 files

0.15.12

2 files

0.15.11

2 files

0.15.10

2 files

0.15.9

2 files

0.15.8

2 files

0.15.7

2 files

0.15.6

2 files

0.15.5

2 files

0.15.4

2 files

0.15.3

2 files

0.15.1

2 files

0.15.0

2 files

0.14.0

2 files

0.13.1

2 files

0.13.0

2 files

0.12.9

2 files

0.12.8

2 files

0.12.7

2 files

0.12.6

2 files

0.12.5

2 files

0.12.4

2 files

0.12.3

2 files

0.12.2

2 files

0.12.1

2 files

0.12.0

2 files

0.11.8

2 files

0.11.7

2 files

0.11.6

2 files

0.11.5

2 files

0.11.4

2 files

0.11.3

2 files

0.11.2

2 files

0.11.1

2 files

0.11.0

2 files

0.10.39

2 files

0.10.38

2 files

0.10.37

2 files

0.10.36

2 files

0.10.35

2 files

0.10.34

2 files

0.10.33

2 files

0.10.32

2 files

0.10.31

2 files

0.10.30

2 files

0.10.29

2 files

0.10.28

2 files

0.10.27

2 files

0.10.26

2 files

0.10.25

2 files

0.10.24

2 files

0.10.23

2 files

0.10.22

2 files

0.10.21

2 files

0.10.20

2 files

0.10.18

2 files

0.10.17

2 files

0.10.16

2 files

0.10.8

2 files

0.10.7

2 files

0.10.6

2 files

0.10.4

2 files

0.10.3

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.23

2 files

0.9.22

2 files

0.9.19

2 files

0.9.18

2 files

0.9.16

2 files

0.9.15

2 files

0.9.14

2 files

0.9.13

2 files

0.9.12

2 files

0.9.11

2 files

0.9.10

2 files

0.9.9

2 files

0.9.8

2 files

0.9.7

2 files

0.9.5

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.15

2 files

0.8.14

2 files

0.8.13

2 files

0.8.11

2 files

0.8.8

2 files

0.8.7

2 files

0.8.6

2 files

0.8.5

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.7

2 files

0.7.6

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.13

2 files

0.6.12

2 files

0.6.10

2 files

0.6.9

2 files

0.6.8

2 files

0.6.6

2 files

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.3.8

2 files

0.3.4

2 files

0.3.3

2 files

0.3.1

2 files

0.2.0

2 files

0.1.36

2 files

0.1.35

2 files

0.1.34

2 files

0.1.33

2 files

0.1.32

2 files

0.1.30

2 files

0.1.25

2 files

0.1.21

2 files

0.1.20

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page