Skip to main content
Glama

get_definition

Navigate to symbol definitions in Python code using precise line and column positions for accurate code analysis and editing.

Instructions

Go to definition of symbol at position (1-based).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
lineYes
columnYes

Implementation Reference

  • The 'get_definition' tool implementation in 'src/mcp_ty/server.py' which handles the request, converts 1-based line/column to 0-based for the underlying client, and formats the output.
    @mcp.tool()
    async def get_definition(file_path: str, line: int, column: int) -> str:
        """Go to definition of symbol 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)
            locations = await client.get_definition(path, line - 1, column - 1)
    
            if not locations:
                return _not_found(f"No definition at {path.name}:{line}:{column}")
    
            defs = []
            for loc in locations:
                def_path = _uri_to_path(loc.uri)
                defs.append({
                    "file": def_path.name,
                    "path": str(def_path),
                    "line": loc.range.start.line + 1,
                    "column": loc.range.start.character + 1
                })
    
            return _ok({"definitions": defs})
        except Exception as e:
            return _error(str(e))

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