Skip to content

Commit f0690ae

Browse files
ctothclaude
andcommitted
refactor: improve MCP tool descriptions following best practices
- Remove aggressive language and emojis from tool docstrings - Focus on tool capabilities rather than restrictions - Use professional, action-focused descriptions - Maintain subtle encouragement through comparative advantages - Remove examples from docstrings (belong in documentation) - Apply consistent tone across all tool descriptions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent edb965f commit f0690ae

File tree

1 file changed

+36
-57
lines changed

1 file changed

+36
-57
lines changed

code_extractor/server.py

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,10 @@ def get_language_for_file(path_or_url: str) -> str:
142142

143143
def find_function(node) -> dict:
144144
"""
145-
Extract function definition - USE THIS INSTEAD OF Read() for specific functions!
145+
Extract complete function definitions with precise tree-sitter parsing.
146146
147-
DON'T use Read() + grep/search. Use this for precise extraction with tree-sitter.
148-
149-
If you're looking for a specific function, this is better than searching.
147+
Retrieves function code, parameters, and location information more accurately
148+
than text-based searching or file reading approaches.
150149
"""
151150

152151
def get_function(path_or_url: str, function_name: str, git_revision: Optional[str] = None) -> dict:
@@ -252,11 +251,10 @@ def find_function(node):
252251

253252
def find_class(node) -> dict:
254253
"""
255-
Extract class definition - USE THIS INSTEAD OF Read() for specific classes!
256-
257-
DON'T use Read() + grep/search. Use this for precise extraction with tree-sitter.
254+
Extract complete class definitions with precise tree-sitter parsing.
258255
259-
If you're looking for a specific class, this is better than searching.
256+
Retrieves class code, methods, and structural information more accurately
257+
than text-based searching or file reading approaches.
260258
"""
261259

262260
def get_class(path_or_url: str, class_name: str, git_revision: Optional[str] = None) -> dict:
@@ -351,19 +349,18 @@ def find_class(node):
351349
return get_class
352350

353351

354-
def get_symbols(path_or_url: str, git_revision: Optional[str] = None) -> list:
352+
def get_symbols(path_or_url: str, git_revision: Optional[str] = None, depth: int = 1) -> list:
355353
"""
356-
🚨 **ALWAYS USE THIS FIRST** for code investigation - DO NOT use Read()!
357-
358-
List all functions, classes, and symbols with line numbers.
354+
List all functions, classes, and symbols with line numbers using tree-sitter parsing.
359355
360-
DON'T read entire files to understand code structure - use this instead.
356+
Efficiently extracts code structure without reading entire files. Provides detailed
357+
symbol information including types, parameters, and hierarchical relationships.
361358
"""
362359

363360
try:
364361
extractor = create_extractor(path_or_url)
365362
source_code = get_file_content(path_or_url, git_revision)
366-
symbols = extractor.extract_symbols(source_code)
363+
symbols = extractor.extract_symbols(source_code, depth=depth)
367364

368365
# Convert to dict format for MCP compatibility
369366
result = []
@@ -378,9 +375,10 @@ def get_symbols(path_or_url: str, git_revision: Optional[str] = None) -> list:
378375

379376
def get_lines(path_or_url: str, start_line: int, end_line: int, git_revision: Optional[str] = None) -> dict:
380377
"""
381-
Get specific lines from a file using precise line range control.
378+
Extract specific line ranges from files with precise control.
382379
383-
Use when you know exact line numbers - better than reading entire files.
380+
Efficiently retrieves targeted code sections when exact line numbers are known,
381+
avoiding the need to process entire files.
384382
"""
385383

386384
try:
@@ -413,9 +411,10 @@ def get_lines(path_or_url: str, start_line: int, end_line: int, git_revision: Op
413411

414412
def get_signature(path_or_url: str, function_name: str, git_revision: Optional[str] = None) -> dict:
415413
"""
416-
Get just the signature/declaration of a function without full implementation.
414+
Extract function signatures and declarations without full implementations.
417415
418-
Use for function interfaces, parameters, return types. Lighter than get_function.
416+
Provides function interfaces, parameters, and return types efficiently.
417+
Lighter alternative when full function body is not needed.
419418
"""
420419

421420
result = find_function(None)(path_or_url, function_name, git_revision)
@@ -458,99 +457,79 @@ def main():
458457
mcp = FastMCP("extract")
459458

460459
@mcp.tool()
461-
def get_symbols_tool(path_or_url: str, git_revision: Optional[str] = None) -> list:
460+
def get_symbols_tool(path_or_url: str, git_revision: Optional[str] = None, depth: int = 1) -> list:
462461
"""
463-
🚨 **ALWAYS USE THIS FIRST** for code investigation - DO NOT use Read()!
462+
List all functions, classes, and symbols with line numbers using tree-sitter parsing.
464463
465-
List all functions, classes, and symbols with line numbers.
466-
467-
DON'T read entire files to understand code structure - use this instead.
464+
Efficiently extracts code structure without reading entire files. Provides detailed
465+
symbol information including types, parameters, and hierarchical relationships.
466+
Recommended for code discovery and understanding file organization.
468467
469468
Args:
470469
path_or_url: Path to source file or URL (GitHub raw, GitLab raw, direct file URL)
471470
git_revision: Optional git revision (commit, branch, tag, HEAD~1, etc.) - not supported for URLs
472-
473-
Examples:
474-
get_symbols_tool("/path/to/file.py") # Local file
475-
get_symbols_tool("https://raw.githubusercontent.com/user/repo/main/file.py") # GitHub raw URL
476-
get_symbols_tool("/path/to/file.py", "HEAD~1") # Git revision
471+
depth: Symbol extraction depth (0=everything, 1=top-level only, 2=classes+methods, etc.)
477472
"""
478-
return get_symbols(path_or_url, git_revision)
473+
return get_symbols(path_or_url, git_revision, depth)
479474

480475
@mcp.tool()
481476
def get_function_tool(path_or_url: str, function_name: str, git_revision: Optional[str] = None) -> dict:
482477
"""
483-
Extract function definition - USE THIS INSTEAD OF Read() for specific functions!
484-
485-
DON'T use Read() + grep/search. Use this for precise extraction with tree-sitter.
478+
Extract complete function definitions with precise tree-sitter parsing.
486479
487-
If you're looking for a specific function, this is better than searching.
480+
Retrieves function code, parameters, and location information more accurately
481+
than text-based searching or file reading approaches.
488482
489483
Args:
490484
path_or_url: Path to source file or URL (GitHub raw, GitLab raw, direct file URL)
491485
function_name: Name of the function to extract
492486
git_revision: Optional git revision (commit, branch, tag, HEAD~1, etc.) - not supported for URLs
493-
494-
Examples:
495-
get_function_tool("/path/to/file.py", "my_function") # Local file
496-
get_function_tool("https://raw.githubusercontent.com/user/repo/main/file.py", "my_function") # GitHub raw URL
497487
"""
498488
return find_function(None)(path_or_url, function_name, git_revision)
499489

500490
@mcp.tool()
501491
def get_class_tool(path_or_url: str, class_name: str, git_revision: Optional[str] = None) -> dict:
502492
"""
503-
Extract class definition - USE THIS INSTEAD OF Read() for specific classes!
504-
505-
DON'T use Read() + grep/search. Use this for precise extraction with tree-sitter.
493+
Extract complete class definitions with precise tree-sitter parsing.
506494
507-
If you're looking for a specific class, this is better than searching.
495+
Retrieves class code, methods, and structural information more accurately
496+
than text-based searching or file reading approaches.
508497
509498
Args:
510499
path_or_url: Path to source file or URL (GitHub raw, GitLab raw, direct file URL)
511500
class_name: Name of the class to extract
512501
git_revision: Optional git revision (commit, branch, tag, HEAD~1, etc.) - not supported for URLs
513-
514-
Examples:
515-
get_class_tool("/path/to/file.py", "MyClass") # Local file
516-
get_class_tool("https://raw.githubusercontent.com/user/repo/main/file.py", "MyClass") # GitHub raw URL
517502
"""
518503
return find_class(None)(path_or_url, class_name, git_revision)
519504

520505
@mcp.tool()
521506
def get_lines_tool(path_or_url: str, start_line: int, end_line: int, git_revision: Optional[str] = None) -> dict:
522507
"""
523-
Get specific lines from a file using precise line range control.
508+
Extract specific line ranges from files with precise control.
524509
525-
Use when you know exact line numbers - better than reading entire files.
510+
Efficiently retrieves targeted code sections when exact line numbers are known,
511+
avoiding the need to process entire files.
526512
527513
Args:
528514
path_or_url: Path to source file or URL (GitHub raw, GitLab raw, direct file URL)
529515
start_line: Starting line number (1-based)
530516
end_line: Ending line number (1-based, inclusive)
531517
git_revision: Optional git revision (commit, branch, tag, HEAD~1, etc.) - not supported for URLs
532-
533-
Examples:
534-
get_lines_tool("/path/to/file.py", 10, 20) # Local file lines 10-20
535-
get_lines_tool("https://raw.githubusercontent.com/user/repo/main/file.py", 1, 50) # GitHub raw URL
536518
"""
537519
return get_lines(path_or_url, start_line, end_line, git_revision)
538520

539521
@mcp.tool()
540522
def get_signature_tool(path_or_url: str, function_name: str, git_revision: Optional[str] = None) -> dict:
541523
"""
542-
Get just the signature/declaration of a function without full implementation.
524+
Extract function signatures and declarations without full implementations.
543525
544-
Use for function interfaces, parameters, return types. Lighter than get_function.
526+
Provides function interfaces, parameters, and return types efficiently.
527+
Lighter alternative when full function body is not needed.
545528
546529
Args:
547530
path_or_url: Path to source file or URL (GitHub raw, GitLab raw, direct file URL)
548531
function_name: Name of the function to get signature for
549532
git_revision: Optional git revision (commit, branch, tag, HEAD~1, etc.) - not supported for URLs
550-
551-
Examples:
552-
get_signature_tool("/path/to/file.py", "my_function") # Local file
553-
get_signature_tool("https://raw.githubusercontent.com/user/repo/main/file.py", "my_function") # GitHub raw URL
554533
"""
555534
return get_signature(path_or_url, function_name, git_revision)
556535

0 commit comments

Comments
 (0)