hanzo-mcp 0.1.20__py3-none-any.whl
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.
- hanzo_mcp/__init__.py +3 -0
- hanzo_mcp/cli.py +213 -0
- hanzo_mcp/server.py +149 -0
- hanzo_mcp/tools/__init__.py +81 -0
- hanzo_mcp/tools/agent/__init__.py +59 -0
- hanzo_mcp/tools/agent/agent_tool.py +474 -0
- hanzo_mcp/tools/agent/prompt.py +137 -0
- hanzo_mcp/tools/agent/tool_adapter.py +75 -0
- hanzo_mcp/tools/common/__init__.py +18 -0
- hanzo_mcp/tools/common/base.py +216 -0
- hanzo_mcp/tools/common/context.py +444 -0
- hanzo_mcp/tools/common/permissions.py +253 -0
- hanzo_mcp/tools/common/thinking_tool.py +123 -0
- hanzo_mcp/tools/common/validation.py +124 -0
- hanzo_mcp/tools/filesystem/__init__.py +89 -0
- hanzo_mcp/tools/filesystem/base.py +113 -0
- hanzo_mcp/tools/filesystem/content_replace.py +287 -0
- hanzo_mcp/tools/filesystem/directory_tree.py +286 -0
- hanzo_mcp/tools/filesystem/edit_file.py +287 -0
- hanzo_mcp/tools/filesystem/get_file_info.py +170 -0
- hanzo_mcp/tools/filesystem/read_files.py +198 -0
- hanzo_mcp/tools/filesystem/search_content.py +275 -0
- hanzo_mcp/tools/filesystem/write_file.py +162 -0
- hanzo_mcp/tools/jupyter/__init__.py +71 -0
- hanzo_mcp/tools/jupyter/base.py +284 -0
- hanzo_mcp/tools/jupyter/edit_notebook.py +295 -0
- hanzo_mcp/tools/jupyter/notebook_operations.py +514 -0
- hanzo_mcp/tools/jupyter/read_notebook.py +165 -0
- hanzo_mcp/tools/project/__init__.py +64 -0
- hanzo_mcp/tools/project/analysis.py +882 -0
- hanzo_mcp/tools/project/base.py +66 -0
- hanzo_mcp/tools/project/project_analyze.py +173 -0
- hanzo_mcp/tools/shell/__init__.py +58 -0
- hanzo_mcp/tools/shell/base.py +148 -0
- hanzo_mcp/tools/shell/command_executor.py +740 -0
- hanzo_mcp/tools/shell/run_command.py +204 -0
- hanzo_mcp/tools/shell/run_script.py +215 -0
- hanzo_mcp/tools/shell/script_tool.py +244 -0
- hanzo_mcp-0.1.20.dist-info/METADATA +111 -0
- hanzo_mcp-0.1.20.dist-info/RECORD +44 -0
- hanzo_mcp-0.1.20.dist-info/WHEEL +5 -0
- hanzo_mcp-0.1.20.dist-info/entry_points.txt +2 -0
- hanzo_mcp-0.1.20.dist-info/licenses/LICENSE +21 -0
- hanzo_mcp-0.1.20.dist-info/top_level.txt +1 -0
hanzo_mcp/__init__.py
ADDED
hanzo_mcp/cli.py
ADDED
|
@@ -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()
|
hanzo_mcp/server.py
ADDED
|
@@ -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)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Agent tools for Hanzo MCP.
|
|
2
|
+
|
|
3
|
+
This module provides tools that allow Claude to delegate tasks to sub-agents,
|
|
4
|
+
enabling concurrent execution of multiple operations and specialized processing.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from mcp.server.fastmcp import FastMCP
|
|
8
|
+
|
|
9
|
+
from hanzo_mcp.tools.agent.agent_tool import AgentTool
|
|
10
|
+
from hanzo_mcp.tools.common.base import BaseTool, ToolRegistry
|
|
11
|
+
from hanzo_mcp.tools.common.context import DocumentContext
|
|
12
|
+
from hanzo_mcp.tools.common.permissions import PermissionManager
|
|
13
|
+
from hanzo_mcp.tools.shell.command_executor import CommandExecutor
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def register_agent_tools(
|
|
17
|
+
mcp_server: FastMCP,
|
|
18
|
+
document_context: DocumentContext,
|
|
19
|
+
permission_manager: PermissionManager,
|
|
20
|
+
command_executor: CommandExecutor,
|
|
21
|
+
agent_model: str | None = None,
|
|
22
|
+
agent_max_tokens: int | None = None,
|
|
23
|
+
agent_api_key: str | None = None,
|
|
24
|
+
agent_max_iterations: int = 10,
|
|
25
|
+
agent_max_tool_uses: int = 30,
|
|
26
|
+
) -> list[BaseTool]:
|
|
27
|
+
"""Register agent tools with the MCP server.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
mcp_server: The FastMCP server instance
|
|
31
|
+
document_context: Document context for tracking file contents
|
|
32
|
+
permission_manager: Permission manager for access control
|
|
33
|
+
command_executor: Command executor for running shell commands
|
|
34
|
+
agent_model: Optional model name for agent tool in LiteLLM format
|
|
35
|
+
agent_max_tokens: Optional maximum tokens for agent responses
|
|
36
|
+
agent_api_key: Optional API key for the LLM provider
|
|
37
|
+
agent_max_iterations: Maximum number of iterations for agent (default: 10)
|
|
38
|
+
agent_max_tool_uses: Maximum number of total tool uses for agent (default: 30)
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
List of registered tools
|
|
42
|
+
"""
|
|
43
|
+
# Create agent tool
|
|
44
|
+
agent_tool = AgentTool(
|
|
45
|
+
document_context=document_context,
|
|
46
|
+
permission_manager=permission_manager,
|
|
47
|
+
command_executor=command_executor,
|
|
48
|
+
model=agent_model,
|
|
49
|
+
api_key=agent_api_key,
|
|
50
|
+
max_tokens=agent_max_tokens,
|
|
51
|
+
max_iterations=agent_max_iterations,
|
|
52
|
+
max_tool_uses=agent_max_tool_uses
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Register agent tool
|
|
56
|
+
ToolRegistry.register_tool(mcp_server, agent_tool)
|
|
57
|
+
|
|
58
|
+
# Return list of registered tools
|
|
59
|
+
return [agent_tool]
|