Skip to main content
Glama
0xjcf
by 0xjcf

analyze-cursor

Analyzes code at a specific cursor position to provide context-aware insights and identify relevant patterns or issues in the surrounding code structure.

Input Schema

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

Implementation Reference

  • Handler function that processes the cursor position context, identifies the code entity using helper functions, analyzes it, and returns a JSON-formatted response.
    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)
        }]
      };
    }
  • Zod schema defining the input parameters for the analyze-cursor tool, including file info, position, and local context.
    {
      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 on the MCP server using server.tool() with name, input schema, and handler function.
    server.tool(
      "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)
          }]
        };
      }
    );
  • Placeholder helper to identify the type and details of the code entity at the cursor position.
    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
      };
    }
  • Placeholder helper to analyze the identified code entity and provide metrics and 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"
        ]
      };
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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