Skip to main content

codebolt.code_utils

Code analysis and utility functions for processing and understanding code structures.

Available Tools

  • get_files_markdown - Get files content in markdown format
  • get_js_tree - Get JavaScript/TypeScript AST tree
  • perform_match - Perform pattern matching on code
  • get_matcher_list - Get list of available matchers
  • get_match_detail - Get detailed match information

Tool Parameters

get_files_markdown

Retrieves all project files content formatted as Markdown. Useful for generating documentation or getting an overview of the codebase.

ParameterTypeRequiredDescription
(none)--This tool takes no parameters

get_js_tree

Parses a JavaScript or TypeScript file and returns its Abstract Syntax Tree (AST) representation.

ParameterTypeRequiredDescription
filePathstringYesThe path to the JavaScript/TypeScript file to parse

perform_match

Performs pattern matching on code using a matcher definition. Useful for finding specific patterns, errors, or issues in code output.

ParameterTypeRequiredDescription
matcherDefinitionobjectYesThe definition of the matcher containing owner and pattern configuration
matcherDefinition.ownerstringYesIdentifier for the matcher (e.g., "eslint-compact")
matcherDefinition.patternarrayYesArray of pattern objects defining the regex and capture groups
patternarrayYesArray of pattern objects with regex definitions
pattern[].regexpstringYesRegular expression pattern for matching
pattern[].filenumberNoCapture group index for file path
pattern[].linenumberNoCapture group index for line number
pattern[].columnnumberNoCapture group index for column number
pattern[].severitynumberNoCapture group index for severity level
pattern[].messagenumberNoCapture group index for message
pattern[].codenumberNoCapture group index for error code
problemsarrayYesArray of problem objects to match against
problems[].linestringNoThe line content to match
problems[].sourcestringNoThe source identifier

get_matcher_list

Retrieves a list of all available problem matchers in the system.

ParameterTypeRequiredDescription
(none)--This tool takes no parameters

get_match_detail

Gets detailed information about a specific problem matcher by its identifier.

ParameterTypeRequiredDescription
matcherIdstringYesThe unique identifier of the matcher to get details for (e.g., "xmllint")

Sample Usage

// Get files content in markdown format
const markdownResult = await codebolt.tools.executeTool(
"codebolt.code_utils",
"get_files_markdown",
{}
);

// Get JavaScript AST tree
const astResult = await codebolt.tools.executeTool(
"codebolt.code_utils",
"get_js_tree",
{ filePath: "./tests/terminal-test.js" }
);

// Perform pattern matching on code
const matcherDefinition = {
owner: "eslint-compact",
pattern: [{
regexp: "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
file: 1,
line: 2,
column: 3,
severity: 4,
message: 5,
code: 6
}]
};
const testProblems = [
{ line: "src/file1.js: line 10, col 5, Error - Unexpected console statement (no-console)", source: "test" },
{ line: "src/file2.js: line 25, col 8, Warning - 'var' used instead of 'let' or 'const' (no-var)", source: "test" },
{ line: "This should not match", source: "test" },
{},
{ line: "src/file3.js: line 5, col 15, Info - Missing JSDoc comment (require-jsdoc)", source: "test" }
];
const matchResult = await codebolt.tools.executeTool(
"codebolt.code_utils",
"perform_match",
{ matcherDefinition, pattern: matcherDefinition.pattern, problems: testProblems }
);

// Get list of available matchers
const matchersResult = await codebolt.tools.executeTool(
"codebolt.code_utils",
"get_matcher_list",
{}
);

// Get detailed match information
const detailResult = await codebolt.tools.executeTool(
"codebolt.code_utils",
"get_match_detail",
{ matcherId: 'xmllint' }
);
info

This functionality provides code analysis through the MCP interface.