tree-sitter-analyzer 0.8.1__py3-none-any.whl → 0.8.3__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 tree-sitter-analyzer might be problematic. Click here for more details.
- tree_sitter_analyzer/__init__.py +1 -1
- tree_sitter_analyzer/cli/commands/base_command.py +3 -1
- tree_sitter_analyzer/cli/commands/query_command.py +1 -1
- tree_sitter_analyzer/mcp/server.py +29 -1
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +677 -673
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +4 -9
- tree_sitter_analyzer/mcp/utils/error_handler.py +18 -0
- tree_sitter_analyzer/project_detector.py +317 -317
- tree_sitter_analyzer/security/__init__.py +22 -22
- tree_sitter_analyzer/security/boundary_manager.py +44 -2
- tree_sitter_analyzer/security/regex_checker.py +292 -292
- tree_sitter_analyzer/security/validator.py +5 -2
- {tree_sitter_analyzer-0.8.1.dist-info → tree_sitter_analyzer-0.8.3.dist-info}/METADATA +35 -7
- {tree_sitter_analyzer-0.8.1.dist-info → tree_sitter_analyzer-0.8.3.dist-info}/RECORD +16 -16
- {tree_sitter_analyzer-0.8.1.dist-info → tree_sitter_analyzer-0.8.3.dist-info}/WHEEL +0 -0
- {tree_sitter_analyzer-0.8.1.dist-info → tree_sitter_analyzer-0.8.3.dist-info}/entry_points.txt +0 -0
tree_sitter_analyzer/__init__.py
CHANGED
|
@@ -47,7 +47,9 @@ class BaseCommand(ABC):
|
|
|
47
47
|
return False
|
|
48
48
|
|
|
49
49
|
# Security validation
|
|
50
|
-
is_valid, error_msg = self.security_validator.validate_file_path(
|
|
50
|
+
is_valid, error_msg = self.security_validator.validate_file_path(
|
|
51
|
+
self.args.file_path, base_path=self.project_root
|
|
52
|
+
)
|
|
51
53
|
if not is_valid:
|
|
52
54
|
output_error(f"Invalid file path: {error_msg}")
|
|
53
55
|
return False
|
|
@@ -24,7 +24,7 @@ class QueryCommand(BaseCommand):
|
|
|
24
24
|
query_to_execute = query_loader.get_query(language, sanitized_query_key)
|
|
25
25
|
if query_to_execute is None:
|
|
26
26
|
output_error(
|
|
27
|
-
f"
|
|
27
|
+
f"Query '{sanitized_query_key}' not found for language '{language}'"
|
|
28
28
|
)
|
|
29
29
|
return 1
|
|
30
30
|
except ValueError as e:
|
|
@@ -71,8 +71,22 @@ class TreeSitterAnalyzerMCPServer:
|
|
|
71
71
|
def __init__(self, project_root: str = None) -> None:
|
|
72
72
|
"""Initialize the MCP server with analyzer components."""
|
|
73
73
|
self.server: Server | None = None
|
|
74
|
+
self._initialization_complete = False
|
|
75
|
+
|
|
76
|
+
logger.info("Starting MCP server initialization...")
|
|
77
|
+
|
|
74
78
|
self.analysis_engine = get_analysis_engine(project_root)
|
|
75
79
|
self.security_validator = SecurityValidator(project_root)
|
|
80
|
+
# Ensure boundary manager exposes the exact provided project_root for consistency in tests/environments
|
|
81
|
+
try:
|
|
82
|
+
import os as _os
|
|
83
|
+
if self.security_validator.boundary_manager and project_root:
|
|
84
|
+
provided_root = _os.path.abspath(project_root)
|
|
85
|
+
self.security_validator.boundary_manager.project_root = provided_root
|
|
86
|
+
# Keep allowed directories in sync with the exposed project_root
|
|
87
|
+
self.security_validator.boundary_manager.allowed_directories = {provided_root}
|
|
88
|
+
except Exception:
|
|
89
|
+
pass
|
|
76
90
|
# Use unified analysis engine instead of deprecated AdvancedAnalyzer
|
|
77
91
|
|
|
78
92
|
# Initialize MCP tools with security validation
|
|
@@ -88,13 +102,24 @@ class TreeSitterAnalyzerMCPServer:
|
|
|
88
102
|
self.name = MCP_INFO["name"]
|
|
89
103
|
self.version = MCP_INFO["version"]
|
|
90
104
|
|
|
91
|
-
|
|
105
|
+
self._initialization_complete = True
|
|
106
|
+
logger.info(f"MCP server initialization complete: {self.name} v{self.version}")
|
|
107
|
+
|
|
108
|
+
def is_initialized(self) -> bool:
|
|
109
|
+
"""Check if the server is fully initialized."""
|
|
110
|
+
return self._initialization_complete
|
|
111
|
+
|
|
112
|
+
def _ensure_initialized(self) -> None:
|
|
113
|
+
"""Ensure the server is initialized before processing requests."""
|
|
114
|
+
if not self._initialization_complete:
|
|
115
|
+
raise RuntimeError("Server not fully initialized. Please wait for initialization to complete.")
|
|
92
116
|
|
|
93
117
|
@handle_mcp_errors("analyze_code_scale")
|
|
94
118
|
async def _analyze_code_scale(self, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
95
119
|
"""
|
|
96
120
|
Analyze code scale and complexity metrics by delegating to the universal_analyze_tool.
|
|
97
121
|
"""
|
|
122
|
+
self._ensure_initialized()
|
|
98
123
|
# Delegate the execution to the already initialized tool
|
|
99
124
|
return await self.universal_analyze_tool.execute(arguments)
|
|
100
125
|
|
|
@@ -168,6 +193,9 @@ class TreeSitterAnalyzerMCPServer:
|
|
|
168
193
|
) -> list[TextContent]:
|
|
169
194
|
"""Handle tool calls with security validation."""
|
|
170
195
|
try:
|
|
196
|
+
# Ensure server is fully initialized
|
|
197
|
+
self._ensure_initialized()
|
|
198
|
+
|
|
171
199
|
# Security validation for tool name
|
|
172
200
|
sanitized_name = self.security_validator.sanitize_input(name, max_length=100)
|
|
173
201
|
|