Metadata-Version: 2.4
Name: hanzo-mcp
Version: 0.8.15
Summary: The Zen of Hanzo MCP: One server to rule them all. The ultimate MCP that orchestrates all others.
Author-email: Hanzo Industries Inc <dev@hanzo.ai>
License: MIT
Project-URL: Homepage, https://github.com/hanzoai/mcp
Project-URL: Bug Tracker, https://github.com/hanzoai/mcp/issues
Project-URL: Documentation, https://mcp.hanzo.ai
Keywords: mcp,claude,hanzo,code,agent
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: mcp>=1.9.4
Requires-Dist: fastmcp>=2.9.2
Requires-Dist: httpx>=0.28.1
Requires-Dist: uvicorn>=0.34.0
Requires-Dist: openai>=1.62.0
Requires-Dist: python-dotenv>=1.0.1
Requires-Dist: litellm>=1.73.2
Requires-Dist: grep-ast>=0.8.1
Requires-Dist: bashlex>=0.18
Requires-Dist: libtmux>=0.39.0
Requires-Dist: nbformat>=5.10.4
Requires-Dist: psutil>=6.0.0
Requires-Dist: pydantic>=2.9.2
Requires-Dist: pydantic-settings>=2.7.0
Requires-Dist: typing-extensions>=4.13.0
Requires-Dist: watchdog>=6.0.0
Requires-Dist: keyring>=24.0.0
Requires-Dist: ffind>=1.3.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
Requires-Dist: ruff>=0.13.0; extra == "dev"
Requires-Dist: black>=23.3.0; extra == "dev"
Requires-Dist: sphinx>=8.0.0; extra == "dev"
Requires-Dist: sphinx-rtd-theme>=3.0.0; extra == "dev"
Requires-Dist: myst-parser>=4.0.0; extra == "dev"
Requires-Dist: sphinx-copybutton>=0.5.0; extra == "dev"
Requires-Dist: mypy>=1.10.0; extra == "dev"
Requires-Dist: types-aiofiles>=23.2.0; extra == "dev"
Requires-Dist: types-psutil>=5.9.5; extra == "dev"
Requires-Dist: types-setuptools>=69.5.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=8.0.0; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=3.0.0; extra == "docs"
Requires-Dist: myst-parser>=4.0.0; extra == "docs"
Requires-Dist: sphinx-copybutton>=0.5.0; extra == "docs"
Provides-Extra: analytics
Requires-Dist: posthog>=3.0.0; extra == "analytics"
Provides-Extra: test
Requires-Dist: pytest>=7.0.0; extra == "test"
Requires-Dist: pytest-cov>=4.1.0; extra == "test"
Requires-Dist: pytest-mock>=3.10.0; extra == "test"
Requires-Dist: pytest-asyncio>=0.25.3; extra == "test"
Requires-Dist: twisted; extra == "test"
Provides-Extra: agents
Requires-Dist: hanzo-agents>=0.1.0; extra == "agents"
Provides-Extra: memory
Requires-Dist: hanzo-memory>=1.0.0; extra == "memory"
Provides-Extra: performance
Requires-Dist: ujson>=5.7.0; extra == "performance"
Requires-Dist: orjson>=3.9.0; extra == "performance"
Provides-Extra: publish
Requires-Dist: twine>=4.0.2; extra == "publish"
Requires-Dist: build>=1.0.3; extra == "publish"

# Hanzo Model Context Protocol (MCP)

[![PyPI](https://img.shields.io/pypi/v/hanzo-mcp.svg)](https://pypi.org/project/hanzo-mcp/)
[![Python Version](https://img.shields.io/pypi/pyversions/hanzo-mcp.svg)](https://pypi.org/project/hanzo-mcp/)

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

## Installation

```bash
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

```python
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

```python
# 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

```python
# 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

```python
# 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

```python
# 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

```python
# 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

```python
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

```python
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

```python
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

```bash
# 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

```yaml
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

```bash
# Install to Claude Desktop
hanzo-mcp install-desktop

# Serve MCP
hanzo-mcp serve --port 3000
```

### Standalone Server

```bash
# 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

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

### Testing

```bash
# Unit tests
pytest tests/ -v

# Integration tests
pytest tests/ -m integration

# With coverage
pytest tests/ --cov=hanzo_mcp
```

### Building

```bash
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
