tree-sitter-analyzer 0.1.3__py3-none-any.whl → 0.3.0__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.

Files changed (79) hide show
  1. tree_sitter_analyzer/__init__.py +133 -121
  2. tree_sitter_analyzer/__main__.py +11 -12
  3. tree_sitter_analyzer/api.py +531 -539
  4. tree_sitter_analyzer/cli/__init__.py +39 -39
  5. tree_sitter_analyzer/cli/__main__.py +12 -13
  6. tree_sitter_analyzer/cli/commands/__init__.py +26 -27
  7. tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
  8. tree_sitter_analyzer/cli/commands/base_command.py +160 -155
  9. tree_sitter_analyzer/cli/commands/default_command.py +18 -19
  10. tree_sitter_analyzer/cli/commands/partial_read_command.py +141 -133
  11. tree_sitter_analyzer/cli/commands/query_command.py +81 -82
  12. tree_sitter_analyzer/cli/commands/structure_command.py +138 -121
  13. tree_sitter_analyzer/cli/commands/summary_command.py +101 -93
  14. tree_sitter_analyzer/cli/commands/table_command.py +232 -233
  15. tree_sitter_analyzer/cli/info_commands.py +120 -121
  16. tree_sitter_analyzer/cli_main.py +277 -276
  17. tree_sitter_analyzer/core/__init__.py +15 -20
  18. tree_sitter_analyzer/core/analysis_engine.py +591 -574
  19. tree_sitter_analyzer/core/cache_service.py +320 -330
  20. tree_sitter_analyzer/core/engine.py +557 -560
  21. tree_sitter_analyzer/core/parser.py +293 -288
  22. tree_sitter_analyzer/core/query.py +494 -502
  23. tree_sitter_analyzer/encoding_utils.py +458 -460
  24. tree_sitter_analyzer/exceptions.py +337 -340
  25. tree_sitter_analyzer/file_handler.py +217 -222
  26. tree_sitter_analyzer/formatters/__init__.py +1 -1
  27. tree_sitter_analyzer/formatters/base_formatter.py +167 -168
  28. tree_sitter_analyzer/formatters/formatter_factory.py +78 -74
  29. tree_sitter_analyzer/formatters/java_formatter.py +287 -270
  30. tree_sitter_analyzer/formatters/python_formatter.py +255 -235
  31. tree_sitter_analyzer/interfaces/__init__.py +9 -10
  32. tree_sitter_analyzer/interfaces/cli.py +528 -557
  33. tree_sitter_analyzer/interfaces/cli_adapter.py +322 -319
  34. tree_sitter_analyzer/interfaces/mcp_adapter.py +180 -170
  35. tree_sitter_analyzer/interfaces/mcp_server.py +405 -416
  36. tree_sitter_analyzer/java_analyzer.py +218 -219
  37. tree_sitter_analyzer/language_detector.py +398 -400
  38. tree_sitter_analyzer/language_loader.py +224 -228
  39. tree_sitter_analyzer/languages/__init__.py +10 -11
  40. tree_sitter_analyzer/languages/java_plugin.py +1129 -1113
  41. tree_sitter_analyzer/languages/python_plugin.py +737 -712
  42. tree_sitter_analyzer/mcp/__init__.py +31 -32
  43. tree_sitter_analyzer/mcp/resources/__init__.py +44 -47
  44. tree_sitter_analyzer/mcp/resources/code_file_resource.py +212 -213
  45. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +560 -550
  46. tree_sitter_analyzer/mcp/server.py +333 -345
  47. tree_sitter_analyzer/mcp/tools/__init__.py +30 -31
  48. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +621 -557
  49. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +242 -245
  50. tree_sitter_analyzer/mcp/tools/base_tool.py +54 -55
  51. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -302
  52. tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -359
  53. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -476
  54. tree_sitter_analyzer/mcp/utils/__init__.py +105 -106
  55. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
  56. tree_sitter_analyzer/models.py +470 -481
  57. tree_sitter_analyzer/output_manager.py +261 -264
  58. tree_sitter_analyzer/plugins/__init__.py +333 -334
  59. tree_sitter_analyzer/plugins/base.py +477 -446
  60. tree_sitter_analyzer/plugins/java_plugin.py +608 -625
  61. tree_sitter_analyzer/plugins/javascript_plugin.py +446 -439
  62. tree_sitter_analyzer/plugins/manager.py +362 -355
  63. tree_sitter_analyzer/plugins/plugin_loader.py +85 -83
  64. tree_sitter_analyzer/plugins/python_plugin.py +606 -598
  65. tree_sitter_analyzer/plugins/registry.py +374 -366
  66. tree_sitter_analyzer/queries/__init__.py +26 -27
  67. tree_sitter_analyzer/queries/java.py +391 -394
  68. tree_sitter_analyzer/queries/javascript.py +148 -149
  69. tree_sitter_analyzer/queries/python.py +285 -286
  70. tree_sitter_analyzer/queries/typescript.py +229 -230
  71. tree_sitter_analyzer/query_loader.py +254 -260
  72. tree_sitter_analyzer/table_formatter.py +468 -448
  73. tree_sitter_analyzer/utils.py +277 -277
  74. tree_sitter_analyzer-0.3.0.dist-info/METADATA +346 -0
  75. tree_sitter_analyzer-0.3.0.dist-info/RECORD +77 -0
  76. tree_sitter_analyzer-0.1.3.dist-info/METADATA +0 -444
  77. tree_sitter_analyzer-0.1.3.dist-info/RECORD +0 -77
  78. {tree_sitter_analyzer-0.1.3.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/WHEEL +0 -0
  79. {tree_sitter_analyzer-0.1.3.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -1,302 +1,300 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Read Code Partial MCP Tool
5
-
6
- This tool provides partial file reading functionality through the MCP protocol,
7
- allowing selective content extraction with line and column range support.
8
- """
9
-
10
- import json
11
- import logging
12
- from pathlib import Path
13
- from typing import Any, Dict, Optional
14
-
15
- from ...file_handler import read_file_partial
16
- from ...utils import log_performance, setup_logger
17
-
18
- # Set up logging
19
- logger = setup_logger(__name__)
20
-
21
-
22
- class ReadPartialTool:
23
- """
24
- MCP Tool for reading partial content from code files.
25
-
26
- This tool integrates with existing file_handler functionality to provide
27
- selective file content reading through the MCP protocol.
28
- """
29
-
30
- def __init__(self) -> None:
31
- """Initialize the read partial tool."""
32
- logger.info("ReadPartialTool initialized")
33
-
34
- def get_tool_schema(self) -> Dict[str, Any]:
35
- """
36
- Get the MCP tool schema for read_code_partial.
37
-
38
- Returns:
39
- Dictionary containing the tool schema
40
- """
41
- return {
42
- "type": "object",
43
- "properties": {
44
- "file_path": {
45
- "type": "string",
46
- "description": "Path to the code file to read",
47
- },
48
- "start_line": {
49
- "type": "integer",
50
- "description": "Starting line number (1-based)",
51
- "minimum": 1,
52
- },
53
- "end_line": {
54
- "type": "integer",
55
- "description": "Ending line number (1-based, optional - reads to end if not specified)",
56
- "minimum": 1,
57
- },
58
- "start_column": {
59
- "type": "integer",
60
- "description": "Starting column number (0-based, optional)",
61
- "minimum": 0,
62
- },
63
- "end_column": {
64
- "type": "integer",
65
- "description": "Ending column number (0-based, optional)",
66
- "minimum": 0,
67
- },
68
- "format": {
69
- "type": "string",
70
- "description": "Output format for the content",
71
- "enum": ["text", "json"],
72
- "default": "text",
73
- },
74
- },
75
- "required": ["file_path", "start_line"],
76
- "additionalProperties": False,
77
- }
78
-
79
- async def execute(self, arguments: Dict[str, Any]) -> Dict[str, Any]:
80
- """
81
- Execute the read_code_partial tool.
82
-
83
- Args:
84
- arguments: Tool arguments containing file_path, line/column ranges, and format
85
-
86
- Returns:
87
- Dictionary containing the partial file content and metadata (CLI --partial-read compatible format)
88
-
89
- Raises:
90
- ValueError: If required arguments are missing or invalid
91
- FileNotFoundError: If the specified file doesn't exist
92
- """
93
- # Validate required arguments
94
- if "file_path" not in arguments:
95
- raise ValueError("file_path is required")
96
-
97
- if "start_line" not in arguments:
98
- raise ValueError("start_line is required")
99
-
100
- file_path = arguments["file_path"]
101
- start_line = arguments["start_line"]
102
- end_line = arguments.get("end_line")
103
- start_column = arguments.get("start_column")
104
- end_column = arguments.get("end_column")
105
- output_format = arguments.get("format", "text")
106
-
107
- # Validate file exists
108
- if not Path(file_path).exists():
109
- raise FileNotFoundError(f"File not found: {file_path}")
110
-
111
- # Validate line numbers
112
- if start_line < 1:
113
- raise ValueError("start_line must be >= 1")
114
-
115
- if end_line is not None and end_line < start_line:
116
- raise ValueError("end_line must be >= start_line")
117
-
118
- # Validate column numbers
119
- if start_column is not None and start_column < 0:
120
- raise ValueError("start_column must be >= 0")
121
-
122
- if end_column is not None and end_column < 0:
123
- raise ValueError("end_column must be >= 0")
124
-
125
- logger.info(
126
- f"Reading partial content from {file_path}: lines {start_line}-{end_line or 'end'}"
127
- )
128
-
129
- try:
130
- # Use existing file_handler functionality
131
- # Use performance monitoring with proper context manager
132
- from ...mcp.utils import get_performance_monitor
133
-
134
- with get_performance_monitor().measure_operation("read_code_partial"):
135
- content = self._read_file_partial(
136
- file_path, start_line, end_line, start_column, end_column
137
- )
138
-
139
- if content is None:
140
- raise RuntimeError(
141
- f"Failed to read partial content from file: {file_path}"
142
- )
143
-
144
- # Build result structure compatible with CLI --partial-read format
145
- result_data = {
146
- "file_path": file_path,
147
- "range": {
148
- "start_line": start_line,
149
- "end_line": end_line,
150
- "start_column": start_column,
151
- "end_column": end_column,
152
- },
153
- "content": content,
154
- "content_length": len(content),
155
- }
156
-
157
- # Format as JSON string like CLI does
158
- json_output = json.dumps(result_data, indent=2, ensure_ascii=False)
159
-
160
- # Build range info for header
161
- range_info = f"Line {start_line}"
162
- if end_line:
163
- range_info += f"-{end_line}"
164
-
165
- # Build CLI-compatible output with header and JSON (without log message)
166
- cli_output = (
167
- f"--- Partial Read Result ---\n"
168
- f"File: {file_path}\n"
169
- f"Range: {range_info}\n"
170
- f"Characters read: {len(content)}\n"
171
- f"{json_output}"
172
- )
173
-
174
- logger.info(
175
- f"Successfully read {len(content)} characters from {file_path}"
176
- )
177
-
178
- return {"partial_content_result": cli_output}
179
-
180
- except Exception as e:
181
- logger.error(f"Error reading partial content from {file_path}: {e}")
182
- raise
183
-
184
- def _read_file_partial(
185
- self,
186
- file_path: str,
187
- start_line: int,
188
- end_line: Optional[int] = None,
189
- start_column: Optional[int] = None,
190
- end_column: Optional[int] = None,
191
- ) -> Optional[str]:
192
- """
193
- Internal method to read partial file content.
194
-
195
- This method wraps the existing read_file_partial function from file_handler.
196
-
197
- Args:
198
- file_path: Path to the file to read
199
- start_line: Starting line number (1-based)
200
- end_line: Ending line number (1-based, optional)
201
- start_column: Starting column number (0-based, optional)
202
- end_column: Ending column number (0-based, optional)
203
-
204
- Returns:
205
- Partial file content as string, or None if error
206
- """
207
- return read_file_partial(
208
- file_path, start_line, end_line, start_column, end_column
209
- )
210
-
211
- def validate_arguments(self, arguments: Dict[str, Any]) -> bool:
212
- """
213
- Validate tool arguments against the schema.
214
-
215
- Args:
216
- arguments: Arguments to validate
217
-
218
- Returns:
219
- True if arguments are valid
220
-
221
- Raises:
222
- ValueError: If arguments are invalid
223
- """
224
- schema = self.get_tool_schema()
225
- required_fields = schema.get("required", [])
226
-
227
- # Check required fields
228
- for field in required_fields:
229
- if field not in arguments:
230
- raise ValueError(f"Required field '{field}' is missing")
231
-
232
- # Validate file_path
233
- if "file_path" in arguments:
234
- file_path = arguments["file_path"]
235
- if not isinstance(file_path, str):
236
- raise ValueError("file_path must be a string")
237
- if not file_path.strip():
238
- raise ValueError("file_path cannot be empty")
239
-
240
- # Validate start_line
241
- if "start_line" in arguments:
242
- start_line = arguments["start_line"]
243
- if not isinstance(start_line, int):
244
- raise ValueError("start_line must be an integer")
245
- if start_line < 1:
246
- raise ValueError("start_line must be >= 1")
247
-
248
- # Validate end_line
249
- if "end_line" in arguments:
250
- end_line = arguments["end_line"]
251
- if not isinstance(end_line, int):
252
- raise ValueError("end_line must be an integer")
253
- if end_line < 1:
254
- raise ValueError("end_line must be >= 1")
255
- if "start_line" in arguments and end_line < arguments["start_line"]:
256
- raise ValueError("end_line must be >= start_line")
257
-
258
- # Validate column numbers
259
- for col_field in ["start_column", "end_column"]:
260
- if col_field in arguments:
261
- col_value = arguments[col_field]
262
- if not isinstance(col_value, int):
263
- raise ValueError(f"{col_field} must be an integer")
264
- if col_value < 0:
265
- raise ValueError(f"{col_field} must be >= 0")
266
-
267
- # Validate format
268
- if "format" in arguments:
269
- format_value = arguments["format"]
270
- if not isinstance(format_value, str):
271
- raise ValueError("format must be a string")
272
- if format_value not in ["text", "json"]:
273
- raise ValueError("format must be 'text' or 'json'")
274
-
275
- return True
276
-
277
- def get_tool_definition(self) -> Any:
278
- """
279
- Get the MCP tool definition for read_code_partial.
280
-
281
- Returns:
282
- Tool definition object compatible with MCP server
283
- """
284
- try:
285
- from mcp.types import Tool
286
-
287
- return Tool(
288
- name="read_code_partial",
289
- description="Read partial content from code files with line and column range support (equivalent to CLI --partial-read option)",
290
- inputSchema=self.get_tool_schema(),
291
- )
292
- except ImportError:
293
- # Fallback for when MCP is not available
294
- return {
295
- "name": "read_code_partial",
296
- "description": "Read partial content from code files with line and column range support (equivalent to CLI --partial-read option)",
297
- "inputSchema": self.get_tool_schema(),
298
- }
299
-
300
-
301
- # Tool instance for easy access
302
- read_partial_tool = ReadPartialTool()
1
+ #!/usr/bin/env python3
2
+ """
3
+ Read Code Partial MCP Tool
4
+
5
+ This tool provides partial file reading functionality through the MCP protocol,
6
+ allowing selective content extraction with line and column range support.
7
+ """
8
+
9
+ import json
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ from ...file_handler import read_file_partial
14
+ from ...utils import setup_logger
15
+
16
+ # Set up logging
17
+ logger = setup_logger(__name__)
18
+
19
+
20
+ class ReadPartialTool:
21
+ """
22
+ MCP Tool for reading partial content from code files.
23
+
24
+ This tool integrates with existing file_handler functionality to provide
25
+ selective file content reading through the MCP protocol.
26
+ """
27
+
28
+ def __init__(self) -> None:
29
+ """Initialize the read partial tool."""
30
+ logger.info("ReadPartialTool initialized")
31
+
32
+ def get_tool_schema(self) -> dict[str, Any]:
33
+ """
34
+ Get the MCP tool schema for read_code_partial.
35
+
36
+ Returns:
37
+ Dictionary containing the tool schema
38
+ """
39
+ return {
40
+ "type": "object",
41
+ "properties": {
42
+ "file_path": {
43
+ "type": "string",
44
+ "description": "Path to the code file to read",
45
+ },
46
+ "start_line": {
47
+ "type": "integer",
48
+ "description": "Starting line number (1-based)",
49
+ "minimum": 1,
50
+ },
51
+ "end_line": {
52
+ "type": "integer",
53
+ "description": "Ending line number (1-based, optional - reads to end if not specified)",
54
+ "minimum": 1,
55
+ },
56
+ "start_column": {
57
+ "type": "integer",
58
+ "description": "Starting column number (0-based, optional)",
59
+ "minimum": 0,
60
+ },
61
+ "end_column": {
62
+ "type": "integer",
63
+ "description": "Ending column number (0-based, optional)",
64
+ "minimum": 0,
65
+ },
66
+ "format": {
67
+ "type": "string",
68
+ "description": "Output format for the content",
69
+ "enum": ["text", "json"],
70
+ "default": "text",
71
+ },
72
+ },
73
+ "required": ["file_path", "start_line"],
74
+ "additionalProperties": False,
75
+ }
76
+
77
+ async def execute(self, arguments: dict[str, Any]) -> dict[str, Any]:
78
+ """
79
+ Execute the read_code_partial tool.
80
+
81
+ Args:
82
+ arguments: Tool arguments containing file_path, line/column ranges, and format
83
+
84
+ Returns:
85
+ Dictionary containing the partial file content and metadata (CLI --partial-read compatible format)
86
+
87
+ Raises:
88
+ ValueError: If required arguments are missing or invalid
89
+ FileNotFoundError: If the specified file doesn't exist
90
+ """
91
+ # Validate required arguments
92
+ if "file_path" not in arguments:
93
+ raise ValueError("file_path is required")
94
+
95
+ if "start_line" not in arguments:
96
+ raise ValueError("start_line is required")
97
+
98
+ file_path = arguments["file_path"]
99
+ start_line = arguments["start_line"]
100
+ end_line = arguments.get("end_line")
101
+ start_column = arguments.get("start_column")
102
+ end_column = arguments.get("end_column")
103
+ # output_format = arguments.get("format", "text") # Not used currently
104
+
105
+ # Validate file exists
106
+ if not Path(file_path).exists():
107
+ raise FileNotFoundError(f"File not found: {file_path}")
108
+
109
+ # Validate line numbers
110
+ if start_line < 1:
111
+ raise ValueError("start_line must be >= 1")
112
+
113
+ if end_line is not None and end_line < start_line:
114
+ raise ValueError("end_line must be >= start_line")
115
+
116
+ # Validate column numbers
117
+ if start_column is not None and start_column < 0:
118
+ raise ValueError("start_column must be >= 0")
119
+
120
+ if end_column is not None and end_column < 0:
121
+ raise ValueError("end_column must be >= 0")
122
+
123
+ logger.info(
124
+ f"Reading partial content from {file_path}: lines {start_line}-{end_line or 'end'}"
125
+ )
126
+
127
+ try:
128
+ # Use existing file_handler functionality
129
+ # Use performance monitoring with proper context manager
130
+ from ...mcp.utils import get_performance_monitor
131
+
132
+ with get_performance_monitor().measure_operation("read_code_partial"):
133
+ content = self._read_file_partial(
134
+ file_path, start_line, end_line, start_column, end_column
135
+ )
136
+
137
+ if content is None:
138
+ raise RuntimeError(
139
+ f"Failed to read partial content from file: {file_path}"
140
+ )
141
+
142
+ # Build result structure compatible with CLI --partial-read format
143
+ result_data = {
144
+ "file_path": file_path,
145
+ "range": {
146
+ "start_line": start_line,
147
+ "end_line": end_line,
148
+ "start_column": start_column,
149
+ "end_column": end_column,
150
+ },
151
+ "content": content,
152
+ "content_length": len(content),
153
+ }
154
+
155
+ # Format as JSON string like CLI does
156
+ json_output = json.dumps(result_data, indent=2, ensure_ascii=False)
157
+
158
+ # Build range info for header
159
+ range_info = f"Line {start_line}"
160
+ if end_line:
161
+ range_info += f"-{end_line}"
162
+
163
+ # Build CLI-compatible output with header and JSON (without log message)
164
+ cli_output = (
165
+ f"--- Partial Read Result ---\n"
166
+ f"File: {file_path}\n"
167
+ f"Range: {range_info}\n"
168
+ f"Characters read: {len(content)}\n"
169
+ f"{json_output}"
170
+ )
171
+
172
+ logger.info(
173
+ f"Successfully read {len(content)} characters from {file_path}"
174
+ )
175
+
176
+ return {"partial_content_result": cli_output}
177
+
178
+ except Exception as e:
179
+ logger.error(f"Error reading partial content from {file_path}: {e}")
180
+ raise
181
+
182
+ def _read_file_partial(
183
+ self,
184
+ file_path: str,
185
+ start_line: int,
186
+ end_line: int | None = None,
187
+ start_column: int | None = None,
188
+ end_column: int | None = None,
189
+ ) -> str | None:
190
+ """
191
+ Internal method to read partial file content.
192
+
193
+ This method wraps the existing read_file_partial function from file_handler.
194
+
195
+ Args:
196
+ file_path: Path to the file to read
197
+ start_line: Starting line number (1-based)
198
+ end_line: Ending line number (1-based, optional)
199
+ start_column: Starting column number (0-based, optional)
200
+ end_column: Ending column number (0-based, optional)
201
+
202
+ Returns:
203
+ Partial file content as string, or None if error
204
+ """
205
+ return read_file_partial(
206
+ file_path, start_line, end_line, start_column, end_column
207
+ )
208
+
209
+ def validate_arguments(self, arguments: dict[str, Any]) -> bool:
210
+ """
211
+ Validate tool arguments against the schema.
212
+
213
+ Args:
214
+ arguments: Arguments to validate
215
+
216
+ Returns:
217
+ True if arguments are valid
218
+
219
+ Raises:
220
+ ValueError: If arguments are invalid
221
+ """
222
+ schema = self.get_tool_schema()
223
+ required_fields = schema.get("required", [])
224
+
225
+ # Check required fields
226
+ for field in required_fields:
227
+ if field not in arguments:
228
+ raise ValueError(f"Required field '{field}' is missing")
229
+
230
+ # Validate file_path
231
+ if "file_path" in arguments:
232
+ file_path = arguments["file_path"]
233
+ if not isinstance(file_path, str):
234
+ raise ValueError("file_path must be a string")
235
+ if not file_path.strip():
236
+ raise ValueError("file_path cannot be empty")
237
+
238
+ # Validate start_line
239
+ if "start_line" in arguments:
240
+ start_line = arguments["start_line"]
241
+ if not isinstance(start_line, int):
242
+ raise ValueError("start_line must be an integer")
243
+ if start_line < 1:
244
+ raise ValueError("start_line must be >= 1")
245
+
246
+ # Validate end_line
247
+ if "end_line" in arguments:
248
+ end_line = arguments["end_line"]
249
+ if not isinstance(end_line, int):
250
+ raise ValueError("end_line must be an integer")
251
+ if end_line < 1:
252
+ raise ValueError("end_line must be >= 1")
253
+ if "start_line" in arguments and end_line < arguments["start_line"]:
254
+ raise ValueError("end_line must be >= start_line")
255
+
256
+ # Validate column numbers
257
+ for col_field in ["start_column", "end_column"]:
258
+ if col_field in arguments:
259
+ col_value = arguments[col_field]
260
+ if not isinstance(col_value, int):
261
+ raise ValueError(f"{col_field} must be an integer")
262
+ if col_value < 0:
263
+ raise ValueError(f"{col_field} must be >= 0")
264
+
265
+ # Validate format
266
+ if "format" in arguments:
267
+ format_value = arguments["format"]
268
+ if not isinstance(format_value, str):
269
+ raise ValueError("format must be a string")
270
+ if format_value not in ["text", "json"]:
271
+ raise ValueError("format must be 'text' or 'json'")
272
+
273
+ return True
274
+
275
+ def get_tool_definition(self) -> Any:
276
+ """
277
+ Get the MCP tool definition for read_code_partial.
278
+
279
+ Returns:
280
+ Tool definition object compatible with MCP server
281
+ """
282
+ try:
283
+ from mcp.types import Tool
284
+
285
+ return Tool(
286
+ name="read_code_partial",
287
+ description="Read partial content from code files with line and column range support (equivalent to CLI --partial-read option)",
288
+ inputSchema=self.get_tool_schema(),
289
+ )
290
+ except ImportError:
291
+ # Fallback for when MCP is not available
292
+ return {
293
+ "name": "read_code_partial",
294
+ "description": "Read partial content from code files with line and column range support (equivalent to CLI --partial-read option)",
295
+ "inputSchema": self.get_tool_schema(),
296
+ }
297
+
298
+
299
+ # Tool instance for easy access
300
+ read_partial_tool = ReadPartialTool()