Files
zeekayandHanzo Dev d3110e47ea Major refactor: Unified tools, palette system, dev mode, and shell improvements (v0.6.0)
🎨 **Tool Palette System**
- Created palette system for organizing development tools by ecosystem
- Pre-defined palettes: Python (Guido), Ruby (Matz), JavaScript, Go, Rust, DevOps, Full Stack, Minimal
- `palette` tool to list, activate, and manage tool sets
- Environment variables applied from active palette
- Keeps MCP interface clean while supporting specialized workflows

🔧 **Unified Process Tools with OO Design**
- Refactored all process execution to use clean base class hierarchy
- `BaseProcessTool`, `BaseBinaryTool`, `BaseScriptTool` for consistent interface
- Unified `bash`, `npx`, `uvx` tools with action-based approach (run/background)
- `process` tool for managing background processes
- All tools use same execution pipeline internally

🐚 **Smart Shell Detection**
- Shell tool now detects user's preferred shell from $SHELL environment
- Automatically uses zsh if .zshrc exists (perfect for your setup\!)
- Falls back to bash if no special configuration found
- All zsh aliases, functions, and configurations now available in MCP

🚀 **Development Mode with Hot Reload**
- Added `--dev` flag to hanzo-mcp CLI for development mode
- File watching with automatic reload detection using watchdog
- `hanzo-mcp-dev` command for dedicated dev server
- Watches Python files and config changes
- Debounced reloading to prevent spam

🛠️ **New Tools Added**
- `open`: Opens files/URLs in default application (platform-aware)
- `watch`: Monitors files/directories for changes with pattern matching
- `diff`: Compares files with unified/context diff formats
- `config`: Git-style configuration management

📚 **Documentation & Infrastructure**
- Comprehensive Sphinx documentation with black theme
- Automated deployment to mcp.hanzo.ai via Cloudflare Pages
- GitHub Actions workflow for docs deployment
- 25+ documentation pages organized by category

⚙️ **Configuration Improvements**
- Tool enable/disable system with palette override
- Per-project vs global indexing configuration
- Environment variable management through palettes
- Clean separation of concerns in tool registration

This release provides a much cleaner, more extensible architecture while
maintaining backward compatibility. The palette system makes it easy to
switch between development environments, and the unified process tools
eliminate code duplication while providing consistent behavior.

Co-authored-by: Hanzo Dev <[email protected]>
2025-06-26 17:59:24 -04:00

116 lines
4.3 KiB
Python

"""Vector indexing tool for adding documents to vector database."""
from typing import Dict, List, Optional, TypedDict, Unpack, final
from pathlib import Path
from mcp.server.fastmcp import Context as MCPContext
from pydantic import Field
from hanzo_mcp.tools.common.base import BaseTool
from hanzo_mcp.tools.common.permissions import PermissionManager
from hanzo_mcp.tools.common.validation import validate_path_parameter
from .infinity_store import InfinityVectorStore
from .project_manager import ProjectVectorManager
class VectorIndexParams(TypedDict, total=False):
"""Parameters for vector indexing operations."""
file_path: str
content: Optional[str]
chunk_size: Optional[int]
chunk_overlap: Optional[int]
metadata: Optional[Dict[str, str]]
@final
class VectorIndexTool(BaseTool):
"""Tool for indexing documents in the vector database."""
def __init__(self, permission_manager: PermissionManager, project_manager: ProjectVectorManager):
"""Initialize the vector index tool.
Args:
permission_manager: Permission manager for access control
project_manager: Project-aware vector store manager
"""
self.permission_manager = permission_manager
self.project_manager = project_manager
@property
def name(self) -> str:
"""Get the tool name."""
return "vector_index"
@property
def description(self) -> str:
"""Get the tool description."""
return """Index documents in project-aware vector databases for semantic search.
Can index individual text content or entire files. Files are automatically assigned
to the appropriate project database based on LLM.md detection or stored in the global
database. Files are chunked for optimal search performance.
Projects are detected by finding LLM.md files, with databases stored in .hanzo/db
directories alongside them. Use this to build searchable knowledge bases per project."""
async def call(
self,
ctx: MCPContext,
**params: Unpack[VectorIndexParams],
) -> str:
"""Index content or files in the vector database.
Args:
ctx: MCP context
**params: Tool parameters
Returns:
Indexing result message
"""
file_path = params.get("file_path")
content = params.get("content")
chunk_size = params.get("chunk_size", 1000)
chunk_overlap = params.get("chunk_overlap", 200)
metadata = params.get("metadata", {})
if not file_path and not content:
return "Error: Either file_path or content must be provided"
try:
if file_path:
# Validate file access
# Use permission manager's existing validation
if not self.permission_manager.is_path_allowed(file_path):
return f"Error: Access denied to path {file_path}"
if not Path(file_path).exists():
return f"Error: File does not exist: {file_path}"
# Index file using project-aware manager
doc_ids, project_info = self.project_manager.add_file_to_appropriate_store(
file_path=file_path,
chunk_size=chunk_size,
chunk_overlap=chunk_overlap,
metadata=metadata,
)
file_name = Path(file_path).name
if project_info:
return f"Successfully indexed {file_name} with {len(doc_ids)} chunks in project '{project_info.name}'"
else:
return f"Successfully indexed {file_name} with {len(doc_ids)} chunks in global database"
else:
# Index content directly in global store (no project context)
global_store = self.project_manager._get_global_store()
doc_id = global_store.add_document(
content=content,
metadata=metadata,
)
return f"Successfully indexed content as document {doc_id} in global database"
except Exception as e:
return f"Error indexing content: {str(e)}"