Skip to main content
POST
/
tools
/
get_definition
Get Definition
curl --request POST \
  --url https://api.example.com/tools/get_definition
{
  "locations": [
    {
      "uri": "<string>",
      "range": {
        "start": {},
        "end": {}
      }
    }
  ]
}

Overview

Find where a Python symbol (function, class, variable, etc.) is defined. This provides the “Go to Definition” functionality that lets you navigate to the source code of any symbol.

Request

uri
string
required
File URI (e.g., file:///workspace/main.py)
line
number
required
Line number (0-indexed)
character
number
required
Character position (0-indexed)

Response

locations
array
Array of definition locations (usually just one)

Example Request

curl -X POST https://api.pylancemcp.dev/v1/tools/call \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "get_definition",
    "arguments": {
      "uri": "file:///workspace/app/views.py",
      "line": 42,
      "character": 15
    }
  }'

Example Response

{
  "locations": [
    {
      "uri": "file:///workspace/app/models.py",
      "range": {
        "start": { "line": 15, "character": 6 },
        "end": { "line": 15, "character": 10 }
      }
    }
  ]
}

Use Cases

# In views.py, line 42:
result = calculate_total(items)
#        ^^^^^^^^^^^^^^
# Get definition → Goes to utils.py where calculate_total is defined

# Result:
# file:///workspace/app/utils.py, line 8
# def calculate_total(items: List[Item]) -> float:

Find Class Definition

# In views.py:
user = User(name="John", email="john@example.com")
#      ^^^^
# Get definition → Goes to models.py

# Result:
# file:///workspace/app/models.py, line 25
# class User(BaseModel):

Jump to Import Source

# In views.py:
from app.utils import calculate_total
#                     ^^^^^^^^^^^^^^
# Get definition → Goes to utils.py

# Result:
# file:///workspace/app/utils.py, line 8

Find Variable Declaration

# In functions.py:
total = calculate_total(items)
# ... many lines later ...
print(total)  # Where was total defined?
#     ^^^^^
# Get definition → Goes back to where total was assigned

Multiple Definitions

Some symbols may have multiple definitions (e.g., overloaded functions, re-exports):
{
  "locations": [
    {
      "uri": "file:///workspace/app/models.py",
      "range": { "start": { "line": 15, "character": 6 }, "end": { "line": 15, "character": 10 } }
    },
    {
      "uri": "file:///workspace/app/__init__.py",
      "range": { "start": { "line": 3, "character": 0 }, "end": { "line": 3, "character": 23 } }
    }
  ]
}
When multiple definitions exist, the first one is typically the primary definition.

Definition Types

Symbol TypeWhat You Get
FunctionThe def statement where function is defined
ClassThe class statement where class is defined
VariableThe line where variable is first assigned
ImportThe source file of the imported module/symbol
MethodThe method definition inside the class
PropertyThe @property decorated method

Performance Tips

Cache Definition Locations: Store frequently accessed definitions to reduce lookups
Batch Requests: If checking multiple symbols, batch them in one request
Workspace Indexing: Initial workspace load may take time; subsequent lookups are fast

Error Responses

CodeReasonSolution
FILE_NOT_FOUNDFile doesn’t existVerify file path
INVALID_POSITIONPosition out of boundsCheck line/character values
NO_DEFINITION_FOUNDNo symbol at positionMove cursor to a valid symbol
EXTERNAL_DEFINITIONSymbol defined in external libraryNot available for external packages
WORKSPACE_NOT_LOADEDWorkspace still indexingWait and retry

Rate Limits

TierRequests/HourRequests/Day
Free20100
Hobby5005,000
Pro5,00050,000
EnterpriseUnlimitedUnlimited