Skip to main content
Glama

analyze-cursor

Identifies and analyzes code context around a cursor position to support syntax analysis, dependency checks, and AI-assisted development workflows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
columnYesCursor column position (1-based)
contextYesContext around cursor
fileContentYesContent of the file
filePathYesPath to the file
lineYesCursor line position (1-based)

Implementation Reference

  • Handler function for the analyze-cursor tool. It takes file path, content, cursor position, and context; identifies the code entity at cursor, analyzes it using helpers, and returns a JSON-formatted analysis as text content.
    async (args: { filePath: string; fileContent: string; line: number; column: number; context: { before: string[]; target: string; after: string[]; } }) => { const { filePath, fileContent, line, column, context } = args; // Determine language from file extension const extension = path.extname(filePath).slice(1); // Find the code entity at the cursor position const entity = identifyCodeEntity(fileContent, line, column, extension); // Analyze the entity const analysis = analyzeCodeEntity(entity, extension); return { content: [{ type: "text", text: JSON.stringify({ file: path.basename(filePath), position: { line, column }, entity: entity.type, name: entity.name, analysis }, null, 2) }] }; } );
  • Input schema definition for the analyze-cursor tool using Zod, validating filePath, fileContent, line, column, and context around cursor.
    filePath: z.string().describe("Path to the file"), fileContent: z.string().describe("Content of the file"), line: z.number().describe("Cursor line position (1-based)"), column: z.number().describe("Cursor column position (1-based)"), context: z.object({ before: z.array(z.string()).describe("Lines before cursor"), target: z.string().describe("Line at cursor"), after: z.array(z.string()).describe("Lines after cursor") }).describe("Context around cursor") },
  • Registration of the analyze-cursor tool via server.tool() call within registerIdeTools function.
    "analyze-cursor", { filePath: z.string().describe("Path to the file"), fileContent: z.string().describe("Content of the file"), line: z.number().describe("Cursor line position (1-based)"), column: z.number().describe("Cursor column position (1-based)"), context: z.object({ before: z.array(z.string()).describe("Lines before cursor"), target: z.string().describe("Line at cursor"), after: z.array(z.string()).describe("Lines after cursor") }).describe("Context around cursor") }, async (args: { filePath: string; fileContent: string; line: number; column: number; context: { before: string[]; target: string; after: string[]; } }) => { const { filePath, fileContent, line, column, context } = args; // Determine language from file extension const extension = path.extname(filePath).slice(1); // Find the code entity at the cursor position const entity = identifyCodeEntity(fileContent, line, column, extension); // Analyze the entity const analysis = analyzeCodeEntity(entity, extension); return { content: [{ type: "text", text: JSON.stringify({ file: path.basename(filePath), position: { line, column }, entity: entity.type, name: entity.name, analysis }, null, 2) }] }; } );
  • Helper function to identify the code entity (e.g., function) at the given cursor position in the file content.
    function identifyCodeEntity( content: string, line: number, column: number, language: string ): { type: string; name: string; startLine: number; endLine: number; complexity: number; } { // This is a placeholder implementation // In a real implementation, you would use a language parser to identify // the function, class, or other entity at the cursor position return { type: "function", name: "exampleFunction", startLine: line - 2, endLine: line + 5, complexity: 3 }; }
  • Helper function to analyze the identified code entity, computing metrics like complexity, LOC, and providing recommendations.
    function analyzeCodeEntity( entity: { type: string; name: string; startLine: number; endLine: number; complexity: number }, language: string ): { complexity: number; linesOfCode: number; recommendations: string[]; } { // This is a placeholder implementation // In a real implementation, you would perform deeper analysis on the entity return { complexity: entity.complexity, linesOfCode: entity.endLine - entity.startLine + 1, recommendations: [ "Consider breaking this function into smaller parts", "Add more descriptive variable names" ] }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/0xjcf/MCP_CodeAnalysis'

If you have feedback or need assistance with the MCP directory API, please join our Discord server