lookup_context
Map compiled JavaScript code positions to original source code context using source maps, helping developers locate and fix issues by providing surrounding code lines.
Instructions
Lookup Source Code Context
This tool looks up original source code context for a specific line and column position in compiled/minified code.
Parameters:
line: The line number in the compiled code (1-based)
column: The column number in the compiled code
sourceMapUrl: The URL of the source map file
contextLines (optional): Number of context lines to include before and after the target line (default: 5)
Returns:
A JSON object containing the source code context snippet with file path, target line info, and surrounding context lines
Returns null if the position cannot be mapped
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| line | Yes | The line number in the compiled code (1-based) | |
| column | Yes | The column number in the compiled code | |
| sourceMapUrl | Yes | The URL of the source map file | |
| contextLines | No | Number of context lines to include (default: 5) |
Implementation Reference
- src/tools.ts:294-304 (handler)MCP tool handler for 'lookup_context'. Awaits parser instance, invokes parser.lookupContext with parameters, and returns JSON-formatted result as text content.handler: async ({ line, column, sourceMapUrl, contextLines }, getParser) => { const parser = await getParser(); const result = await parser.lookupContext(line, column, sourceMapUrl, contextLines); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], } }
- src/tools.ts:280-293 (schema)Zod input schema for 'lookup_context' tool parameters: line (number), column (number), sourceMapUrl (string), contextLines (optional number, default 5).schema: { line: z.number({ description: "The line number in the compiled code (1-based)", }), column: z.number({ description: "The column number in the compiled code", }), sourceMapUrl: z.string({ description: "The URL of the source map file", }), contextLines: z.number({ description: "Number of context lines to include (default: 5)", }).optional().default(5), },
- src/tools.ts:263-305 (registration)Declarative tool definition object for 'lookup_context' in toolDefinitions array, used by registerTools to conditionally register the tool with the MCP server via server.tool().{ name: "lookup_context", description: ` # Lookup Source Code Context This tool looks up original source code context for a specific line and column position in compiled/minified code. ## Parameters: - **line**: The line number in the compiled code (1-based) - **column**: The column number in the compiled code - **sourceMapUrl**: The URL of the source map file - **contextLines** (optional): Number of context lines to include before and after the target line (default: 5) ## Returns: - A JSON object containing the source code context snippet with file path, target line info, and surrounding context lines - Returns null if the position cannot be mapped `, schema: { line: z.number({ description: "The line number in the compiled code (1-based)", }), column: z.number({ description: "The column number in the compiled code", }), sourceMapUrl: z.string({ description: "The URL of the source map file", }), contextLines: z.number({ description: "Number of context lines to include (default: 5)", }).optional().default(5), }, handler: async ({ line, column, sourceMapUrl, contextLines }, getParser) => { const parser = await getParser(); const result = await parser.lookupContext(line, column, sourceMapUrl, contextLines); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], } } },
- src/parser.ts:393-408 (helper)Core helper method in Parser class: lookupContext. Validates URL, fetches source map content, initializes parser, calls external sourceMapParser.lookup_context WASM function, and returns the source context result. Invoked by the tool handler.public async lookupContext(line: number, column: number, sourceMapUrl: string, contextLines: number = 5) { validateUrl(sourceMapUrl); await this.init(); try { const sourceMapContent = await this.fetchSourceMapContent(sourceMapUrl); // Use the high-level lookup_context function directly const result = sourceMapParser.lookup_context(sourceMapContent, line, column, contextLines); return result; } catch (error) { throw new Error("lookup context error: " + (error instanceof Error ? error.message : error), { cause: error, }); } }