tree-sitter-analyzer 0.9.6__py3-none-any.whl → 0.9.8__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/core/query_service.py +162 -162
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +22 -10
- tree_sitter_analyzer/mcp/tools/query_tool.py +18 -6
- tree_sitter_analyzer/mcp/tools/read_partial_tool.py +4 -15
- tree_sitter_analyzer/mcp/tools/table_format_tool.py +11 -24
- tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +32 -22
- tree_sitter_analyzer/mcp/utils/__init__.py +7 -0
- tree_sitter_analyzer/mcp/utils/error_handler.py +569 -569
- tree_sitter_analyzer/mcp/utils/path_resolver.py +194 -0
- {tree_sitter_analyzer-0.9.6.dist-info → tree_sitter_analyzer-0.9.8.dist-info}/METADATA +22 -11
- {tree_sitter_analyzer-0.9.6.dist-info → tree_sitter_analyzer-0.9.8.dist-info}/RECORD +14 -13
- {tree_sitter_analyzer-0.9.6.dist-info → tree_sitter_analyzer-0.9.8.dist-info}/WHEEL +0 -0
- {tree_sitter_analyzer-0.9.6.dist-info → tree_sitter_analyzer-0.9.8.dist-info}/entry_points.txt +0 -0
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""
|
|
3
|
-
Universal
|
|
3
|
+
Universal Analyze Tool for MCP
|
|
4
4
|
|
|
5
|
-
This tool provides universal code analysis capabilities
|
|
6
|
-
|
|
5
|
+
This tool provides universal code analysis capabilities through the MCP protocol,
|
|
6
|
+
supporting multiple languages with both basic and detailed analysis options.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
import logging
|
|
10
9
|
from pathlib import Path
|
|
11
10
|
from typing import Any
|
|
12
11
|
|
|
13
12
|
from ...core.analysis_engine import AnalysisRequest, get_analysis_engine
|
|
14
13
|
from ...language_detector import detect_language_from_file, is_language_supported
|
|
15
14
|
from ...security import SecurityValidator
|
|
15
|
+
from ...utils import setup_logger
|
|
16
16
|
from ..utils import get_performance_monitor
|
|
17
17
|
from ..utils.error_handler import handle_mcp_errors
|
|
18
|
+
from ..utils.path_resolver import PathResolver
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
# Set up logging
|
|
21
|
+
logger = setup_logger(__name__)
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
class UniversalAnalyzeTool:
|
|
23
25
|
"""
|
|
24
|
-
Universal code analysis
|
|
26
|
+
Universal MCP Tool for code analysis across multiple languages.
|
|
25
27
|
|
|
26
|
-
This tool
|
|
27
|
-
|
|
28
|
+
This tool provides comprehensive code analysis capabilities through the MCP protocol,
|
|
29
|
+
supporting both basic and detailed analysis with language-specific optimizations.
|
|
28
30
|
"""
|
|
29
31
|
|
|
30
|
-
def __init__(self, project_root: str = None) -> None:
|
|
31
|
-
"""Initialize the universal
|
|
32
|
-
# Use unified analysis engine instead of deprecated AdvancedAnalyzer
|
|
32
|
+
def __init__(self, project_root: str | None = None) -> None:
|
|
33
|
+
"""Initialize the universal analyze tool."""
|
|
33
34
|
self.project_root = project_root
|
|
34
35
|
self.analysis_engine = get_analysis_engine(project_root)
|
|
35
36
|
self.security_validator = SecurityValidator(project_root)
|
|
37
|
+
self.path_resolver = PathResolver(project_root)
|
|
36
38
|
logger.info("UniversalAnalyzeTool initialized with security validation")
|
|
37
39
|
|
|
38
40
|
def get_tool_definition(self) -> dict[str, Any]:
|
|
@@ -101,11 +103,17 @@ class UniversalAnalyzeTool:
|
|
|
101
103
|
language = arguments.get("language")
|
|
102
104
|
analysis_type = arguments.get("analysis_type", "basic")
|
|
103
105
|
|
|
104
|
-
#
|
|
105
|
-
|
|
106
|
+
# Resolve file path to absolute path
|
|
107
|
+
resolved_file_path = self.path_resolver.resolve(file_path)
|
|
108
|
+
logger.info(f"Analyzing file: {file_path} (resolved to: {resolved_file_path})")
|
|
109
|
+
|
|
110
|
+
# Security validation using resolved path
|
|
111
|
+
is_valid, error_msg = self.security_validator.validate_file_path(
|
|
112
|
+
resolved_file_path
|
|
113
|
+
)
|
|
106
114
|
if not is_valid:
|
|
107
115
|
logger.warning(
|
|
108
|
-
f"Security validation failed for file path: {
|
|
116
|
+
f"Security validation failed for file path: {resolved_file_path} - {error_msg}"
|
|
109
117
|
)
|
|
110
118
|
raise ValueError(f"Invalid file path: {error_msg}")
|
|
111
119
|
|
|
@@ -120,14 +128,16 @@ class UniversalAnalyzeTool:
|
|
|
120
128
|
include_queries = arguments.get("include_queries", False)
|
|
121
129
|
|
|
122
130
|
# Validate file exists
|
|
123
|
-
if not Path(
|
|
131
|
+
if not Path(resolved_file_path).exists():
|
|
124
132
|
raise ValueError("Invalid file path: file does not exist")
|
|
125
133
|
|
|
126
134
|
# Detect language if not specified
|
|
127
135
|
if not language:
|
|
128
|
-
language = detect_language_from_file(
|
|
136
|
+
language = detect_language_from_file(resolved_file_path)
|
|
129
137
|
if language == "unknown":
|
|
130
|
-
raise ValueError(
|
|
138
|
+
raise ValueError(
|
|
139
|
+
f"Could not detect language for file: {resolved_file_path}"
|
|
140
|
+
)
|
|
131
141
|
|
|
132
142
|
# Check if language is supported
|
|
133
143
|
if not is_language_supported(language):
|
|
@@ -141,7 +151,7 @@ class UniversalAnalyzeTool:
|
|
|
141
151
|
)
|
|
142
152
|
|
|
143
153
|
logger.info(
|
|
144
|
-
f"Analyzing {
|
|
154
|
+
f"Analyzing {resolved_file_path} (language: {language}, type: {analysis_type})"
|
|
145
155
|
)
|
|
146
156
|
|
|
147
157
|
try:
|
|
@@ -151,12 +161,12 @@ class UniversalAnalyzeTool:
|
|
|
151
161
|
if language == "java":
|
|
152
162
|
# Use advanced analyzer for Java
|
|
153
163
|
result = await self._analyze_with_advanced_analyzer(
|
|
154
|
-
|
|
164
|
+
resolved_file_path, language, analysis_type, include_ast
|
|
155
165
|
)
|
|
156
166
|
else:
|
|
157
167
|
# Use universal analyzer for other languages
|
|
158
168
|
result = await self._analyze_with_universal_analyzer(
|
|
159
|
-
|
|
169
|
+
resolved_file_path, language, analysis_type, include_ast
|
|
160
170
|
)
|
|
161
171
|
|
|
162
172
|
# Add query information if requested
|
|
@@ -165,11 +175,11 @@ class UniversalAnalyzeTool:
|
|
|
165
175
|
language
|
|
166
176
|
)
|
|
167
177
|
|
|
168
|
-
logger.info(f"Successfully analyzed {
|
|
178
|
+
logger.info(f"Successfully analyzed {resolved_file_path}")
|
|
169
179
|
return result
|
|
170
180
|
|
|
171
181
|
except Exception as e:
|
|
172
|
-
logger.error(f"Error analyzing {
|
|
182
|
+
logger.error(f"Error analyzing {resolved_file_path}: {e}")
|
|
173
183
|
raise
|
|
174
184
|
|
|
175
185
|
async def _analyze_with_advanced_analyzer(
|
|
@@ -26,6 +26,9 @@ from .error_handler import (
|
|
|
26
26
|
handle_mcp_errors,
|
|
27
27
|
)
|
|
28
28
|
|
|
29
|
+
# Export path resolver utilities
|
|
30
|
+
from .path_resolver import PathResolver, resolve_path
|
|
31
|
+
|
|
29
32
|
# Module metadata
|
|
30
33
|
__version__ = "2.0.0"
|
|
31
34
|
__author__ = "Tree-Sitter Analyzer Team"
|
|
@@ -36,6 +39,7 @@ MCP_UTILS_CAPABILITIES = {
|
|
|
36
39
|
"features": [
|
|
37
40
|
"Comprehensive Error Handling",
|
|
38
41
|
"Unified Core Services Integration",
|
|
42
|
+
"Cross-Platform Path Resolution",
|
|
39
43
|
],
|
|
40
44
|
"deprecated_features": [
|
|
41
45
|
"LRU Cache with TTL (moved to core.cache_service)",
|
|
@@ -99,6 +103,9 @@ __all__ = [
|
|
|
99
103
|
"ErrorCategory",
|
|
100
104
|
"handle_mcp_errors",
|
|
101
105
|
"get_error_handler",
|
|
106
|
+
# Path resolution
|
|
107
|
+
"PathResolver",
|
|
108
|
+
"resolve_path",
|
|
102
109
|
# Backward compatibility
|
|
103
110
|
"get_cache_manager",
|
|
104
111
|
"get_performance_monitor",
|