Get Definition
curl --request POST \
--url https://api.example.com/tools/get_definitionimport requests
url = "https://api.example.com/tools/get_definition"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/tools/get_definition', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/tools/get_definition",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/tools/get_definition"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/tools/get_definition")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/tools/get_definition")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body{
"locations": [
{
"uri": "<string>",
"range": {
"start": {},
"end": {}
}
}
]
}API Reference
Get Definition
Jump to where a symbol is defined
POST
/
tools
/
get_definition
Get Definition
curl --request POST \
--url https://api.example.com/tools/get_definitionimport requests
url = "https://api.example.com/tools/get_definition"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/tools/get_definition', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/tools/get_definition",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/tools/get_definition"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/tools/get_definition")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/tools/get_definition")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body{
"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
string
required
File URI (e.g.,
file:///workspace/main.py)number
required
Line number (0-indexed)
number
required
Character position (0-indexed)
Response
array
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
}
}'
from pylance_mcp import Client
client = Client(api_key="YOUR_API_KEY")
definitions = client.get_definition(
uri="file:///workspace/app/views.py",
line=42,
character=15
)
for location in definitions.locations:
print(f"Defined at: {location.uri}")
print(f"Line: {location.range.start.line}")
import { PylanceMCP } from '@pylance-mcp/client';
const client = new PylanceMCP({ apiKey: 'YOUR_API_KEY' });
const definitions = await client.getDefinition({
uri: 'file:///workspace/app/views.py',
line: 42,
character: 15
});
definitions.locations.forEach(location => {
console.log(`Defined at: ${location.uri}`);
console.log(`Line: ${location.range.start.line}`);
});
import { PylanceMCP, DefinitionRequest } from '@pylance-mcp/client';
const client = new PylanceMCP({ apiKey: process.env.PYLANCE_API_KEY! });
const request: DefinitionRequest = {
uri: 'file:///workspace/app/views.py',
line: 42,
character: 15
};
const definitions = await client.getDefinition(request);
for (const location of definitions.locations) {
console.log(`Defined at: ${location.uri}`);
console.log(`Line: ${location.range.start.line}`);
}
Example Response
{
"locations": [
{
"uri": "file:///workspace/app/models.py",
"range": {
"start": { "line": 15, "character": 6 },
"end": { "line": 15, "character": 10 }
}
}
]
}
Use Cases
Navigate to Function Definition
# 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 Type | What You Get |
|---|---|
| Function | The def statement where function is defined |
| Class | The class statement where class is defined |
| Variable | The line where variable is first assigned |
| Import | The source file of the imported module/symbol |
| Method | The method definition inside the class |
| Property | The @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
| Code | Reason | Solution |
|---|---|---|
FILE_NOT_FOUND | File doesn’t exist | Verify file path |
INVALID_POSITION | Position out of bounds | Check line/character values |
NO_DEFINITION_FOUND | No symbol at position | Move cursor to a valid symbol |
EXTERNAL_DEFINITION | Symbol defined in external library | Not available for external packages |
WORKSPACE_NOT_LOADED | Workspace still indexing | Wait and retry |
Rate Limits
| Tier | Requests/Hour | Requests/Day |
|---|---|---|
| Free | 20 | 100 |
| Hobby | 500 | 5,000 |
| Pro | 5,000 | 50,000 |
| Enterprise | Unlimited | Unlimited |
Related Tools
Get References
Find all places where a symbol is used
Get Hover
See documentation without jumping
Get Type Definition
Go to type definition instead of value
Rename Symbol
Rename symbol across entire project
Was this page helpful?
⌘I