Skip to main content
Glama

unpack_sources

Extract original source files and their content from a source map to map JavaScript error stack traces back to original code for debugging.

Instructions

Unpack Source Map Sources

This tool extracts all source files and their content from a source map.

Parameters:

  • sourceMapUrl: The URL of the source map file to unpack

Returns:

  • A JSON object containing:

    • sources: Object with source file paths as keys and their content as values

    • sourceRoot: The source root path from the source map

    • file: The original file name

    • totalSources: Total number of source files found

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceMapUrlYesThe URL of the source map file to unpack

Implementation Reference

  • MCP tool handler function for 'unpack_sources'. Awaits the parser instance and calls its unpackSources method, then returns the result as formatted JSON text content.
    handler: async ({ sourceMapUrl }, getParser) => { const parser = await getParser(); const result = await parser.unpackSources(sourceMapUrl); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], } }
  • Zod input schema for the 'unpack_sources' tool, validating the required sourceMapUrl parameter.
    schema: { sourceMapUrl: z.string({ description: "The URL of the source map file to unpack", }), },
  • src/tools.ts:348-354 (registration)
    Registration loop in registerTools function that calls server.tool() for 'unpack_sources' (and other tools) if it passes the filter check.
    toolDefinitions.forEach(tool => { if (shouldRegisterTool(tool.name, options.toolFilter)) { server.tool(tool.name, tool.description, tool.schema, async (params) => { return tool.handler(params, getParser); }); } });
  • Core helper method in Parser class that fetches and parses the source map JSON to extract all source file paths and contents (from sourcesContent if present, else null), returning structured result.
    public async unpackSources(sourceMapUrl: string) { validateUrl(sourceMapUrl); try { const sourceMapContent = await this.fetchSourceMapContent(sourceMapUrl); const sourceMap = JSON.parse(sourceMapContent); if (!sourceMap.sources || !Array.isArray(sourceMap.sources)) { throw new Error("Invalid source map: missing or invalid sources array"); } const result: Record<string, string | null> = {}; // Extract sources from sourcesContent if available if (sourceMap.sourcesContent && Array.isArray(sourceMap.sourcesContent)) { sourceMap.sources.forEach((source: string, index: number) => { result[source] = sourceMap.sourcesContent[index] || null; }); } else { // If no sourcesContent, list sources with null content sourceMap.sources.forEach((source: string) => { result[source] = null; }); } return { sources: result, sourceRoot: sourceMap.sourceRoot || null, file: sourceMap.file || null, totalSources: sourceMap.sources.length }; } catch (error) { throw new Error("unpack sources error: " + (error instanceof Error ? error.message : error), { cause: error, }); } }

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/MasonChow/source-map-parser-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server