MCP cover image
See in Github
2025-04-14

Carte source de paser

1

Github Watches

0

Github Forks

2

Github Stars

Source Map Parser

🌐 语言: English | 简体中文

Source-Map-Parser-MCP image

This project implements a WebAssembly-based Source Map parser that can map JavaScript error stack traces back to source code and extract relevant context information. Developers can easily map JavaScript error stack traces back to source code for quick problem identification and resolution. This documentation aims to help developers better understand and use this tool.

MCP Integration

Note: Requires Node.js 18+ support

Option 1: Run directly with NPX

npx -y source-map-parser-mcp@latest

Option 2: Download the build artifacts

Download the corresponding version of the build artifacts from the GitHub Release page, then run:

node dist/main.es.js

Runtime Parameter Configuration

System runtime parameters can be flexibly configured through environment variables to meet the needs of different scenarios

  • SOURCE_MAP_PARSER_RESOURCE_CACHE_MAX_SIZE: Sets the maximum memory space occupied by resource cache, default is 200MB. Adjusting this value appropriately can balance performance and memory usage.
  • SOURCE_MAP_PARSER_CONTEXT_OFFSET_LINE: Defines the number of context code lines to display around the error location, default is 1 line. Increasing this value provides more context information, facilitating problem diagnosis.

Example:

# Set 500MB cache and display 3 lines of context
export SOURCE_MAP_PARSER_RESOURCE_CACHE_MAX_SIZE=500
export SOURCE_MAP_PARSER_CONTEXT_OFFSET_LINE=3
npx -y source-map-parser-mcp@latest

Feature Overview

  1. Stack Parsing: Parse the corresponding source code location based on provided line number, column number, and Source Map file.
  2. Batch Processing: Support parsing multiple stack traces simultaneously and return batch results.
  3. Context Extraction: Extract context code for a specified number of lines to help developers better understand the environment where errors occur.

MCP Service Tool Description

operating_guide

Get usage instructions for the MCP service. Provides information on how to use the MCP service through chat interaction.

parse_stack

Parse stack information by providing stack traces and Source Map addresses.

Request Example

  • stacks: Stack information including line number, column number, and Source Map address.
    • line: Line number, required.
    • column: Column number, required.
    • sourceMapUrl: Source Map address, required.
{
  "stacks": [
    {
      "line": 10,
      "column": 5,
      "sourceMapUrl": "https://example.com/source.map"
    }
  ]
}

Response Example

{
  "content": [
    {
      "type": "text",
      "text": "[{\"success\":true,\"token\":{\"line\":10,\"column\":5,\"sourceCode\":[{\"line\":8,\"isStackLine\":false,\"raw\":\"function foo() {\"},{\"line\":9,\"isStackLine\":false,\"raw\":\"  console.log('bar');\"},{\"line\":10,\"isStackLine\":true,\"raw\":\"  throw new Error('test');\"},{\"line\":11,\"isStackLine\":false,\"raw\":\"}\"}],\"src\":\"index.js\"}}]"
    }
  ]
}

Parsing Result Description

  • success: Indicates whether the parsing was successful.
  • token: The Token object returned when parsing is successful, containing source code line number, column number, context code, and other information.
  • error: Error information returned when parsing fails.

Advanced Usage

Some teams, for security or performance reasons, may not want to expose Source Maps directly to browsers for parsing, and instead process the Source Map upload paths. For example, converting path /assets/index.js to source_backup/index.js.map.

In such cases, prompt rules can guide the model to complete path conversion.

Prompt Example

**Source Map Tool Usage Guide**

The following are the parsing rules for Source Map remote addresses, where `origin_url` represents the error address in the stack.

1. Replace the resource address of the Source Map based on the source path in the stack:
   `https://example.com${origin_url.replace('/assets/', '/source_backup/')}.map`

2. If all rules fail to match, use the following fallback rule:
   `${origin_url}.map` and try again.

FAQ

1. WebAssembly Module Loading Failure

If the tool returns the following error message, please troubleshoot as follows:

parser init error: WebAssembly.instantiate(): invalid value type 'externref', enable with --experimental-wasm-reftypes @+86

  1. Check Node.js Version: Ensure Node.js version is 18 or higher. If it's lower than 18, please upgrade Node.js.
  2. Enable Experimental Flag: If Node.js version is 18+ but you still encounter issues, use the following command to start the tool:
    npx --node-arg=--experimental-wasm-reftypes -y source-map-parser-mcp@latest
    

Local Development Guide

1. Install Dependencies

Ensure Node.js and npm are installed, then run the following command to install project dependencies:

npm install

2. Link MCP Service

Run the following command to start the MCP server:

npx tsx src/main.ts

Internal Logic Overview

1. Main File Description

  • stack_parser_js_sdk.js: JavaScript wrapper for the WebAssembly module, providing core stack parsing functionality.
  • parser.ts: Main implementation of the parser, responsible for initializing the WebAssembly module, retrieving Source Map content, and parsing stack information.
  • server.ts: Implementation of the MCP server, providing the parse_stack tool interface for external calls.

2. Modify Parsing Logic

To modify the parsing logic, edit the getSourceToken method in the parser.ts file.

3. Add New Tools

In the server.ts file, new tool interfaces can be added using the server.tool method.

Notes

  1. Source Map Files: Ensure that the provided Source Map file address is accessible and the file format is correct.
  2. Error Handling: During parsing, network errors, file format errors, and other issues may be encountered; it's recommended to implement proper error handling when making calls.

Contribution Guidelines

Contributions via Issues and Pull Requests are welcome to improve this project.

License

This project is licensed under the MIT License. See the LICENSE file for details.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • apappascs
  • Découvrez la collection la plus complète et la plus à jour de serveurs MCP sur le marché. Ce référentiel sert de centre centralisé, offrant un vaste catalogue de serveurs MCP open-source et propriétaires, avec des fonctionnalités, des liens de documentation et des contributeurs.

  • modelcontextprotocol
  • Serveurs de protocole de contexte modèle

  • Mintplex-Labs
  • L'application tout-en-un desktop et Docker AI avec chiffon intégré, agents AI, constructeur d'agent sans code, compatibilité MCP, etc.

  • ShrimpingIt
  • Manipulation basée sur Micropython I2C de l'exposition GPIO de la série MCP, dérivée d'Adafruit_MCP230XX

  • n8n-io
  • Plateforme d'automatisation de workflow à code équitable avec des capacités d'IA natives. Combinez le bâtiment visuel avec du code personnalisé, de l'auto-hôte ou du cloud, 400+ intégrations.

  • open-webui
  • Interface AI conviviale (prend en charge Olllama, Openai API, ...)

  • WangRongsheng
  • 🧑‍🚀 全世界最好的 LLM 资料总结 (数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Résumé des meilleures ressources LLM du monde.

    Reviews

    1 (1)
    Avatar
    user_zS2cCsqk
    2025-04-15

    As a loyal user of the MCP Go SDK by riza-io, I highly recommend it for its seamless integration and robust functionality. It greatly simplifies development tasks and enhances productivity. The documentation is comprehensive, making it easy to get started and utilize advanced features. Overall, an excellent tool for any Go developer. Check it out: https://mcp.so/server/mcp-go/riza-io