hanzo-mcp 0.1.20__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hanzo-mcp might be problematic. Click here for more details.

Files changed (52) hide show
  1. hanzo_mcp-0.1.20/LICENSE +21 -0
  2. hanzo_mcp-0.1.20/PKG-INFO +111 -0
  3. hanzo_mcp-0.1.20/README.md +70 -0
  4. hanzo_mcp-0.1.20/hanzo_mcp/__init__.py +3 -0
  5. hanzo_mcp-0.1.20/hanzo_mcp/cli.py +213 -0
  6. hanzo_mcp-0.1.20/hanzo_mcp/server.py +149 -0
  7. hanzo_mcp-0.1.20/hanzo_mcp/tools/__init__.py +81 -0
  8. hanzo_mcp-0.1.20/hanzo_mcp/tools/agent/__init__.py +59 -0
  9. hanzo_mcp-0.1.20/hanzo_mcp/tools/agent/agent_tool.py +474 -0
  10. hanzo_mcp-0.1.20/hanzo_mcp/tools/agent/prompt.py +137 -0
  11. hanzo_mcp-0.1.20/hanzo_mcp/tools/agent/tool_adapter.py +75 -0
  12. hanzo_mcp-0.1.20/hanzo_mcp/tools/common/__init__.py +18 -0
  13. hanzo_mcp-0.1.20/hanzo_mcp/tools/common/base.py +216 -0
  14. hanzo_mcp-0.1.20/hanzo_mcp/tools/common/context.py +444 -0
  15. hanzo_mcp-0.1.20/hanzo_mcp/tools/common/permissions.py +253 -0
  16. hanzo_mcp-0.1.20/hanzo_mcp/tools/common/thinking_tool.py +123 -0
  17. hanzo_mcp-0.1.20/hanzo_mcp/tools/common/validation.py +124 -0
  18. hanzo_mcp-0.1.20/hanzo_mcp/tools/filesystem/__init__.py +89 -0
  19. hanzo_mcp-0.1.20/hanzo_mcp/tools/filesystem/base.py +113 -0
  20. hanzo_mcp-0.1.20/hanzo_mcp/tools/filesystem/content_replace.py +287 -0
  21. hanzo_mcp-0.1.20/hanzo_mcp/tools/filesystem/directory_tree.py +286 -0
  22. hanzo_mcp-0.1.20/hanzo_mcp/tools/filesystem/edit_file.py +287 -0
  23. hanzo_mcp-0.1.20/hanzo_mcp/tools/filesystem/get_file_info.py +170 -0
  24. hanzo_mcp-0.1.20/hanzo_mcp/tools/filesystem/read_files.py +198 -0
  25. hanzo_mcp-0.1.20/hanzo_mcp/tools/filesystem/search_content.py +275 -0
  26. hanzo_mcp-0.1.20/hanzo_mcp/tools/filesystem/write_file.py +162 -0
  27. hanzo_mcp-0.1.20/hanzo_mcp/tools/jupyter/__init__.py +71 -0
  28. hanzo_mcp-0.1.20/hanzo_mcp/tools/jupyter/base.py +284 -0
  29. hanzo_mcp-0.1.20/hanzo_mcp/tools/jupyter/edit_notebook.py +295 -0
  30. hanzo_mcp-0.1.20/hanzo_mcp/tools/jupyter/notebook_operations.py +514 -0
  31. hanzo_mcp-0.1.20/hanzo_mcp/tools/jupyter/read_notebook.py +165 -0
  32. hanzo_mcp-0.1.20/hanzo_mcp/tools/project/__init__.py +64 -0
  33. hanzo_mcp-0.1.20/hanzo_mcp/tools/project/analysis.py +882 -0
  34. hanzo_mcp-0.1.20/hanzo_mcp/tools/project/base.py +66 -0
  35. hanzo_mcp-0.1.20/hanzo_mcp/tools/project/project_analyze.py +173 -0
  36. hanzo_mcp-0.1.20/hanzo_mcp/tools/shell/__init__.py +58 -0
  37. hanzo_mcp-0.1.20/hanzo_mcp/tools/shell/base.py +148 -0
  38. hanzo_mcp-0.1.20/hanzo_mcp/tools/shell/command_executor.py +740 -0
  39. hanzo_mcp-0.1.20/hanzo_mcp/tools/shell/run_command.py +204 -0
  40. hanzo_mcp-0.1.20/hanzo_mcp/tools/shell/run_script.py +215 -0
  41. hanzo_mcp-0.1.20/hanzo_mcp/tools/shell/script_tool.py +244 -0
  42. hanzo_mcp-0.1.20/hanzo_mcp.egg-info/PKG-INFO +111 -0
  43. hanzo_mcp-0.1.20/hanzo_mcp.egg-info/SOURCES.txt +50 -0
  44. hanzo_mcp-0.1.20/hanzo_mcp.egg-info/dependency_links.txt +1 -0
  45. hanzo_mcp-0.1.20/hanzo_mcp.egg-info/entry_points.txt +2 -0
  46. hanzo_mcp-0.1.20/hanzo_mcp.egg-info/requires.txt +27 -0
  47. hanzo_mcp-0.1.20/hanzo_mcp.egg-info/top_level.txt +1 -0
  48. hanzo_mcp-0.1.20/pyproject.toml +71 -0
  49. hanzo_mcp-0.1.20/setup.cfg +4 -0
  50. hanzo_mcp-0.1.20/tests/test_cli.py +316 -0
  51. hanzo_mcp-0.1.20/tests/test_server.py +171 -0
  52. hanzo_mcp-0.1.20/tests/test_validation.py +118 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 hanzoai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,111 @@
1
+ Metadata-Version: 2.4
2
+ Name: hanzo-mcp
3
+ Version: 0.1.20
4
+ Summary: MCP implementation of Hanzo capabilities
5
+ Author-email: hanzoai <sdglbl.me@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/hanzoai/mcp
8
+ Project-URL: Bug Tracker, https://github.com/hanzoai/mcp/issues
9
+ Project-URL: Documentation, https://github.com/hanzoai/mcp/blob/main/README.md
10
+ Keywords: mcp,claude,hanzo,code,agent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.13
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: mcp>=1.3.0
18
+ Requires-Dist: httpx>=0.27.0
19
+ Requires-Dist: uvicorn>=0.23.1
20
+ Requires-Dist: openai>=1.50.0
21
+ Requires-Dist: python-dotenv>=1.0.0
22
+ Requires-Dist: litellm>=1.40.14
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
25
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
26
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
27
+ Requires-Dist: black>=23.3.0; extra == "dev"
28
+ Provides-Extra: test
29
+ Requires-Dist: pytest>=7.0.0; extra == "test"
30
+ Requires-Dist: pytest-cov>=4.1.0; extra == "test"
31
+ Requires-Dist: pytest-mock>=3.10.0; extra == "test"
32
+ Requires-Dist: pytest-asyncio>=0.25.3; extra == "test"
33
+ Requires-Dist: twisted; extra == "test"
34
+ Provides-Extra: performance
35
+ Requires-Dist: ujson>=5.7.0; extra == "performance"
36
+ Requires-Dist: orjson>=3.9.0; extra == "performance"
37
+ Provides-Extra: publish
38
+ Requires-Dist: twine>=4.0.2; extra == "publish"
39
+ Requires-Dist: build>=1.0.3; extra == "publish"
40
+ Dynamic: license-file
41
+
42
+ # Hanzo MCP
43
+
44
+ An implementation of Hanzo capabilities using the Model Context Protocol (MCP).
45
+
46
+ ## Overview
47
+
48
+ This project provides an MCP server that implements Hanzo-like functionality, allowing Claude to directly execute instructions for modifying and improving project files. By leveraging the Model Context Protocol, this implementation enables seamless integration with various MCP clients including Claude Desktop.
49
+
50
+ ![example](./doc/example.gif)
51
+
52
+ ## Features
53
+
54
+ - **Code Understanding**: Analyze and understand codebases through file access and pattern searching
55
+ - **Code Modification**: Make targeted edits to files with proper permission handling
56
+ - **Enhanced Command Execution**: Run commands and scripts in various languages with improved error handling and shell support
57
+ - **File Operations**: Manage files with proper security controls through shell commands
58
+ - **Code Discovery**: Find relevant files and code patterns across your project
59
+ - **Project Analysis**: Understand project structure, dependencies, and frameworks
60
+ - **Agent Delegation**: Delegate complex tasks to specialized sub-agents that can work concurrently
61
+ - **Multiple LLM Provider Support**: Configure any LiteLLM-compatible model for agent operations
62
+ - **Jupyter Notebook Support**: Read and edit Jupyter notebooks with full cell and output handling
63
+
64
+ ## Tools Implemented
65
+
66
+ | Tool | Description |
67
+ | ---------------------- | --------------------------------------------------------------------------------------------- |
68
+ | `read_files` | Read one or multiple files with encoding detection |
69
+ | `write_file` | Create or overwrite files |
70
+ | `edit_file` | Make line-based edits to text files |
71
+ | `directory_tree` | Get a recursive tree view of directories |
72
+ | `get_file_info` | Get metadata about a file or directory |
73
+ | `search_content` | Search for patterns in file contents |
74
+ | `content_replace` | Replace patterns in file contents |
75
+ | `run_command` | Execute shell commands (also used for directory creation, file moving, and directory listing) |
76
+ | `run_script` | Execute scripts with specified interpreters |
77
+ | `script_tool` | Execute scripts in specific programming languages |
78
+ | `project_analyze_tool` | Analyze project structure and dependencies |
79
+ | `read_notebook` | Extract and read source code from all cells in a Jupyter notebook with outputs |
80
+ | `edit_notebook` | Edit, insert, or delete cells in a Jupyter notebook |
81
+ | `think` | Structured space for complex reasoning and analysis without making changes |
82
+ | `dispatch_agent` | Launch one or more agents that can perform tasks using read-only tools concurrently |
83
+
84
+ ## Getting Started
85
+
86
+ For detailed installation and configuration instructions, please refer to [INSTALL.md](./doc/INSTALL.md).
87
+
88
+ Of course, you can also read [USEFUL_PROMPTS](./doc/USEFUL_PROMPTS.md) for some inspiration on how to use hanzo-mcp.
89
+
90
+ ## Security
91
+
92
+ This implementation follows best practices for securing access to your filesystem:
93
+
94
+ - Permission prompts for file modifications and command execution
95
+ - Restricted access to specified directories only
96
+ - Input validation and sanitization
97
+ - Proper error handling and reporting
98
+
99
+ ## Development
100
+
101
+ To contribute to this project:
102
+
103
+ 1. Fork the repository
104
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
105
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
106
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
107
+ 5. Open a Pull Request
108
+
109
+ ## License
110
+
111
+ This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,70 @@
1
+ # Hanzo MCP
2
+
3
+ An implementation of Hanzo capabilities using the Model Context Protocol (MCP).
4
+
5
+ ## Overview
6
+
7
+ This project provides an MCP server that implements Hanzo-like functionality, allowing Claude to directly execute instructions for modifying and improving project files. By leveraging the Model Context Protocol, this implementation enables seamless integration with various MCP clients including Claude Desktop.
8
+
9
+ ![example](./doc/example.gif)
10
+
11
+ ## Features
12
+
13
+ - **Code Understanding**: Analyze and understand codebases through file access and pattern searching
14
+ - **Code Modification**: Make targeted edits to files with proper permission handling
15
+ - **Enhanced Command Execution**: Run commands and scripts in various languages with improved error handling and shell support
16
+ - **File Operations**: Manage files with proper security controls through shell commands
17
+ - **Code Discovery**: Find relevant files and code patterns across your project
18
+ - **Project Analysis**: Understand project structure, dependencies, and frameworks
19
+ - **Agent Delegation**: Delegate complex tasks to specialized sub-agents that can work concurrently
20
+ - **Multiple LLM Provider Support**: Configure any LiteLLM-compatible model for agent operations
21
+ - **Jupyter Notebook Support**: Read and edit Jupyter notebooks with full cell and output handling
22
+
23
+ ## Tools Implemented
24
+
25
+ | Tool | Description |
26
+ | ---------------------- | --------------------------------------------------------------------------------------------- |
27
+ | `read_files` | Read one or multiple files with encoding detection |
28
+ | `write_file` | Create or overwrite files |
29
+ | `edit_file` | Make line-based edits to text files |
30
+ | `directory_tree` | Get a recursive tree view of directories |
31
+ | `get_file_info` | Get metadata about a file or directory |
32
+ | `search_content` | Search for patterns in file contents |
33
+ | `content_replace` | Replace patterns in file contents |
34
+ | `run_command` | Execute shell commands (also used for directory creation, file moving, and directory listing) |
35
+ | `run_script` | Execute scripts with specified interpreters |
36
+ | `script_tool` | Execute scripts in specific programming languages |
37
+ | `project_analyze_tool` | Analyze project structure and dependencies |
38
+ | `read_notebook` | Extract and read source code from all cells in a Jupyter notebook with outputs |
39
+ | `edit_notebook` | Edit, insert, or delete cells in a Jupyter notebook |
40
+ | `think` | Structured space for complex reasoning and analysis without making changes |
41
+ | `dispatch_agent` | Launch one or more agents that can perform tasks using read-only tools concurrently |
42
+
43
+ ## Getting Started
44
+
45
+ For detailed installation and configuration instructions, please refer to [INSTALL.md](./doc/INSTALL.md).
46
+
47
+ Of course, you can also read [USEFUL_PROMPTS](./doc/USEFUL_PROMPTS.md) for some inspiration on how to use hanzo-mcp.
48
+
49
+ ## Security
50
+
51
+ This implementation follows best practices for securing access to your filesystem:
52
+
53
+ - Permission prompts for file modifications and command execution
54
+ - Restricted access to specified directories only
55
+ - Input validation and sanitization
56
+ - Proper error handling and reporting
57
+
58
+ ## Development
59
+
60
+ To contribute to this project:
61
+
62
+ 1. Fork the repository
63
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
64
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
65
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
66
+ 5. Open a Pull Request
67
+
68
+ ## License
69
+
70
+ This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,3 @@
1
+ """Hanzo MCP - Implementation of Hanzo capabilities using MCP."""
2
+
3
+ __version__ = "0.1.8"
@@ -0,0 +1,213 @@
1
+ """Command-line interface for the Hanzo MCP server."""
2
+
3
+ import argparse
4
+ import json
5
+ import os
6
+ import sys
7
+ from pathlib import Path
8
+ from typing import Any, cast
9
+
10
+ from hanzo_mcp.server import HanzoServer
11
+
12
+
13
+ def main() -> None:
14
+ """Run the CLI for the Hanzo MCP server."""
15
+ parser = argparse.ArgumentParser(
16
+ description="MCP server implementing Hanzo capabilities"
17
+ )
18
+
19
+ _ = parser.add_argument(
20
+ "--transport",
21
+ choices=["stdio", "sse"],
22
+ default="stdio",
23
+ help="Transport protocol to use (default: stdio)",
24
+ )
25
+
26
+ _ = parser.add_argument(
27
+ "--name",
28
+ default="claude-code",
29
+ help="Name of the MCP server (default: claude-code)",
30
+ )
31
+
32
+ _ = parser.add_argument(
33
+ "--allow-path",
34
+ action="append",
35
+ dest="allowed_paths",
36
+ help="Add an allowed path (can be specified multiple times)",
37
+ )
38
+
39
+ _ = parser.add_argument(
40
+ "--project-dir", dest="project_dir", help="Set the project directory to analyze"
41
+ )
42
+
43
+ _ = parser.add_argument(
44
+ "--agent-model",
45
+ dest="agent_model",
46
+ help="Specify the model name in LiteLLM format (e.g., 'openai/gpt-4o', 'anthropic/claude-3-sonnet')"
47
+ )
48
+
49
+ _ = parser.add_argument(
50
+ "--agent-max-tokens",
51
+ dest="agent_max_tokens",
52
+ type=int,
53
+ help="Specify the maximum tokens for agent responses"
54
+ )
55
+
56
+ _ = parser.add_argument(
57
+ "--agent-api-key",
58
+ dest="agent_api_key",
59
+ help="Specify the API key for the LLM provider (for development/testing only)"
60
+ )
61
+
62
+ _ = parser.add_argument(
63
+ "--agent-max-iterations",
64
+ dest="agent_max_iterations",
65
+ type=int,
66
+ default=10,
67
+ help="Maximum number of iterations for agent (default: 10)"
68
+ )
69
+
70
+ _ = parser.add_argument(
71
+ "--agent-max-tool-uses",
72
+ dest="agent_max_tool_uses",
73
+ type=int,
74
+ default=30,
75
+ help="Maximum number of total tool uses for agent (default: 30)"
76
+ )
77
+
78
+ _ = parser.add_argument(
79
+ "--enable-agent-tool",
80
+ dest="enable_agent_tool",
81
+ action="store_true",
82
+ default=False,
83
+ help="Enable the agent tool (disabled by default)"
84
+ )
85
+
86
+ _ = parser.add_argument(
87
+ "--install",
88
+ action="store_true",
89
+ help="Install server configuration in Claude Desktop",
90
+ )
91
+
92
+ args = parser.parse_args()
93
+
94
+ # Cast args attributes to appropriate types to avoid 'Any' warnings
95
+ name: str = cast(str, args.name)
96
+ install: bool = cast(bool, args.install)
97
+ transport: str = cast(str, args.transport)
98
+ project_dir: str | None = cast(str | None, args.project_dir)
99
+ agent_model: str | None = cast(str | None, args.agent_model)
100
+ agent_max_tokens: int | None = cast(int | None, args.agent_max_tokens)
101
+ agent_api_key: str | None = cast(str | None, args.agent_api_key)
102
+ agent_max_iterations: int = cast(int, args.agent_max_iterations)
103
+ agent_max_tool_uses: int = cast(int, args.agent_max_tool_uses)
104
+ enable_agent_tool: bool = cast(bool, args.enable_agent_tool)
105
+ allowed_paths: list[str] = (
106
+ cast(list[str], args.allowed_paths) if args.allowed_paths else []
107
+ )
108
+
109
+ if install:
110
+ install_claude_desktop_config(name, allowed_paths)
111
+ return
112
+
113
+ # If no allowed paths are specified, use the current directory
114
+ if not allowed_paths:
115
+ allowed_paths = [os.getcwd()]
116
+
117
+ # If project directory is specified, add it to allowed paths
118
+ if project_dir and project_dir not in allowed_paths:
119
+ allowed_paths.append(project_dir)
120
+
121
+ # Run the server
122
+ server = HanzoServer(
123
+ name=name,
124
+ allowed_paths=allowed_paths,
125
+ agent_model=agent_model,
126
+ agent_max_tokens=agent_max_tokens,
127
+ agent_api_key=agent_api_key,
128
+ agent_max_iterations=agent_max_iterations,
129
+ agent_max_tool_uses=agent_max_tool_uses,
130
+ enable_agent_tool=enable_agent_tool
131
+ )
132
+ # Transport will be automatically cast to Literal['stdio', 'sse'] by the server
133
+ server.run(transport=transport)
134
+
135
+
136
+ def install_claude_desktop_config(
137
+ name: str = "claude-code", allowed_paths: list[str] | None = None
138
+ ) -> None:
139
+ """Install the server configuration in Claude Desktop.
140
+
141
+ Args:
142
+ name: The name to use for the server in the config
143
+ allowed_paths: Optional list of paths to allow
144
+ """
145
+ # Find the Claude Desktop config directory
146
+ home: Path = Path.home()
147
+
148
+ if sys.platform == "darwin": # macOS
149
+ config_dir: Path = home / "Library" / "Application Support" / "Claude"
150
+ elif sys.platform == "win32": # Windows
151
+ config_dir = Path(os.environ.get("APPDATA", "")) / "Claude"
152
+ else: # Linux and others
153
+ config_dir = home / ".config" / "claude"
154
+
155
+ config_file: Path = config_dir / "claude_desktop_config.json"
156
+
157
+ # Create directory if it doesn't exist
158
+ config_dir.mkdir(parents=True, exist_ok=True)
159
+
160
+ # Get current script path
161
+ script_path: Path = Path(sys.executable)
162
+
163
+ # Create args array
164
+ args: list[str] = ["-m", "hanzo_mcp.cli"]
165
+
166
+ # Add allowed paths if specified
167
+ if allowed_paths:
168
+ for path in allowed_paths:
169
+ args.extend(["--allow-path", path])
170
+ else:
171
+ # Allow home directory by default
172
+ args.extend(["--allow-path", str(home)])
173
+
174
+ # Create config object
175
+ config: dict[str, Any] = {
176
+ "mcpServers": {name: {"command": str(script_path), "args": args}}
177
+ }
178
+
179
+ # Check if the file already exists
180
+ if config_file.exists():
181
+ try:
182
+ with open(config_file, "r") as f:
183
+ existing_config: dict[str, Any] = json.load(f)
184
+
185
+ # Update the existing config
186
+ if "mcpServers" not in existing_config:
187
+ existing_config["mcpServers"] = {}
188
+
189
+ existing_config["mcpServers"][name] = config["mcpServers"][name]
190
+ config = existing_config
191
+ except Exception as e:
192
+ print(f"Error reading existing config: {e}")
193
+ print("Creating new config file.")
194
+
195
+ # Write the config file
196
+ with open(config_file, mode="w") as f:
197
+ json.dump(config, f, indent=2)
198
+
199
+ print(f"Successfully installed {name} in Claude Desktop configuration.")
200
+ print(f"Config file: {config_file}")
201
+
202
+ if allowed_paths:
203
+ print("\nAllowed paths:")
204
+ for path in allowed_paths:
205
+ print(f"- {path}")
206
+ else:
207
+ print(f"\nDefault allowed path: {home}")
208
+ print("\nYou can modify allowed paths in the config file directly.")
209
+ print("Restart Claude Desktop for changes to take effect.")
210
+
211
+
212
+ if __name__ == "__main__":
213
+ main()
@@ -0,0 +1,149 @@
1
+ """MCP server implementing Hanzo capabilities."""
2
+
3
+ from typing import Literal, cast, final
4
+
5
+ from mcp.server.fastmcp import FastMCP
6
+
7
+ from hanzo_mcp.tools import register_all_tools
8
+ from hanzo_mcp.tools.common.context import DocumentContext
9
+ from hanzo_mcp.tools.common.permissions import PermissionManager
10
+ from hanzo_mcp.tools.project.analysis import ProjectAnalyzer, ProjectManager
11
+ from hanzo_mcp.tools.shell.command_executor import CommandExecutor
12
+
13
+
14
+ @final
15
+ class HanzoServer:
16
+ """MCP server implementing Hanzo capabilities."""
17
+
18
+ def __init__(
19
+ self,
20
+ name: str = "claude-code",
21
+ allowed_paths: list[str] | None = None,
22
+ mcp_instance: FastMCP | None = None,
23
+ agent_model: str | None = None,
24
+ agent_max_tokens: int | None = None,
25
+ agent_api_key: str | None = None,
26
+ agent_max_iterations: int = 10,
27
+ agent_max_tool_uses: int = 30,
28
+ enable_agent_tool: bool = False,
29
+ ):
30
+ """Initialize the Hanzo server.
31
+
32
+ Args:
33
+ name: The name of the server
34
+ allowed_paths: list of paths that the server is allowed to access
35
+ mcp_instance: Optional FastMCP instance for testing
36
+ agent_model: Optional model name for agent tool in LiteLLM format
37
+ agent_max_tokens: Optional maximum tokens for agent responses
38
+ agent_api_key: Optional API key for the LLM provider
39
+ agent_max_iterations: Maximum number of iterations for agent (default: 10)
40
+ agent_max_tool_uses: Maximum number of total tool uses for agent (default: 30)
41
+ enable_agent_tool: Whether to enable the agent tool (default: False)
42
+ """
43
+ self.mcp = mcp_instance if mcp_instance is not None else FastMCP(name)
44
+
45
+ # Initialize context, permissions, and command executor
46
+ self.document_context = DocumentContext()
47
+ self.permission_manager = PermissionManager()
48
+
49
+ # Initialize command executor
50
+ self.command_executor = CommandExecutor(
51
+ permission_manager=self.permission_manager,
52
+ verbose=False, # Set to True for debugging
53
+ )
54
+
55
+ # Initialize project analyzer
56
+ self.project_analyzer = ProjectAnalyzer(self.command_executor)
57
+
58
+ # Initialize project manager
59
+ self.project_manager = ProjectManager(
60
+ self.document_context, self.permission_manager, self.project_analyzer
61
+ )
62
+
63
+ # Add allowed paths
64
+ if allowed_paths:
65
+ for path in allowed_paths:
66
+ self.permission_manager.add_allowed_path(path)
67
+ self.document_context.add_allowed_path(path)
68
+
69
+ # Store agent options
70
+ self.agent_model = agent_model
71
+ self.agent_max_tokens = agent_max_tokens
72
+ self.agent_api_key = agent_api_key
73
+ self.agent_max_iterations = agent_max_iterations
74
+ self.agent_max_tool_uses = agent_max_tool_uses
75
+ self.enable_agent_tool = enable_agent_tool
76
+
77
+ # Register all tools
78
+ register_all_tools(
79
+ mcp_server=self.mcp,
80
+ document_context=self.document_context,
81
+ permission_manager=self.permission_manager,
82
+ agent_model=self.agent_model,
83
+ agent_max_tokens=self.agent_max_tokens,
84
+ agent_api_key=self.agent_api_key,
85
+ agent_max_iterations=self.agent_max_iterations,
86
+ agent_max_tool_uses=self.agent_max_tool_uses,
87
+ enable_agent_tool=self.enable_agent_tool,
88
+ )
89
+
90
+ def run(self, transport: str = "stdio", allowed_paths: list[str] | None = None):
91
+ """Run the MCP server.
92
+
93
+ Args:
94
+ transport: The transport to use (stdio or sse)
95
+ allowed_paths: list of paths that the server is allowed to access
96
+ """
97
+ # Add allowed paths if provided
98
+ allowed_paths_list = allowed_paths or []
99
+ for path in allowed_paths_list:
100
+ self.permission_manager.add_allowed_path(path)
101
+ self.document_context.add_allowed_path(path)
102
+
103
+ # Run the server
104
+ transport_type = cast(Literal["stdio", "sse"], transport)
105
+ self.mcp.run(transport=transport_type)
106
+
107
+
108
+ def main():
109
+ """Run the Hanzo MCP server."""
110
+ import argparse
111
+
112
+ parser = argparse.ArgumentParser(
113
+ description="MCP server implementing Hanzo capabilities"
114
+ )
115
+
116
+ _ = parser.add_argument(
117
+ "--name",
118
+ default="claude-code",
119
+ help="Name of the MCP server (default: claude-code)",
120
+ )
121
+
122
+ _ = parser.add_argument(
123
+ "--transport",
124
+ choices=["stdio", "sse"],
125
+ default="stdio",
126
+ help="Transport protocol to use (default: stdio)",
127
+ )
128
+
129
+ _ = parser.add_argument(
130
+ "--allow-path",
131
+ action="append",
132
+ dest="allowed_paths",
133
+ help="Add an allowed path (can be specified multiple times)",
134
+ )
135
+
136
+ args = parser.parse_args()
137
+
138
+ # Type annotations for args to avoid Any warnings
139
+ name: str = args.name
140
+ transport: str = args.transport
141
+ allowed_paths: list[str] | None = args.allowed_paths
142
+
143
+ # Create and run the server
144
+ server = HanzoServer(name=name, allowed_paths=allowed_paths)
145
+ server.run(transport=transport, allowed_paths=allowed_paths or [])
146
+
147
+
148
+ if __name__ == "__main__":
149
+ main()
@@ -0,0 +1,81 @@
1
+ """Tools package for Hanzo MCP.
2
+
3
+ This package contains all the tools for the Hanzo MCP server.
4
+ It provides a unified interface for registering all tools with an MCP server.
5
+
6
+ This includes a "think" tool implementation based on Anthropic's research showing
7
+ improved performance for complex tool-based interactions when Claude has a dedicated
8
+ space for structured thinking. It also includes an "agent" tool that enables Claude
9
+ to delegate tasks to sub-agents for concurrent execution and specialized processing.
10
+ """
11
+
12
+ from mcp.server.fastmcp import FastMCP
13
+
14
+ from hanzo_mcp.tools.agent import register_agent_tools
15
+ from hanzo_mcp.tools.common import register_thinking_tool
16
+ from hanzo_mcp.tools.common.context import DocumentContext
17
+ from hanzo_mcp.tools.common.permissions import PermissionManager
18
+ from hanzo_mcp.tools.filesystem import register_filesystem_tools
19
+ from hanzo_mcp.tools.jupyter import register_jupyter_tools
20
+ from hanzo_mcp.tools.project import register_project_tools
21
+ from hanzo_mcp.tools.shell import register_shell_tools
22
+ from hanzo_mcp.tools.shell.command_executor import CommandExecutor
23
+
24
+
25
+ def register_all_tools(
26
+ mcp_server: FastMCP,
27
+ document_context: DocumentContext,
28
+ permission_manager: PermissionManager,
29
+ agent_model: str | None = None,
30
+ agent_max_tokens: int | None = None,
31
+ agent_api_key: str | None = None,
32
+ agent_max_iterations: int = 10,
33
+ agent_max_tool_uses: int = 30,
34
+ enable_agent_tool: bool = False,
35
+ ) -> None:
36
+ """Register all Hanzo tools with the MCP server.
37
+
38
+ Args:
39
+ mcp_server: The FastMCP server instance
40
+ document_context: Document context for tracking file contents
41
+ permission_manager: Permission manager for access control
42
+ agent_model: Optional model name for agent tool in LiteLLM format
43
+ agent_max_tokens: Optional maximum tokens for agent responses
44
+ agent_api_key: Optional API key for the LLM provider
45
+ agent_max_iterations: Maximum number of iterations for agent (default: 10)
46
+ agent_max_tool_uses: Maximum number of total tool uses for agent (default: 30)
47
+ enable_agent_tool: Whether to enable the agent tool (default: False)
48
+ """
49
+ # Register all filesystem tools
50
+ register_filesystem_tools(mcp_server, document_context, permission_manager)
51
+
52
+ # Register all jupyter tools
53
+ register_jupyter_tools(mcp_server, document_context, permission_manager)
54
+
55
+ # Register shell tools
56
+ register_shell_tools(mcp_server, permission_manager)
57
+
58
+ # Register project analysis tools
59
+ register_project_tools(
60
+ mcp_server,
61
+ permission_manager,
62
+ document_context,
63
+ CommandExecutor(permission_manager)
64
+ )
65
+
66
+ # Register agent tools only if enabled
67
+ if enable_agent_tool:
68
+ register_agent_tools(
69
+ mcp_server,
70
+ document_context,
71
+ permission_manager,
72
+ CommandExecutor(permission_manager),
73
+ agent_model=agent_model,
74
+ agent_max_tokens=agent_max_tokens,
75
+ agent_api_key=agent_api_key,
76
+ agent_max_iterations=agent_max_iterations,
77
+ agent_max_tool_uses=agent_max_tool_uses
78
+ )
79
+
80
+ # Initialize and register thinking tool
81
+ register_thinking_tool(mcp_server)