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);

Tool Definition Quality

Score is being calculated. Check back soon.

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