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
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| line | Yes | ||
| column | Yes |
Implementation Reference
- src/mcp_ty/server.py:346-374 (handler)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))