read_code
Reads a specific symbol from a file with full context: imports, definition, and optional callers.
DESCRIPTION
This is the precise code reader. It is AST-aware, so it can isolate the exact function or class you care about without dumping the entire file into context.
WHEN TO USE
GOOD FIT
- Before modifying a function or class.
- When you need to understand a symbol without reading a large file.
- When you want to inspect call sites before changing a signature.
AVOID IT WHEN
- You need a whole-file skim; read the file directly.
- You need text search across many files; use find_code.
- You still do not know which files matter; use scope_task first.
PARAMETERS
| Name | Type | Required | Description |
|---|---|---|---|
| file | string | Yes | Path to the file to inspect. |
| symbol | string | No | Function, class, or type name to extract. |
| include_callers | boolean | No | Whether to include call sites. Defaults to true. |
EXAMPLE
tools-call.json
{ "jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": { "name": "read_code", "arguments": { "file": "src/lib/auth.ts", "symbol": "validateApiKey", "include_callers": true } }}OUTPUT
response.json
{ "jsonrpc": "2.0", "id": 5, "result": { "content": [ { "type": "text", "text": "Definition: validateApiKey(apiKey: string)\nImports: crypto, Supabase client\nBehavior: hashes candidate key, checks revocation, expiry, and user tier\nCallers: src/app/api/mcp/route.ts, src/lib/tool-preferences.ts" } ] }}TOKEN EFFICIENCY
By returning only the symbol and its callers, this tool avoids spending context on unrelated code in the same file.