Tools

get_code_element

Extract specific functions, classes, or methods by name

The get_code_element tool retrieves the complete implementation of a specific function, class, method, or type by name. It returns the full source code along with rich metadata including parameters, return types, complexity scores, and documentation.

How It Works

Stellarion uses tree-sitter AST parsing to accurately identify code elements and extract their complete implementations. It first queries a RocksDB index for instant results (<10ms) and falls back to full AST parsing if needed.

When to Use

  • Getting the implementation of a known function: When you need to see exactly how a function works
  • Extracting a class definition: View complete class with all methods and properties
  • Reviewing a specific method: Understand a single method in isolation
  • Understanding a particular piece of code: Deep dive into specific code elements
  • Getting signature details: Check parameter types, return types, and documentation

Parameters

ParameterTypeRequiredDefaultDescription
namestringYes-Name of the element to find (or * for entire file)
typestringNoautoElement type: function, class, method, type, enum, variable, constant, or auto
filestringNo-Specific file path to search in
includeCommentsbooleanNofalseInclude associated documentation comments
includeSignaturebooleanNofalseInclude detailed function/method signature

MCP Command Syntax

mcp__stellarion__get_code_element name:"ElementName" type:class file:src/services/user.ts

Examples

Get a Function

Natural Language:

Show me the validateEmail function implementation

Direct MCP Call:

mcp__stellarion__get_code_element name:validateEmail type:function

Returns: Complete implementation of validateEmail with file path and line numbers


Get a Class

Natural Language:

Show me the UserService class

Direct MCP Call:

mcp__stellarion__get_code_element name:UserService type:class includeComments:true

Returns: Full class definition including all methods, properties, and JSDoc comments


Get a Specific Method

Natural Language:

Show me the handleSubmit method

Direct MCP Call:

mcp__stellarion__get_code_element name:handleSubmit type:method includeSignature:true

Returns: The handleSubmit method with parameter and return type details


Get from Specific File

Natural Language:

Get the processData function from src/utils/helpers.ts

Direct MCP Call:

mcp__stellarion__get_code_element name:processData file:src/utils/helpers.ts

Returns: The processData function from that specific file (useful when multiple functions share the same name)


Get a Type Definition

Natural Language:

Show me the UserConfig type

Direct MCP Call:

mcp__stellarion__get_code_element name:UserConfig type:type includeComments:true

Returns: The complete type definition with documentation


Get an Interface

Natural Language:

Show me the ApiResponse interface

Direct MCP Call:

mcp__stellarion__get_code_element name:ApiResponse type:type

Returns: Interface definition with all properties


Get Entire File Content

Natural Language:

Show me the entire config.ts file

Direct MCP Call:

mcp__stellarion__get_code_element name:"*" file:src/config.ts

Returns: Complete file content (special * wildcard)

Output Format

Results include:

FieldDescription
Source codeComplete implementation of the element
File pathFull path to the file
Line rangeStart and end line numbers
Element typeFunction, class, method, etc.
VisibilityPublic, private, protected, exported
ParametersParameter names, types, and documentation
Return typeFunction return type
PropertiesClass/interface properties with types
ComplexityCyclomatic and cognitive complexity scores
DocumentationJSDoc/docstring comments if present

Element Types

TypeDescriptionExamples
functionStandalone functionsfunction foo(), const foo = () =>
classClass definitionsclass UserService
methodClass methodsclass.method()
typeType aliases and interfacestype Config = {}, interface User
enumEnumerationsenum Status
variableVariable declarationsconst config = {}
constantConstant declarationsconst MAX_SIZE = 100
autoAuto-detect element typeAny of the above

Tips for Best Results

  1. Use type: "auto" if you're not sure of the element type - Stellarion will find it
  2. Add includeComments: true to get documentation and understand the purpose
  3. Specify file when multiple elements share the same name across the codebase
  4. Use includeSignature: true for detailed parameter information
  5. Combine with search tools - use search_pattern to find elements, then get_code_element to extract them

Handling Multiple Matches

If the same name exists in multiple files:

  1. Best practice: Specify the file parameter to get the exact element you want
  2. Without file: Returns the first match found (may not be what you expect)
  3. Use search first: Run search_pattern to see all locations, then extract the specific one

Performance

  • With index: Sub-10ms retrieval from RocksDB
  • Without index: Falls back to AST parsing (still fast for single files)
  • Large files: Efficiently handles files of any size