Skip to main content
Glama

get_hover

Retrieve detailed hover information for a specific position in a code document, including language ID, file path, content, and project root, to enhance code editing and analysis.

Instructions

Get hover information for a position in a document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
characterYesZero-based character offset for hover position
contentYesThe current content of the file
filePathYesAbsolute or relative path to the source file
languageIdYesThe language identifier (e.g., "typescript", "javascript")
lineYesZero-based line number for hover position
projectRootYesImportant: Root directory of the project for resolving imports and node_modules where the tsconfig.json or jsconfig.json is located

Implementation Reference

  • The main handler function for the 'get_hover' tool. It creates or retrieves a language server instance, opens the provided document, sends a hover request at the specified position, and returns the hover contents or an error.
    private async handleGetHover(args: any): Promise<any> {
      const { languageId, filePath, content, line, character, projectRoot } = args;
      console.log(`[handleGetHover] Processing request for ${languageId}`);
      
      const server = await this.getOrCreateServer(languageId, projectRoot);
      const actualRoot = server.workspaceRoot;
    
      const absolutePath = isAbsolute(filePath) ? filePath : join(actualRoot, filePath);
      const uri = `file://${absolutePath}`;
    
      // Ensure directory exists (for languages that may require file presence)
      const dir = dirname(absolutePath);
      if (!existsSync(dir)) {
        mkdirSync(dir, { recursive: true });
      }
    
      const textDocument: TextDocumentItem = {
        uri,
        languageId,
        version: 1,
        text: content,
      };
    
      console.log(`[handleGetHover] Sending document to server:`, textDocument);
      await server.connection.sendNotification('textDocument/didOpen', {
        textDocument,
      } as DidOpenTextDocumentParams);
    
      try {
        console.log(`[handleGetHover] Requesting hover information`);
        const hover: Hover = await server.connection.sendRequest('textDocument/hover', {
          textDocument: { uri } as TextDocumentIdentifier,
          position: { line, character },
        });
    
        console.log(`[handleGetHover] Received hover response:`, hover);
        return {
          content: [
            {
              type: 'text',
              text: hover?.contents
                ? JSON.stringify(hover.contents, null, 2)
                : 'No hover information available',
            },
          ],
        };
      } catch (error) {
        console.error('[handleGetHover] Request failed:', error);
        return {
          content: [
            {
              type: 'text',
              text: 'Failed to get hover information',
            },
          ],
          isError: true,
        };
      }
    }
  • Input schema definition for the 'get_hover' tool, specifying parameters like languageId, filePath, content, position (line, character), and projectRoot.
      type: 'object',
      properties: {
        languageId: { 
          type: 'string',
          description: 'The language identifier (e.g., "typescript", "javascript")'
        },
        filePath: { 
          type: 'string',
          description: 'Absolute or relative path to the source file'
        },
        content: { 
          type: 'string',
          description: 'The current content of the file'
        },
        line: { 
          type: 'number',
          description: 'Zero-based line number for hover position'
        },
        character: { 
          type: 'number',
          description: 'Zero-based character offset for hover position'
        },
        projectRoot: { 
          type: 'string',
          description: 'Important: Root directory of the project for resolving imports and node_modules where the tsconfig.json or jsconfig.json is located'
        },
      },
      required: ['languageId', 'filePath', 'content', 'line', 'character', 'projectRoot'],
    },
  • src/index.ts:291-324 (registration)
    Registration of the 'get_hover' tool in the MCP server's tool list, returned by ListToolsRequestSchema handler.
    {
      name: 'get_hover',
      description: 'Get hover information for a position in a document',
      inputSchema: {
        type: 'object',
        properties: {
          languageId: { 
            type: 'string',
            description: 'The language identifier (e.g., "typescript", "javascript")'
          },
          filePath: { 
            type: 'string',
            description: 'Absolute or relative path to the source file'
          },
          content: { 
            type: 'string',
            description: 'The current content of the file'
          },
          line: { 
            type: 'number',
            description: 'Zero-based line number for hover position'
          },
          character: { 
            type: 'number',
            description: 'Zero-based character offset for hover position'
          },
          projectRoot: { 
            type: 'string',
            description: 'Important: Root directory of the project for resolving imports and node_modules where the tsconfig.json or jsconfig.json is located'
          },
        },
        required: ['languageId', 'filePath', 'content', 'line', 'character', 'projectRoot'],
      },
    },
  • src/index.ts:395-396 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes 'get_hover' calls to the handleGetHover method.
    case 'get_hover':
      result = await this.handleGetHover(args);
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe behavioral traits like whether it's read-only, what the output format might be, potential errors, or performance characteristics. For a tool with 6 required parameters and no annotations, this leaves significant gaps in understanding how the tool behaves.

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

Conciseness5/5

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

The description is a single, efficient sentence that states the purpose clearly without unnecessary words. It's appropriately sized and front-loaded with the essential information. Every word earns its place in this concise formulation.

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

Completeness2/5

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

Given the complexity (6 required parameters, no annotations, no output schema), the description is insufficiently complete. It doesn't explain what 'hover information' entails, what format the response might have, or any behavioral aspects. For a tool that likely returns structured data about code elements at a specific position, more context about the expected output would be helpful.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all 6 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

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

Purpose4/5

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

The description clearly states the verb ('Get') and resource ('hover information') with specific context ('for a position in a document'). It distinguishes from sibling tools like 'get_completions' and 'get_diagnostics' by focusing on hover functionality rather than completions or diagnostics. However, it doesn't explicitly differentiate from siblings beyond the inherent difference in purpose.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention sibling tools, prerequisites, or specific contexts for invocation. It lacks explicit instructions on when this tool is appropriate compared to other tools in the server.

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

Related 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/alexwohletz/language-server-mcp'

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