Skip to main content
Glama

get_completions

Generate code completion suggestions for a specified position in a document by providing language, file path, content, and project context.

Instructions

Get completion suggestions for a position in a document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
characterYesZero-based character offset for completion 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 completion 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 core handler function that implements the 'get_completions' tool logic. It extracts parameters, ensures the language server is running, opens the document, sends a completion request to the LSP server, and formats the response.
    private async handleGetCompletions(args: any): Promise<any> {
      const { languageId, filePath, content, line, character, projectRoot } = args;
      console.log(`[handleGetCompletions] 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
      const dir = dirname(absolutePath);
      if (!existsSync(dir)) {
        mkdirSync(dir, { recursive: true });
      }
    
      const textDocument: TextDocumentItem = {
        uri,
        languageId,
        version: 1,
        text: content,
      };
    
      console.log(`[handleGetCompletions] Sending document to server:`, textDocument);
      await server.connection.sendNotification('textDocument/didOpen', {
        textDocument,
      } as DidOpenTextDocumentParams);
    
      try {
        console.log(`[handleGetCompletions] Requesting completions`);
        const completionParams: CompletionParams = {
          textDocument: { uri },
          position: { line, character },
        };
    
        const completions: CompletionItem[] | null = await server.connection.sendRequest(
          'textDocument/completion',
          completionParams
        );
    
        console.log(`[handleGetCompletions] Received completions:`, completions);
        return {
          content: [
            {
              type: 'text',
              text: completions
                ? JSON.stringify(completions, null, 2)
                : 'No completions available',
            },
          ],
        };
      } catch (error) {
        console.error('[handleGetCompletions] Request failed:', error);
        return {
          content: [
            {
              type: 'text',
              text: 'Failed to get completions',
            },
          ],
          isError: true,
        };
      }
  • src/index.ts:325-358 (registration)
    The tool registration object returned in the listTools response, defining the name, description, and input schema for 'get_completions'.
    {
      name: 'get_completions',
      description: 'Get completion suggestions 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 completion position'
          },
          character: { 
            type: 'number',
            description: 'Zero-based character offset for completion 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:398-400 (registration)
    The dispatch case in the callTool request handler that routes 'get_completions' calls to the handleGetCompletions method.
    case 'get_completions':
      result = await this.handleGetCompletions(args);
      break;
  • The input schema defining the parameters expected by the 'get_completions' tool.
    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 completion position'
        },
        character: { 
          type: 'number',
          description: 'Zero-based character offset for completion 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'],
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but provides minimal information. It mentions getting 'completion suggestions' but doesn't describe what format these suggestions come in, whether there are rate limits, authentication requirements, or any side effects. The description doesn't contradict annotations (since none exist), but it fails to provide the behavioral context needed for a tool with 6 required parameters.

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 gets straight to the point with zero wasted words. It's appropriately sized for the tool's complexity and front-loads the core purpose immediately. Every word earns its place in communicating the essential function.

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?

For a tool with 6 required parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what kind of completions are returned, in what format, or any behavioral characteristics. The agent would need to guess about the tool's behavior and output based solely on the parameter schema, which is inadequate for a tool of this complexity.

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?

The description mentions 'for a position in a document' which hints at the line/character parameters, but provides no additional semantic context beyond what's already in the schema (which has 100% coverage). The schema descriptions already clearly explain each parameter's purpose, so the description adds minimal value. This meets the baseline of 3 for high schema coverage.

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 'completion suggestions' with the context 'for a position in a document', making the purpose immediately understandable. It distinguishes from sibling tools like get_diagnostics and get_hover by focusing specifically on completion suggestions rather than diagnostics or hover information. However, it doesn't specify what type of completions (e.g., code completions, text completions) or from what source.

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?

The description provides no guidance on when to use this tool versus alternatives. There are no explicit instructions about when this tool is appropriate, what prerequisites might be needed, or how it differs from other completion-related tools that might exist. The agent must infer usage purely from the tool name and parameter schema.

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