Skip to main content
Glama

find_usages

Locate all references to a Python symbol at a specific position in your codebase to understand usage patterns and dependencies.

Instructions

Find all references to symbol at position (1-based).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
lineYes
columnYes

Implementation Reference

  • The handler function for the 'find_usages' MCP tool, which finds references using the language server client.
    async def find_usages(file_path: str, line: int, column: int) -> str:
        """Find all references to 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.find_references(path, line - 1, column - 1)
    
            if not locations:
                return _not_found(f"No references at {path.name}:{line}:{column}")
    
            refs = []
            for loc in locations:
                ref_path = _uri_to_path(loc.uri)
                refs.append({
                    "file": ref_path.name,
                    "path": str(ref_path),
                    "line": loc.range.start.line + 1,
                    "column": loc.range.start.character + 1
                })
    
            files = list(set(r["file"] for r in refs))
            return _ok({"count": len(refs), "files_count": len(files), "references": refs})
        except Exception as e:
            return _error(str(e))
  • The registration decorator for the 'find_usages' tool.
    @mcp.tool()
    async def find_usages(file_path: str, line: int, column: int) -> str:

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