hanzo-mcp 0.1.21__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.
- hanzo_mcp-0.1.21/LICENSE +21 -0
- hanzo_mcp-0.1.21/PKG-INFO +168 -0
- hanzo_mcp-0.1.21/README.md +135 -0
- hanzo_mcp-0.1.21/hanzo_mcp/__init__.py +3 -0
- hanzo_mcp-0.1.21/hanzo_mcp/cli.py +155 -0
- hanzo_mcp-0.1.21/hanzo_mcp/server.py +125 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/__init__.py +62 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/common/__init__.py +1 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/common/context.py +444 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/common/permissions.py +253 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/common/thinking.py +65 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/common/validation.py +124 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/filesystem/__init__.py +9 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/filesystem/file_operations.py +1050 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/jupyter/__init__.py +8 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/jupyter/notebook_operations.py +554 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/project/__init__.py +1 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/project/analysis.py +879 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/shell/__init__.py +1 -0
- hanzo_mcp-0.1.21/hanzo_mcp/tools/shell/command_executor.py +1001 -0
- hanzo_mcp-0.1.21/hanzo_mcp.egg-info/PKG-INFO +168 -0
- hanzo_mcp-0.1.21/hanzo_mcp.egg-info/SOURCES.txt +29 -0
- hanzo_mcp-0.1.21/hanzo_mcp.egg-info/dependency_links.txt +1 -0
- hanzo_mcp-0.1.21/hanzo_mcp.egg-info/entry_points.txt +2 -0
- hanzo_mcp-0.1.21/hanzo_mcp.egg-info/requires.txt +22 -0
- hanzo_mcp-0.1.21/hanzo_mcp.egg-info/top_level.txt +1 -0
- hanzo_mcp-0.1.21/pyproject.toml +57 -0
- hanzo_mcp-0.1.21/setup.cfg +4 -0
- hanzo_mcp-0.1.21/tests/test_cli.py +290 -0
- hanzo_mcp-0.1.21/tests/test_server.py +172 -0
- hanzo_mcp-0.1.21/tests/test_validation.py +118 -0
hanzo_mcp-0.1.21/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Hanzo Industries Inc
|
|
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,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hanzo-mcp
|
|
3
|
+
Version: 0.1.21
|
|
4
|
+
Summary: MCP server for accessing Hanzo APIs and Platform capabilities
|
|
5
|
+
Author-email: Hanzo Dev <dev@hanzo.ai>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.13
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: mcp>=1.3.0
|
|
14
|
+
Requires-Dist: httpx>=0.27.0
|
|
15
|
+
Requires-Dist: uvicorn>=0.23.1
|
|
16
|
+
Requires-Dist: mcp
|
|
17
|
+
Requires-Dist: pytest
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
20
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
21
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
22
|
+
Requires-Dist: black>=23.3.0; extra == "dev"
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
25
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "test"
|
|
26
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "test"
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.25.3; extra == "test"
|
|
28
|
+
Requires-Dist: twisted; extra == "test"
|
|
29
|
+
Provides-Extra: performance
|
|
30
|
+
Requires-Dist: ujson>=5.7.0; extra == "performance"
|
|
31
|
+
Requires-Dist: orjson>=3.9.0; extra == "performance"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# Hanzo MCP
|
|
35
|
+
|
|
36
|
+
Hanzo AI + Platform capabilities via the Model Context Protocol (MCP).
|
|
37
|
+
|
|
38
|
+
## Overview
|
|
39
|
+
|
|
40
|
+
This project provides an MCP server that enables access to Hanzo APIs and Platform capabilities, as well as providing development tools for managing and improving projects. By leveraging the Model Context Protocol, this server enables seamless integration with various MCP clients including Claude Desktop, allowing LLMs to directly access Hanzo's platform functionality.
|
|
41
|
+
|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- **Code Understanding**: Analyze and understand codebases through file access and pattern searching
|
|
47
|
+
- **Code Modification**: Make targeted edits to files with proper permission handling
|
|
48
|
+
- **Enhanced Command Execution**: Run commands and scripts in various languages with improved error handling and shell support
|
|
49
|
+
- **File Operations**: Manage files with proper security controls through shell commands
|
|
50
|
+
- **Code Discovery**: Find relevant files and code patterns across your project
|
|
51
|
+
- **Project Analysis**: Understand project structure, dependencies, and frameworks
|
|
52
|
+
- **Jupyter Notebook Support**: Read and edit Jupyter notebooks with full cell and output handling
|
|
53
|
+
|
|
54
|
+
## Tools Implemented
|
|
55
|
+
|
|
56
|
+
| Tool | Description |
|
|
57
|
+
| ---------------------- | --------------------------------------------------------------------------------------------- |
|
|
58
|
+
| `read_files` | Read one or multiple files with encoding detection |
|
|
59
|
+
| `write_file` | Create or overwrite files |
|
|
60
|
+
| `edit_file` | Make line-based edits to text files |
|
|
61
|
+
| `directory_tree` | Get a recursive tree view of directories |
|
|
62
|
+
| `get_file_info` | Get metadata about a file or directory |
|
|
63
|
+
| `search_content` | Search for patterns in file contents |
|
|
64
|
+
| `content_replace` | Replace patterns in file contents |
|
|
65
|
+
| `run_command` | Execute shell commands (also used for directory creation, file moving, and directory listing) |
|
|
66
|
+
| `run_script` | Execute scripts with specified interpreters |
|
|
67
|
+
| `script_tool` | Execute scripts in specific programming languages |
|
|
68
|
+
| `project_analyze_tool` | Analyze project structure and dependencies |
|
|
69
|
+
| `read_notebook` | Extract and read source code from all cells in a Jupyter notebook with outputs |
|
|
70
|
+
| `edit_notebook` | Edit, insert, or delete cells in a Jupyter notebook |
|
|
71
|
+
| `think` | Structured space for complex reasoning and analysis without making changes |
|
|
72
|
+
|
|
73
|
+
## Getting Started
|
|
74
|
+
|
|
75
|
+
### Usage
|
|
76
|
+
|
|
77
|
+
#### Configuring Claude Desktop
|
|
78
|
+
|
|
79
|
+
You can run it with `uvx run hanzo-mcp` without installation. Configure Claude Desktop to use this server by adding the following to your Claude Desktop configuration file:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"mcpServers": {
|
|
84
|
+
"hanzo": {
|
|
85
|
+
"command": "uvx",
|
|
86
|
+
"args": [
|
|
87
|
+
"--from",
|
|
88
|
+
"hanzo-mcp",
|
|
89
|
+
"hanzo-mcp",
|
|
90
|
+
"--allow-path",
|
|
91
|
+
"/path/to/your/project"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Make sure to replace `/path/to/your/project` with the actual path to the project you want Claude to access.
|
|
99
|
+
|
|
100
|
+
#### Advanced Configuration Options
|
|
101
|
+
|
|
102
|
+
You can customize the server using other options:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"mcpServers": {
|
|
107
|
+
"hanzo": {
|
|
108
|
+
"command": "uvx",
|
|
109
|
+
"args": [
|
|
110
|
+
"--from",
|
|
111
|
+
"hanzo-mcp",
|
|
112
|
+
"hanzo-mcp",
|
|
113
|
+
"--allow-path",
|
|
114
|
+
"/path/to/project",
|
|
115
|
+
"--name",
|
|
116
|
+
"custom-hanzo",
|
|
117
|
+
"--transport",
|
|
118
|
+
"stdio"
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Configuring Claude Desktop System Prompt
|
|
126
|
+
|
|
127
|
+
To get the best experience with Hanzo MCP, you need to add the provided system prompt to your Claude Desktop client. This system prompt guides Claude through a structured workflow for interacting with Hanzo platform services and managing project files.
|
|
128
|
+
|
|
129
|
+
Follow these steps:
|
|
130
|
+
|
|
131
|
+
1. Locate the system prompt file in this repository at `doc/system_prompt`
|
|
132
|
+
2. Open your Claude Desktop client
|
|
133
|
+
3. Create a new project or open an existing one
|
|
134
|
+
4. Navigate to the "Project instructions" section in the Claude Desktop sidebar
|
|
135
|
+
5. Copy the contents of `doc/system_prompt` and paste it into the "Project instructions" section
|
|
136
|
+
6. Replace `{project_path}` with the actual absolute path to your project
|
|
137
|
+
|
|
138
|
+
The system prompt provides Claude with:
|
|
139
|
+
|
|
140
|
+
- A structured workflow for analyzing and modifying code
|
|
141
|
+
- Best practices for project exploration and analysis
|
|
142
|
+
- Guidelines for development, refactoring, and quality assurance
|
|
143
|
+
- Special formatting instructions for mathematical content
|
|
144
|
+
|
|
145
|
+
This step is crucial as it enables Claude to follow a consistent approach when helping you with code modifications.
|
|
146
|
+
|
|
147
|
+
## Security
|
|
148
|
+
|
|
149
|
+
This implementation follows best practices for securing access to your filesystem:
|
|
150
|
+
|
|
151
|
+
- Permission prompts for file modifications and command execution
|
|
152
|
+
- Restricted access to specified directories only
|
|
153
|
+
- Input validation and sanitization
|
|
154
|
+
- Proper error handling and reporting
|
|
155
|
+
|
|
156
|
+
## Development
|
|
157
|
+
|
|
158
|
+
To contribute to this project:
|
|
159
|
+
|
|
160
|
+
1. Fork the repository
|
|
161
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
162
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
163
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
164
|
+
5. Open a Pull Request
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Hanzo MCP
|
|
2
|
+
|
|
3
|
+
Hanzo AI + Platform capabilities via the Model Context Protocol (MCP).
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This project provides an MCP server that enables access to Hanzo APIs and Platform capabilities, as well as providing development tools for managing and improving projects. By leveraging the Model Context Protocol, this server enables seamless integration with various MCP clients including Claude Desktop, allowing LLMs to directly access Hanzo's platform functionality.
|
|
8
|
+
|
|
9
|
+

|
|
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
|
+
- **Jupyter Notebook Support**: Read and edit Jupyter notebooks with full cell and output handling
|
|
20
|
+
|
|
21
|
+
## Tools Implemented
|
|
22
|
+
|
|
23
|
+
| Tool | Description |
|
|
24
|
+
| ---------------------- | --------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `read_files` | Read one or multiple files with encoding detection |
|
|
26
|
+
| `write_file` | Create or overwrite files |
|
|
27
|
+
| `edit_file` | Make line-based edits to text files |
|
|
28
|
+
| `directory_tree` | Get a recursive tree view of directories |
|
|
29
|
+
| `get_file_info` | Get metadata about a file or directory |
|
|
30
|
+
| `search_content` | Search for patterns in file contents |
|
|
31
|
+
| `content_replace` | Replace patterns in file contents |
|
|
32
|
+
| `run_command` | Execute shell commands (also used for directory creation, file moving, and directory listing) |
|
|
33
|
+
| `run_script` | Execute scripts with specified interpreters |
|
|
34
|
+
| `script_tool` | Execute scripts in specific programming languages |
|
|
35
|
+
| `project_analyze_tool` | Analyze project structure and dependencies |
|
|
36
|
+
| `read_notebook` | Extract and read source code from all cells in a Jupyter notebook with outputs |
|
|
37
|
+
| `edit_notebook` | Edit, insert, or delete cells in a Jupyter notebook |
|
|
38
|
+
| `think` | Structured space for complex reasoning and analysis without making changes |
|
|
39
|
+
|
|
40
|
+
## Getting Started
|
|
41
|
+
|
|
42
|
+
### Usage
|
|
43
|
+
|
|
44
|
+
#### Configuring Claude Desktop
|
|
45
|
+
|
|
46
|
+
You can run it with `uvx run hanzo-mcp` without installation. Configure Claude Desktop to use this server by adding the following to your Claude Desktop configuration file:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"mcpServers": {
|
|
51
|
+
"hanzo": {
|
|
52
|
+
"command": "uvx",
|
|
53
|
+
"args": [
|
|
54
|
+
"--from",
|
|
55
|
+
"hanzo-mcp",
|
|
56
|
+
"hanzo-mcp",
|
|
57
|
+
"--allow-path",
|
|
58
|
+
"/path/to/your/project"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Make sure to replace `/path/to/your/project` with the actual path to the project you want Claude to access.
|
|
66
|
+
|
|
67
|
+
#### Advanced Configuration Options
|
|
68
|
+
|
|
69
|
+
You can customize the server using other options:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"mcpServers": {
|
|
74
|
+
"hanzo": {
|
|
75
|
+
"command": "uvx",
|
|
76
|
+
"args": [
|
|
77
|
+
"--from",
|
|
78
|
+
"hanzo-mcp",
|
|
79
|
+
"hanzo-mcp",
|
|
80
|
+
"--allow-path",
|
|
81
|
+
"/path/to/project",
|
|
82
|
+
"--name",
|
|
83
|
+
"custom-hanzo",
|
|
84
|
+
"--transport",
|
|
85
|
+
"stdio"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Configuring Claude Desktop System Prompt
|
|
93
|
+
|
|
94
|
+
To get the best experience with Hanzo MCP, you need to add the provided system prompt to your Claude Desktop client. This system prompt guides Claude through a structured workflow for interacting with Hanzo platform services and managing project files.
|
|
95
|
+
|
|
96
|
+
Follow these steps:
|
|
97
|
+
|
|
98
|
+
1. Locate the system prompt file in this repository at `doc/system_prompt`
|
|
99
|
+
2. Open your Claude Desktop client
|
|
100
|
+
3. Create a new project or open an existing one
|
|
101
|
+
4. Navigate to the "Project instructions" section in the Claude Desktop sidebar
|
|
102
|
+
5. Copy the contents of `doc/system_prompt` and paste it into the "Project instructions" section
|
|
103
|
+
6. Replace `{project_path}` with the actual absolute path to your project
|
|
104
|
+
|
|
105
|
+
The system prompt provides Claude with:
|
|
106
|
+
|
|
107
|
+
- A structured workflow for analyzing and modifying code
|
|
108
|
+
- Best practices for project exploration and analysis
|
|
109
|
+
- Guidelines for development, refactoring, and quality assurance
|
|
110
|
+
- Special formatting instructions for mathematical content
|
|
111
|
+
|
|
112
|
+
This step is crucial as it enables Claude to follow a consistent approach when helping you with code modifications.
|
|
113
|
+
|
|
114
|
+
## Security
|
|
115
|
+
|
|
116
|
+
This implementation follows best practices for securing access to your filesystem:
|
|
117
|
+
|
|
118
|
+
- Permission prompts for file modifications and command execution
|
|
119
|
+
- Restricted access to specified directories only
|
|
120
|
+
- Input validation and sanitization
|
|
121
|
+
- Proper error handling and reporting
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
To contribute to this project:
|
|
126
|
+
|
|
127
|
+
1. Fork the repository
|
|
128
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
129
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
130
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
131
|
+
5. Open a Pull Request
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,155 @@
|
|
|
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 HanzoDevServer
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> None:
|
|
14
|
+
"""Run the CLI for the Hanzo Dev MCP server."""
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
description="MCP server for accessing Hanzo APIs and Platform 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="hanzo",
|
|
29
|
+
help="Name of the MCP server (default: hanzo)",
|
|
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
|
+
"--install",
|
|
45
|
+
action="store_true",
|
|
46
|
+
help="Install server configuration in Claude Desktop",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
args = parser.parse_args()
|
|
50
|
+
|
|
51
|
+
# Cast args attributes to appropriate types to avoid 'Any' warnings
|
|
52
|
+
name: str = cast(str, args.name)
|
|
53
|
+
install: bool = cast(bool, args.install)
|
|
54
|
+
transport: str = cast(str, args.transport)
|
|
55
|
+
project_dir: str | None = cast(str | None, args.project_dir)
|
|
56
|
+
allowed_paths: list[str] = (
|
|
57
|
+
cast(list[str], args.allowed_paths) if args.allowed_paths else []
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
if install:
|
|
61
|
+
install_claude_desktop_config(name, allowed_paths)
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
# If no allowed paths are specified, use the current directory
|
|
65
|
+
if not allowed_paths:
|
|
66
|
+
allowed_paths = [os.getcwd()]
|
|
67
|
+
|
|
68
|
+
# If project directory is specified, add it to allowed paths
|
|
69
|
+
if project_dir and project_dir not in allowed_paths:
|
|
70
|
+
allowed_paths.append(project_dir)
|
|
71
|
+
|
|
72
|
+
# Run the server
|
|
73
|
+
server = HanzoDevServer(name=name, allowed_paths=allowed_paths)
|
|
74
|
+
# Transport will be automatically cast to Literal['stdio', 'sse'] by the server
|
|
75
|
+
server.run(transport=transport)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def install_claude_desktop_config(
|
|
79
|
+
name: str = "hanzo", allowed_paths: list[str] | None = None
|
|
80
|
+
) -> None:
|
|
81
|
+
"""Install the server configuration in Claude Desktop.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
name: The name to use for the server in the config
|
|
85
|
+
allowed_paths: Optional list of paths to allow
|
|
86
|
+
"""
|
|
87
|
+
# Find the Claude Desktop config directory
|
|
88
|
+
home: Path = Path.home()
|
|
89
|
+
|
|
90
|
+
if sys.platform == "darwin": # macOS
|
|
91
|
+
config_dir: Path = home / "Library" / "Application Support" / "Claude"
|
|
92
|
+
elif sys.platform == "win32": # Windows
|
|
93
|
+
config_dir = Path(os.environ.get("APPDATA", "")) / "Claude"
|
|
94
|
+
else: # Linux and others
|
|
95
|
+
config_dir = home / ".config" / "claude"
|
|
96
|
+
|
|
97
|
+
config_file: Path = config_dir / "claude_desktop_config.json"
|
|
98
|
+
|
|
99
|
+
# Create directory if it doesn't exist
|
|
100
|
+
config_dir.mkdir(parents=True, exist_ok=True)
|
|
101
|
+
|
|
102
|
+
# Get current script path
|
|
103
|
+
script_path: Path = Path(sys.executable)
|
|
104
|
+
|
|
105
|
+
# Create args array
|
|
106
|
+
args: list[str] = ["-m", "hanzo_mcp.cli"]
|
|
107
|
+
|
|
108
|
+
# Add allowed paths if specified
|
|
109
|
+
if allowed_paths:
|
|
110
|
+
for path in allowed_paths:
|
|
111
|
+
args.extend(["--allow-path", path])
|
|
112
|
+
else:
|
|
113
|
+
# Allow home directory by default
|
|
114
|
+
args.extend(["--allow-path", str(home)])
|
|
115
|
+
|
|
116
|
+
# Create config object
|
|
117
|
+
config: dict[str, Any] = {
|
|
118
|
+
"mcpServers": {name: {"command": str(script_path), "args": args}}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
# Check if the file already exists
|
|
122
|
+
if config_file.exists():
|
|
123
|
+
try:
|
|
124
|
+
with open(config_file, "r") as f:
|
|
125
|
+
existing_config: dict[str, Any] = json.load(f)
|
|
126
|
+
|
|
127
|
+
# Update the existing config
|
|
128
|
+
if "mcpServers" not in existing_config:
|
|
129
|
+
existing_config["mcpServers"] = {}
|
|
130
|
+
|
|
131
|
+
existing_config["mcpServers"][name] = config["mcpServers"][name]
|
|
132
|
+
config = existing_config
|
|
133
|
+
except Exception as e:
|
|
134
|
+
print(f"Error reading existing config: {e}")
|
|
135
|
+
print("Creating new config file.")
|
|
136
|
+
|
|
137
|
+
# Write the config file
|
|
138
|
+
with open(config_file, mode="w") as f:
|
|
139
|
+
json.dump(config, f, indent=2)
|
|
140
|
+
|
|
141
|
+
print(f"Successfully installed {name} in Claude Desktop configuration.")
|
|
142
|
+
print(f"Config file: {config_file}")
|
|
143
|
+
|
|
144
|
+
if allowed_paths:
|
|
145
|
+
print("\nAllowed paths:")
|
|
146
|
+
for path in allowed_paths:
|
|
147
|
+
print(f"- {path}")
|
|
148
|
+
else:
|
|
149
|
+
print(f"\nDefault allowed path: {home}")
|
|
150
|
+
print("\nYou can modify allowed paths in the config file directly.")
|
|
151
|
+
print("Restart Claude Desktop for changes to take effect.")
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
if __name__ == "__main__":
|
|
155
|
+
main()
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""MCP server for accessing Hanzo APIs and Platform 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 HanzoDevServer:
|
|
16
|
+
"""MCP server for accessing Hanzo APIs and Platform capabilities."""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
name: str = "hanzo",
|
|
21
|
+
allowed_paths: list[str] | None = None,
|
|
22
|
+
mcp_instance: FastMCP | None = None,
|
|
23
|
+
):
|
|
24
|
+
"""Initialize the Hanzo Dev server.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
name: The name of the server
|
|
28
|
+
allowed_paths: list of paths that the server is allowed to access
|
|
29
|
+
mcp_instance: Optional FastMCP instance for testing
|
|
30
|
+
"""
|
|
31
|
+
self.mcp = mcp_instance if mcp_instance is not None else FastMCP(name)
|
|
32
|
+
|
|
33
|
+
# Initialize context, permissions, and command executor
|
|
34
|
+
self.document_context = DocumentContext()
|
|
35
|
+
self.permission_manager = PermissionManager()
|
|
36
|
+
|
|
37
|
+
# Initialize command executor
|
|
38
|
+
self.command_executor = CommandExecutor(
|
|
39
|
+
permission_manager=self.permission_manager,
|
|
40
|
+
verbose=False, # Set to True for debugging
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Initialize project analyzer
|
|
44
|
+
self.project_analyzer = ProjectAnalyzer(self.command_executor)
|
|
45
|
+
|
|
46
|
+
# Initialize project manager
|
|
47
|
+
self.project_manager = ProjectManager(
|
|
48
|
+
self.document_context, self.permission_manager, self.project_analyzer
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Add allowed paths
|
|
52
|
+
if allowed_paths:
|
|
53
|
+
for path in allowed_paths:
|
|
54
|
+
self.permission_manager.add_allowed_path(path)
|
|
55
|
+
self.document_context.add_allowed_path(path)
|
|
56
|
+
|
|
57
|
+
# Register all tools
|
|
58
|
+
register_all_tools(
|
|
59
|
+
mcp_server=self.mcp,
|
|
60
|
+
document_context=self.document_context,
|
|
61
|
+
permission_manager=self.permission_manager,
|
|
62
|
+
project_manager=self.project_manager,
|
|
63
|
+
project_analyzer=self.project_analyzer,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def run(self, transport: str = "stdio", allowed_paths: list[str] | None = None):
|
|
67
|
+
"""Run the MCP server.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
transport: The transport to use (stdio or sse)
|
|
71
|
+
allowed_paths: list of paths that the server is allowed to access
|
|
72
|
+
"""
|
|
73
|
+
# Add allowed paths if provided
|
|
74
|
+
allowed_paths_list = allowed_paths or []
|
|
75
|
+
for path in allowed_paths_list:
|
|
76
|
+
self.permission_manager.add_allowed_path(path)
|
|
77
|
+
self.document_context.add_allowed_path(path)
|
|
78
|
+
|
|
79
|
+
# Run the server
|
|
80
|
+
transport_type = cast(Literal["stdio", "sse"], transport)
|
|
81
|
+
self.mcp.run(transport=transport_type)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def main():
|
|
85
|
+
"""Run the Hanzo MCP server."""
|
|
86
|
+
import argparse
|
|
87
|
+
|
|
88
|
+
parser = argparse.ArgumentParser(
|
|
89
|
+
description="MCP server for accessing Hanzo APIs and Platform capabilities"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
_ = parser.add_argument(
|
|
93
|
+
"--name",
|
|
94
|
+
default="hanzo",
|
|
95
|
+
help="Name of the MCP server (default: hanzo)",
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
_ = parser.add_argument(
|
|
99
|
+
"--transport",
|
|
100
|
+
choices=["stdio", "sse"],
|
|
101
|
+
default="stdio",
|
|
102
|
+
help="Transport protocol to use (default: stdio)",
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
_ = parser.add_argument(
|
|
106
|
+
"--allow-path",
|
|
107
|
+
action="append",
|
|
108
|
+
dest="allowed_paths",
|
|
109
|
+
help="Add an allowed path (can be specified multiple times)",
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
args = parser.parse_args()
|
|
113
|
+
|
|
114
|
+
# Type annotations for args to avoid Any warnings
|
|
115
|
+
name: str = args.name
|
|
116
|
+
transport: str = args.transport
|
|
117
|
+
allowed_paths: list[str] | None = args.allowed_paths
|
|
118
|
+
|
|
119
|
+
# Create and run the server
|
|
120
|
+
server = HanzoDevServer(name=name, allowed_paths=allowed_paths)
|
|
121
|
+
server.run(transport=transport, allowed_paths=allowed_paths or [])
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
if __name__ == "__main__":
|
|
125
|
+
main()
|
|
@@ -0,0 +1,62 @@
|
|
|
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.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from mcp.server.fastmcp import FastMCP
|
|
14
|
+
|
|
15
|
+
from hanzo_mcp.tools.common.context import DocumentContext
|
|
16
|
+
from hanzo_mcp.tools.common.permissions import PermissionManager
|
|
17
|
+
from hanzo_mcp.tools.common.thinking import ThinkingTool
|
|
18
|
+
from hanzo_mcp.tools.filesystem.file_operations import FileOperations
|
|
19
|
+
from hanzo_mcp.tools.jupyter.notebook_operations import JupyterNotebookTools
|
|
20
|
+
from hanzo_mcp.tools.project.analysis import ProjectAnalysis, ProjectManager
|
|
21
|
+
from hanzo_mcp.tools.shell.command_executor import CommandExecutor
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def register_all_tools(
|
|
25
|
+
mcp_server: FastMCP,
|
|
26
|
+
document_context: DocumentContext,
|
|
27
|
+
permission_manager: PermissionManager,
|
|
28
|
+
project_manager: ProjectManager,
|
|
29
|
+
project_analyzer: Any,
|
|
30
|
+
) -> None:
|
|
31
|
+
"""Register all Hanzo MCP tools with the MCP server.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
mcp_server: The FastMCP server instance
|
|
35
|
+
document_context: Document context for tracking file contents
|
|
36
|
+
permission_manager: Permission manager for access control
|
|
37
|
+
command_executor: Enhanced command executor for running shell commands
|
|
38
|
+
project_manager: Project manager for tracking projects
|
|
39
|
+
project_analyzer: Project analyzer for analyzing project structure and dependencies
|
|
40
|
+
"""
|
|
41
|
+
# Initialize and register file operations tools
|
|
42
|
+
# Now includes all filesystem functionality (navigation + file operations)
|
|
43
|
+
file_ops = FileOperations(document_context, permission_manager)
|
|
44
|
+
file_ops.register_tools(mcp_server)
|
|
45
|
+
|
|
46
|
+
# Initialize and register command execution tools
|
|
47
|
+
cmd_exec = CommandExecutor(permission_manager)
|
|
48
|
+
cmd_exec.register_tools(mcp_server)
|
|
49
|
+
|
|
50
|
+
# Initialize and register project analysis tools
|
|
51
|
+
proj_analysis = ProjectAnalysis(
|
|
52
|
+
project_manager, project_analyzer, permission_manager
|
|
53
|
+
)
|
|
54
|
+
proj_analysis.register_tools(mcp_server)
|
|
55
|
+
|
|
56
|
+
# Initialize and register Jupyter notebook tools
|
|
57
|
+
jupyter_tools = JupyterNotebookTools(document_context, permission_manager)
|
|
58
|
+
jupyter_tools.register_tools(mcp_server)
|
|
59
|
+
|
|
60
|
+
# Initialize and register thinking tool
|
|
61
|
+
thinking_tool = ThinkingTool()
|
|
62
|
+
thinking_tool.register_tools(mcp_server)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Common utilities for Hanzo Dev MCP tools."""
|