Skip to main content
Glama

get_completions

Generate code completion suggestions for Python at specific positions to improve editing accuracy and semantic understanding during development.

Instructions

Get code completion suggestions at position (1-based).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
lineYes
columnYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The get_completions handler, which is registered as an MCP tool and calls the LSP client to fetch completions.
    async def get_completions(file_path: str, line: int, column: int) -> str:
        """Get code completion suggestions at position (1-based)."""
        client = _get_client()
    
        path = Path(file_path).resolve()
        if not path.exists():
            return _error(f"File not found: {file_path}")
    
        try:
            await client.open_document(path)
            completions = await client.get_completions(path, line - 1, column - 1)
    
            if not completions:
                return _not_found(f"No completions at {path.name}:{line}:{column}")
    
            kind_names = {
                1: "text", 2: "method", 3: "function", 4: "constructor",
                5: "field", 6: "variable", 7: "class", 8: "interface",
                9: "module", 10: "property", 11: "unit", 12: "value",
                13: "enum", 14: "keyword", 15: "snippet", 16: "color",
                17: "file", 18: "reference", 19: "folder", 20: "enum_member",
                21: "constant", 22: "struct", 23: "event", 24: "operator",
                25: "type_parameter"
            }
    
            items = []
            for item in completions[:30]:
                label = item.get("label", "?")
                kind = kind_names.get(item.get("kind", 0), "unknown")
                detail = item.get("detail", "")
                items.append({
                    "label": label,
                    "kind": kind,
                    "detail": detail or None
                })
    
            return _ok({
                "count": len(completions),
                "shown": len(items),
                "completions": items
            })
        except Exception as e:
            return _error(str(e))
  • The underlying LSP client method that sends the 'textDocument/completion' request to the ty language server.
    async def get_completions(
        self, file_path: str | Path, line: int, character: int
    ) -> list[dict[str, Any]]:
        """Get completion items at position."""
        file_path = Path(file_path).resolve()
        uri = file_path.as_uri()
    
        result = await self._send_request("textDocument/completion", {
            "textDocument": {"uri": uri},
            "position": {"line": line, "character": character}
        })
    
        if not result:
            return []
    
        # Result can be CompletionItem[] | CompletionList
        if isinstance(result, list):
            return result
        elif isinstance(result, dict) and "items" in result:
            return result["items"]
    
        return []
Behavior3/5

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

With no annotations provided, the description carries full behavioral disclosure burden. It successfully specifies the 1-based indexing system (critical for correct invocation), but omits other behavioral traits like return format, caching behavior, or side effects.

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

Conciseness4/5

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

Extremely concise with zero wasted words. However, given the lack of annotations and schema descriptions, this brevity becomes a limitation rather than a virtue, as critical context is omitted for the sake of terseness.

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

Completeness3/5

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

Provides the minimum viable context for correct invocation (the 1-based coordinate specification), which prevents off-by-one errors. However, it lacks usage guidance and does not compensate adequately for zero schema annotation coverage across three required parameters.

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 0%, requiring the description to compensate. It partially does so by clarifying that line/column form a 'position' and specifying 1-based indexing, but fails to describe file_path semantics or provide detailed constraints for the parameters.

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?

States a specific action (Get code completion suggestions) and scope (at position). The inclusion of '1-based' distinguishes coordinate expectations. However, it does not explicitly differentiate from similar siblings like get_code_actions or get_definition.

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?

Provides no guidance on when to use this tool versus alternatives like get_code_actions or get_type_info, nor does it mention prerequisites such as the file needing to exist in the project.

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/qinsehm1128/mcp-ty'

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