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.

@@ -11,7 +11,7 @@ Architecture:
11
11
  - Data Models: Generic and language-specific code element representations
12
12
  """
13
13
 
14
- __version__ = "0.4.0"
14
+ __version__ = "0.8.3"
15
15
  __author__ = "aisheng.yu"
16
16
  __email__ = "aimasteracc@gmail.com"
17
17
 
@@ -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(self.args.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"ERROR: Query '{sanitized_query_key}' not found for language '{language}'"
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
- logger.info(f"Initializing {self.name} v{self.version}")
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