hanzo-mcp 0.3.8__py3-none-any.whl → 0.5.1__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.

Files changed (93) hide show
  1. hanzo_mcp/__init__.py +1 -1
  2. hanzo_mcp/cli.py +118 -170
  3. hanzo_mcp/cli_enhanced.py +438 -0
  4. hanzo_mcp/config/__init__.py +19 -0
  5. hanzo_mcp/config/settings.py +449 -0
  6. hanzo_mcp/config/tool_config.py +197 -0
  7. hanzo_mcp/prompts/__init__.py +117 -0
  8. hanzo_mcp/prompts/compact_conversation.py +77 -0
  9. hanzo_mcp/prompts/create_release.py +38 -0
  10. hanzo_mcp/prompts/project_system.py +120 -0
  11. hanzo_mcp/prompts/project_todo_reminder.py +111 -0
  12. hanzo_mcp/prompts/utils.py +286 -0
  13. hanzo_mcp/server.py +117 -99
  14. hanzo_mcp/tools/__init__.py +121 -33
  15. hanzo_mcp/tools/agent/__init__.py +8 -11
  16. hanzo_mcp/tools/agent/agent_tool.py +290 -224
  17. hanzo_mcp/tools/agent/prompt.py +16 -13
  18. hanzo_mcp/tools/agent/tool_adapter.py +9 -9
  19. hanzo_mcp/tools/common/__init__.py +17 -16
  20. hanzo_mcp/tools/common/base.py +79 -110
  21. hanzo_mcp/tools/common/batch_tool.py +330 -0
  22. hanzo_mcp/tools/common/config_tool.py +396 -0
  23. hanzo_mcp/tools/common/context.py +26 -292
  24. hanzo_mcp/tools/common/permissions.py +12 -12
  25. hanzo_mcp/tools/common/thinking_tool.py +153 -0
  26. hanzo_mcp/tools/common/validation.py +1 -63
  27. hanzo_mcp/tools/filesystem/__init__.py +97 -57
  28. hanzo_mcp/tools/filesystem/base.py +32 -24
  29. hanzo_mcp/tools/filesystem/content_replace.py +114 -107
  30. hanzo_mcp/tools/filesystem/directory_tree.py +129 -105
  31. hanzo_mcp/tools/filesystem/edit.py +279 -0
  32. hanzo_mcp/tools/filesystem/grep.py +458 -0
  33. hanzo_mcp/tools/filesystem/grep_ast_tool.py +250 -0
  34. hanzo_mcp/tools/filesystem/multi_edit.py +362 -0
  35. hanzo_mcp/tools/filesystem/read.py +255 -0
  36. hanzo_mcp/tools/filesystem/unified_search.py +689 -0
  37. hanzo_mcp/tools/filesystem/write.py +156 -0
  38. hanzo_mcp/tools/jupyter/__init__.py +41 -29
  39. hanzo_mcp/tools/jupyter/base.py +66 -57
  40. hanzo_mcp/tools/jupyter/{edit_notebook.py → notebook_edit.py} +162 -139
  41. hanzo_mcp/tools/jupyter/notebook_read.py +152 -0
  42. hanzo_mcp/tools/shell/__init__.py +29 -20
  43. hanzo_mcp/tools/shell/base.py +87 -45
  44. hanzo_mcp/tools/shell/bash_session.py +731 -0
  45. hanzo_mcp/tools/shell/bash_session_executor.py +295 -0
  46. hanzo_mcp/tools/shell/command_executor.py +435 -384
  47. hanzo_mcp/tools/shell/run_command.py +284 -131
  48. hanzo_mcp/tools/shell/run_command_windows.py +328 -0
  49. hanzo_mcp/tools/shell/session_manager.py +196 -0
  50. hanzo_mcp/tools/shell/session_storage.py +325 -0
  51. hanzo_mcp/tools/todo/__init__.py +66 -0
  52. hanzo_mcp/tools/todo/base.py +319 -0
  53. hanzo_mcp/tools/todo/todo_read.py +148 -0
  54. hanzo_mcp/tools/todo/todo_write.py +378 -0
  55. hanzo_mcp/tools/vector/__init__.py +99 -0
  56. hanzo_mcp/tools/vector/ast_analyzer.py +459 -0
  57. hanzo_mcp/tools/vector/git_ingester.py +482 -0
  58. hanzo_mcp/tools/vector/infinity_store.py +731 -0
  59. hanzo_mcp/tools/vector/mock_infinity.py +162 -0
  60. hanzo_mcp/tools/vector/project_manager.py +361 -0
  61. hanzo_mcp/tools/vector/vector_index.py +116 -0
  62. hanzo_mcp/tools/vector/vector_search.py +225 -0
  63. hanzo_mcp-0.5.1.dist-info/METADATA +276 -0
  64. hanzo_mcp-0.5.1.dist-info/RECORD +68 -0
  65. {hanzo_mcp-0.3.8.dist-info → hanzo_mcp-0.5.1.dist-info}/WHEEL +1 -1
  66. hanzo_mcp/tools/agent/base_provider.py +0 -73
  67. hanzo_mcp/tools/agent/litellm_provider.py +0 -45
  68. hanzo_mcp/tools/agent/lmstudio_agent.py +0 -385
  69. hanzo_mcp/tools/agent/lmstudio_provider.py +0 -219
  70. hanzo_mcp/tools/agent/provider_registry.py +0 -120
  71. hanzo_mcp/tools/common/error_handling.py +0 -86
  72. hanzo_mcp/tools/common/logging_config.py +0 -115
  73. hanzo_mcp/tools/common/session.py +0 -91
  74. hanzo_mcp/tools/common/think_tool.py +0 -123
  75. hanzo_mcp/tools/common/version_tool.py +0 -120
  76. hanzo_mcp/tools/filesystem/edit_file.py +0 -287
  77. hanzo_mcp/tools/filesystem/get_file_info.py +0 -170
  78. hanzo_mcp/tools/filesystem/read_files.py +0 -199
  79. hanzo_mcp/tools/filesystem/search_content.py +0 -275
  80. hanzo_mcp/tools/filesystem/write_file.py +0 -162
  81. hanzo_mcp/tools/jupyter/notebook_operations.py +0 -514
  82. hanzo_mcp/tools/jupyter/read_notebook.py +0 -165
  83. hanzo_mcp/tools/project/__init__.py +0 -64
  84. hanzo_mcp/tools/project/analysis.py +0 -886
  85. hanzo_mcp/tools/project/base.py +0 -66
  86. hanzo_mcp/tools/project/project_analyze.py +0 -173
  87. hanzo_mcp/tools/shell/run_script.py +0 -215
  88. hanzo_mcp/tools/shell/script_tool.py +0 -244
  89. hanzo_mcp-0.3.8.dist-info/METADATA +0 -196
  90. hanzo_mcp-0.3.8.dist-info/RECORD +0 -53
  91. {hanzo_mcp-0.3.8.dist-info → hanzo_mcp-0.5.1.dist-info}/entry_points.txt +0 -0
  92. {hanzo_mcp-0.3.8.dist-info → hanzo_mcp-0.5.1.dist-info}/licenses/LICENSE +0 -0
  93. {hanzo_mcp-0.3.8.dist-info → hanzo_mcp-0.5.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,396 @@
1
+ """Configuration management tool for dynamic settings updates."""
2
+
3
+ from typing import Dict, List, Optional, TypedDict, Unpack, Any, final
4
+ import json
5
+ from pathlib import Path
6
+
7
+ from fastmcp import Context as MCPContext
8
+
9
+ from hanzo_mcp.tools.common.base import BaseTool
10
+ from hanzo_mcp.tools.common.permissions import PermissionManager
11
+ from hanzo_mcp.config.settings import (
12
+ HanzoMCPSettings,
13
+ MCPServerConfig,
14
+ ProjectConfig,
15
+ load_settings,
16
+ save_settings,
17
+ detect_project_from_path,
18
+ ensure_project_hanzo_dir
19
+ )
20
+
21
+
22
+ class ConfigToolParams(TypedDict, total=False):
23
+ """Parameters for configuration management operations."""
24
+
25
+ action: str # get, set, add_server, remove_server, add_project, etc.
26
+ scope: Optional[str] # global, project, current
27
+ setting_path: Optional[str] # dot-notation path like "agent.enabled"
28
+ value: Optional[Any] # new value to set
29
+ server_name: Optional[str] # for MCP server operations
30
+ server_config: Optional[Dict[str, Any]] # for adding servers
31
+ project_name: Optional[str] # for project operations
32
+ project_path: Optional[str] # for project path detection
33
+
34
+
35
+ @final
36
+ class ConfigTool(BaseTool):
37
+ """Tool for managing Hanzo MCP configuration dynamically."""
38
+
39
+ def __init__(self, permission_manager: PermissionManager):
40
+ """Initialize the configuration tool.
41
+
42
+ Args:
43
+ permission_manager: Permission manager for access control
44
+ """
45
+ self.permission_manager = permission_manager
46
+
47
+ @property
48
+ def name(self) -> str:
49
+ """Get the tool name."""
50
+ return "config"
51
+
52
+ @property
53
+ def description(self) -> str:
54
+ """Get the tool description."""
55
+ return """Dynamically manage Hanzo MCP configuration settings through conversation.
56
+
57
+ Can get/set global settings, project-specific settings, manage MCP servers, configure tools,
58
+ and handle project workflows. Supports dot-notation for nested settings like 'agent.enabled'.
59
+
60
+ Perfect for AI-driven configuration where users can say things like:
61
+ - "Enable the agent tool for this project"
62
+ - "Add a new MCP server for file operations"
63
+ - "Disable write tools globally but enable them for the current project"
64
+ - "Show me the current project configuration"
65
+
66
+ Automatically detects projects based on LLM.md files and manages .hanzo/ directories."""
67
+
68
+ async def call(
69
+ self,
70
+ ctx: MCPContext,
71
+ **params: Unpack[ConfigToolParams],
72
+ ) -> str:
73
+ """Manage configuration settings.
74
+
75
+ Args:
76
+ ctx: MCP context
77
+ **params: Tool parameters
78
+
79
+ Returns:
80
+ Configuration operation result
81
+ """
82
+ action = params.get("action", "get")
83
+ scope = params.get("scope", "global")
84
+ setting_path = params.get("setting_path")
85
+ value = params.get("value")
86
+ server_name = params.get("server_name")
87
+ server_config = params.get("server_config")
88
+ project_name = params.get("project_name")
89
+ project_path = params.get("project_path")
90
+
91
+ try:
92
+ if action == "get":
93
+ return await self._get_config(scope, setting_path, project_name, project_path)
94
+ elif action == "set":
95
+ return await self._set_config(scope, setting_path, value, project_name, project_path)
96
+ elif action == "add_server":
97
+ return await self._add_mcp_server(server_name, server_config, scope, project_name)
98
+ elif action == "remove_server":
99
+ return await self._remove_mcp_server(server_name, scope, project_name)
100
+ elif action == "enable_server":
101
+ return await self._enable_mcp_server(server_name, scope, project_name)
102
+ elif action == "disable_server":
103
+ return await self._disable_mcp_server(server_name, scope, project_name)
104
+ elif action == "trust_server":
105
+ return await self._trust_mcp_server(server_name)
106
+ elif action == "add_project":
107
+ return await self._add_project(project_name, project_path)
108
+ elif action == "set_current_project":
109
+ return await self._set_current_project(project_name, project_path)
110
+ elif action == "list_servers":
111
+ return await self._list_mcp_servers(scope, project_name)
112
+ elif action == "list_projects":
113
+ return await self._list_projects()
114
+ elif action == "detect_project":
115
+ return await self._detect_project(project_path)
116
+ else:
117
+ return f"Error: Unknown action '{action}'. Available actions: get, set, add_server, remove_server, enable_server, disable_server, trust_server, add_project, set_current_project, list_servers, list_projects, detect_project"
118
+
119
+ except Exception as e:
120
+ return f"Error managing configuration: {str(e)}"
121
+
122
+ async def _get_config(self, scope: str, setting_path: Optional[str], project_name: Optional[str], project_path: Optional[str]) -> str:
123
+ """Get configuration value(s)."""
124
+ # Load appropriate settings
125
+ if scope == "project" or project_name or project_path:
126
+ if project_path:
127
+ project_info = detect_project_from_path(project_path)
128
+ if project_info:
129
+ settings = load_settings(project_info["root_path"])
130
+ else:
131
+ return f"No project detected at path: {project_path}"
132
+ else:
133
+ settings = load_settings()
134
+ else:
135
+ settings = load_settings()
136
+
137
+ if not setting_path:
138
+ # Return full config summary
139
+ if scope == "project" and settings.current_project:
140
+ project = settings.get_current_project()
141
+ if project:
142
+ return f"Current Project Configuration ({project.name}):\\n{json.dumps(project.__dict__, indent=2)}"
143
+
144
+ # Return global config summary
145
+ summary = {
146
+ "server": settings.server.__dict__,
147
+ "enabled_tools": settings.get_enabled_tools(),
148
+ "disabled_tools": settings.get_disabled_tools(),
149
+ "agent": settings.agent.__dict__,
150
+ "vector_store": settings.vector_store.__dict__,
151
+ "hub_enabled": settings.hub_enabled,
152
+ "mcp_servers": {name: server.__dict__ for name, server in settings.mcp_servers.items()},
153
+ "current_project": settings.current_project,
154
+ "projects": list(settings.projects.keys()),
155
+ }
156
+ return f"Configuration Summary:\\n{json.dumps(summary, indent=2)}"
157
+
158
+ # Get specific setting
159
+ value = self._get_nested_value(settings.__dict__, setting_path)
160
+ if value is not None:
161
+ return f"{setting_path}: {json.dumps(value, indent=2)}"
162
+ else:
163
+ return f"Setting '{setting_path}' not found"
164
+
165
+ async def _set_config(self, scope: str, setting_path: Optional[str], value: Any, project_name: Optional[str], project_path: Optional[str]) -> str:
166
+ """Set configuration value."""
167
+ if not setting_path:
168
+ return "Error: setting_path is required for set action"
169
+
170
+ # Load settings
171
+ project_dir = None
172
+ if scope == "project" or project_name or project_path:
173
+ if project_path:
174
+ project_info = detect_project_from_path(project_path)
175
+ if project_info:
176
+ project_dir = project_info["root_path"]
177
+ else:
178
+ return f"No project detected at path: {project_path}"
179
+
180
+ settings = load_settings(project_dir)
181
+
182
+ # Set the value
183
+ if self._set_nested_value(settings.__dict__, setting_path, value):
184
+ # Save settings
185
+ if scope == "project" or project_dir:
186
+ save_settings(settings, global_config=False)
187
+ else:
188
+ save_settings(settings, global_config=True)
189
+ return f"Successfully set {setting_path} = {json.dumps(value)}"
190
+ else:
191
+ return f"Error: Could not set '{setting_path}'"
192
+
193
+ async def _add_mcp_server(self, server_name: Optional[str], server_config: Optional[Dict[str, Any]], scope: str, project_name: Optional[str]) -> str:
194
+ """Add a new MCP server."""
195
+ if not server_name or not server_config:
196
+ return "Error: server_name and server_config are required"
197
+
198
+ settings = load_settings()
199
+
200
+ # Create server config
201
+ mcp_server = MCPServerConfig(
202
+ name=server_name,
203
+ command=server_config.get("command", ""),
204
+ args=server_config.get("args", []),
205
+ enabled=server_config.get("enabled", True),
206
+ trusted=server_config.get("trusted", False),
207
+ description=server_config.get("description", ""),
208
+ capabilities=server_config.get("capabilities", []),
209
+ )
210
+
211
+ if settings.add_mcp_server(mcp_server):
212
+ save_settings(settings)
213
+ return f"Successfully added MCP server '{server_name}'"
214
+ else:
215
+ return f"Error: MCP server '{server_name}' already exists"
216
+
217
+ async def _remove_mcp_server(self, server_name: Optional[str], scope: str, project_name: Optional[str]) -> str:
218
+ """Remove an MCP server."""
219
+ if not server_name:
220
+ return "Error: server_name is required"
221
+
222
+ settings = load_settings()
223
+
224
+ if settings.remove_mcp_server(server_name):
225
+ save_settings(settings)
226
+ return f"Successfully removed MCP server '{server_name}'"
227
+ else:
228
+ return f"Error: MCP server '{server_name}' not found"
229
+
230
+ async def _enable_mcp_server(self, server_name: Optional[str], scope: str, project_name: Optional[str]) -> str:
231
+ """Enable an MCP server."""
232
+ if not server_name:
233
+ return "Error: server_name is required"
234
+
235
+ settings = load_settings()
236
+
237
+ if settings.enable_mcp_server(server_name):
238
+ save_settings(settings)
239
+ return f"Successfully enabled MCP server '{server_name}'"
240
+ else:
241
+ return f"Error: MCP server '{server_name}' not found"
242
+
243
+ async def _disable_mcp_server(self, server_name: Optional[str], scope: str, project_name: Optional[str]) -> str:
244
+ """Disable an MCP server."""
245
+ if not server_name:
246
+ return "Error: server_name is required"
247
+
248
+ settings = load_settings()
249
+
250
+ if settings.disable_mcp_server(server_name):
251
+ save_settings(settings)
252
+ return f"Successfully disabled MCP server '{server_name}'"
253
+ else:
254
+ return f"Error: MCP server '{server_name}' not found"
255
+
256
+ async def _trust_mcp_server(self, server_name: Optional[str]) -> str:
257
+ """Trust an MCP server."""
258
+ if not server_name:
259
+ return "Error: server_name is required"
260
+
261
+ settings = load_settings()
262
+
263
+ if settings.trust_mcp_server(server_name):
264
+ save_settings(settings)
265
+ return f"Successfully trusted MCP server '{server_name}'"
266
+ else:
267
+ return f"Error: MCP server '{server_name}' not found"
268
+
269
+ async def _add_project(self, project_name: Optional[str], project_path: Optional[str]) -> str:
270
+ """Add a project configuration."""
271
+ if not project_path:
272
+ return "Error: project_path is required"
273
+
274
+ # Detect or create project
275
+ project_info = detect_project_from_path(project_path)
276
+ if not project_info:
277
+ return f"No LLM.md found in project path: {project_path}"
278
+
279
+ if not project_name:
280
+ project_name = project_info["name"]
281
+
282
+ settings = load_settings()
283
+
284
+ project_config = ProjectConfig(
285
+ name=project_name,
286
+ root_path=project_info["root_path"],
287
+ )
288
+
289
+ if settings.add_project(project_config):
290
+ save_settings(settings)
291
+ return f"Successfully added project '{project_name}' at {project_info['root_path']}"
292
+ else:
293
+ return f"Error: Project '{project_name}' already exists"
294
+
295
+ async def _set_current_project(self, project_name: Optional[str], project_path: Optional[str]) -> str:
296
+ """Set the current active project."""
297
+ settings = load_settings()
298
+
299
+ if project_path:
300
+ project_info = detect_project_from_path(project_path)
301
+ if project_info:
302
+ project_name = project_info["name"]
303
+ # Auto-add project if not exists
304
+ if project_name not in settings.projects:
305
+ await self._add_project(project_name, project_path)
306
+ settings = load_settings() # Reload after adding
307
+
308
+ if not project_name:
309
+ return "Error: project_name or project_path is required"
310
+
311
+ if settings.set_current_project(project_name):
312
+ save_settings(settings)
313
+ return f"Successfully set current project to '{project_name}'"
314
+ else:
315
+ return f"Error: Project '{project_name}' not found"
316
+
317
+ async def _list_mcp_servers(self, scope: str, project_name: Optional[str]) -> str:
318
+ """List MCP servers."""
319
+ settings = load_settings()
320
+
321
+ if not settings.mcp_servers:
322
+ return "No MCP servers configured"
323
+
324
+ servers_info = []
325
+ for name, server in settings.mcp_servers.items():
326
+ status = "enabled" if server.enabled else "disabled"
327
+ trust = "trusted" if server.trusted else "untrusted"
328
+ servers_info.append(f"- {name}: {server.command} ({status}, {trust})")
329
+
330
+ return f"MCP Servers:\\n" + "\\n".join(servers_info)
331
+
332
+ async def _list_projects(self) -> str:
333
+ """List projects."""
334
+ settings = load_settings()
335
+
336
+ if not settings.projects:
337
+ return "No projects configured"
338
+
339
+ projects_info = []
340
+ for name, project in settings.projects.items():
341
+ current = " (current)" if name == settings.current_project else ""
342
+ projects_info.append(f"- {name}: {project.root_path}{current}")
343
+
344
+ return f"Projects:\\n" + "\\n".join(projects_info)
345
+
346
+ async def _detect_project(self, project_path: Optional[str]) -> str:
347
+ """Detect project from path."""
348
+ if not project_path:
349
+ import os
350
+ project_path = os.getcwd()
351
+
352
+ project_info = detect_project_from_path(project_path)
353
+ if project_info:
354
+ return f"Project detected:\\n{json.dumps(project_info, indent=2)}"
355
+ else:
356
+ return f"No project detected at path: {project_path}"
357
+
358
+ def _get_nested_value(self, obj: Dict[str, Any], path: str) -> Any:
359
+ """Get nested value using dot notation."""
360
+ keys = path.split(".")
361
+ current = obj
362
+
363
+ for key in keys:
364
+ if isinstance(current, dict) and key in current:
365
+ current = current[key]
366
+ elif hasattr(current, key):
367
+ current = getattr(current, key)
368
+ else:
369
+ return None
370
+
371
+ return current
372
+
373
+ def _set_nested_value(self, obj: Dict[str, Any], path: str, value: Any) -> bool:
374
+ """Set nested value using dot notation."""
375
+ keys = path.split(".")
376
+ current = obj
377
+
378
+ # Navigate to parent
379
+ for key in keys[:-1]:
380
+ if isinstance(current, dict) and key in current:
381
+ current = current[key]
382
+ elif hasattr(current, key):
383
+ current = getattr(current, key)
384
+ else:
385
+ return False
386
+
387
+ # Set final value
388
+ final_key = keys[-1]
389
+ if isinstance(current, dict):
390
+ current[final_key] = value
391
+ return True
392
+ elif hasattr(current, final_key):
393
+ setattr(current, final_key, value)
394
+ return True
395
+
396
+ return False