Mastergo Magic Mcp

by mastergo-design

268 stars
1k downloads
Not rated
GitHub Website

About

A standalone MCP service that connects MasterGo design tools with AI models, enabling them to retrieve DSL data directly from design files.

Details

Author
mastergo-design
GitHub stars
268
Downloads
1,010
Categories
Developer Tools, Design, Other, AI

- Retrieves DSL data from MasterGo design files
- Runs directly with npx, no external dependencies
- Supports multiple output formats: json, yaml, tree
- Works with short links for design files
- Supports HTTP/HTTPS proxy and custom headers
- Debug mode for detailed error information

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Mastergo Magic Mcp
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Run the service directly with npx @mastergo/magic-mcp --token=YOUR_TOKEN. You can also configure it via environment variables or install it through the Smithery marketplace. The server integrates with MCP clients such as Claude Desktop, Cursor, Cline, Open Code, and LINGMA. Obtain a MasterGo personal access token from your account Security Settings (Team Edition or higher required). Design files must be placed in Team Projects, not the draft box.

version_0_2_8

the current version is 0.2.8

mcp__getDesignSections

BEFORE calling this tool, CHECK the layerId: - If layerId has NO colon and no digits (e.g. "M", or any short non-numeric id), it is likely a PAGE-level id, NOT a layer id. Page-level ids return EMPTY from this tool (they cannot be enumerated via /container). → STOP. Call mcp__getPageLayers with the same fileId+layerId first to enumerate the real layer_ids, then restore each one individually. - Only proceed with THIS tool when layerId looks like a real layer id (contains a colon and digits, e.g. "802:02364", "453:6855"). This check is MANDATORY when the user's URL contains ?page_id= (not ?layer_id=). If you ignore this and call this tool with a page-level id, the server will return an error redirecting you to mcp__getPageLayers anyway — so save the round-trip and call getPageLayers first. [PRIMARY] This is the main tool for all designs. Operates in TWO modes: Mode 1 — Get layout overview (sectionIndex NOT provided): Returns the list of all sections with id, name, type, nodeCount, textPreview (first TEXT node, 20 chars max), and a page-absolute bounding box (x, y, width, height) for each section, plus totalSections and totalNodes. Also returns rootMetadata (root layer width/height/name/type/fill) when available. rootContainer CSS properties for the page wrapper. splitContainers for large page regions that were split into child sections. Use this FIRST to understand the design scope. The per-section bbox tells you exactly where each section sits inside the root container — use it for absolute positioning when generating code. Example: { "fileId": "123", "layerId": "456:789" } Mode 2 — Get section DSL (sectionIndex provided): Returns the full DSL for ONE specific section. - PATH nodes carry a `svgShortKey` field (a short sequential ID like `S0#0`, `S0#1`). The SVG markup is NOT in the DSL. Place `@@SVG:{svgShortKey}@@` where each icon goes, then call `mcp__applyDesign` at the end to inject the real high-precision SVG. NEVER hand-write `<path d="...">`. - CRITICAL: After generating the complete code with all `@@SVG:{svgShortKey}@@` placeholders, call `mcp__applyDesign` to replace them with real SVG. Skipping this WILL cause missing icons. - INSTANCE nodes with a `_variantProps` object carry semantic state labels. Compare these across sibling instances to determine active/selected/hovered states — do NOT default to the first item. CRITICAL — sectionIndex is SINGULAR: the parameter is sectionIndex (a SINGLE integer per call). There is NO plural sectionIndices parameter — passing an array will be rejected with an error. To fetch multiple sections you MUST make multiple calls, each with one sectionIndex. IMPORTANT workflow: 1. First call WITHOUT sectionIndex to get the section list with node counts. 2. Then call WITH sectionIndex=0, then sectionIndex=1, ... up to totalSections-1 — ONE sectionIndex per call. 3. YOU MUST REQUEST ALL SECTIONS. Do NOT skip any section index — missing sections WILL cause missing content. 4. textPreview helps distinguish same-looking sections: "系统信息", "权限设置", "基本设置" — all may have nodeCount=3 and empty name but DIFFERENT textPreview. They are individual menu items, NOT duplicates. 5. Fetch sections in batches of 3-5 CONCURRENT calls (3-5 separate single-sectionIndex calls in parallel), wait for all results, then send the next batch. Each call has exactly one sectionIndex. 6. After fetching all sections, generate code with `@@SVG:{svgShortKey}@@` placeholders for every PATH node, then call `mcp__applyDesign` to inject real SVG. 7. Count your requests. If totalSections=48, you must make exactly 48 sectionIndex calls (each with a SINGLE integer). Keep a checklist and do NOT stop early. 8. Generate the complete HTML with all SVG placeholders, then call `mcp__applyDesign` as the FINAL step. DO NOT call mcp__getDsl after completing this workflow — all data is already provided. If this tool returns an error (e.g. old server), fall back to mcp__getDsl. You can provide either: 1. fileId and layerId d…

mcp__getPageLayers

List ALL layers under a given page (or any container layer) of a MasterGo design file. This is the ENUMERATION step of the multi-layer restoration workflow — it only lists layer_ids; it does NOT restore designs. **Workflow (enumerate → build URLs → restore one by one):** 1. Call this tool with the page_id / parent layerId to get the full layer list. 2. Pick the top-level restorable layers from the result (FRAME/COMPONENT/INSTANCE at depth 0/1). For each, build a URL: https://mastergo.com/file/{fileId}?layer_id={id} (URL-encode the id, e.g. 802:02364 → 802%3A02364). 3. Restore them SEQUENTIALLY — take one layer_id, run the full single-layer restoration (mcp__getDesignSections → fetch all sections → mcp__applyDesign), write its HTML to its OWN separate .html file (a complete standalone document with <!DOCTYPE html>/<head>/<body>), THEN move to the next. Do NOT batch-restore. Do NOT merge multiple layers into one HTML file — ONE layer = ONE standalone .html file. You can provide either: 1. fileId and layerId directly (layerId = the page's layerId, i.e. page_id), or 2. a short link (like https://{domain}/goto/LhGgBAK) The returned layer list is lightweight: each entry has id, name, type, depth, parentId, childrenCount, width, height. It does NOT contain DSL/styles/SVG paths — use the section or DSL tools to restore each layer. NOTE: This tool cannot enumerate a document's PAGE list from a fileId alone — you must already know a page_id / layerId to pass in. The synthetic page_id=M returns empty (page data not available via this API); use a real layer_id URL in that case.

mcp__getDsl

[FALLBACK] Use only when mcp__getDesignSections is unavailable or returns an error. This returns the FULL DSL in one response — may be large and exceed context limits for complex designs. Prefer mcp__getDesignSections as the primary tool for all designs. You can provide either: 1. fileId and layerId directly, or 2. a short link (like https://{domain}/goto/LhGgBAK) This tool returns the raw DSL data that you can then parse and analyze. Use the optional 'format' parameter (json/yaml/tree, defaults to json) to control the serialization. This tool also returns the rules you must follow when generating code. The DSL data can also be used to transform and generate code for different frameworks.

mcp__getD2c

使用此工具从 MasterGo 获取 D2C 数据,并在本地落盘: 1)将返回的 code 写入 html; 2)将返回的 svg / image 资源按 resourcePath 落盘到对应目录; 3)返回落盘摘要,避免把大体积资源塞进上下文。

mcp__C2d

使用此工具将代码文件发送到 MasterGo MCP 服务进行 C2D(代码转设计)处理,将用户代码同步到设计稿。 参数说明: - filePath:HTML 文件的完整路径(如 /path/to/file.html),工具会自动读取文件内容并发送给后端。 - fileId: 不提供 shortLink 时至少需要 fileId。layerId 不是必填,没有就不要传。 - layerId: 可选。图层 ID(只读取 URL 参数 layer_id)。不传或解析不到则仅按 file 维度同步;pageid/page_id 不会被当作 layerId。 - shortLink:可选,短链接形式(例如 https://{domain}/goto/xxxx)。 注意事项:只允许使用 URL 中的 layer_id 参数作为 layerId,严禁将 pageid/page_id 等任何页面 ID 当作 layerId。 如果短链接或 URL 中没有解析出 layer_id,则不传 layerId。 工具会读取 filePath 指定文件的内容,并传给后端,附带 fileId 与可选的 layerId。

mcp__getComponentLink

When the data returned by mcp__getDsl contains a non-empty componentDocumentLinks array, this tool is used to sequentially retrieve URLs from the componentDocumentLinks array and then obtain component documentation data. The returned document data is used for you to generate frontend code based on components.

mcp__getMeta

Use this tool when the user intends to build a complete website or needs to obtain high-level site configuration information. You must provide a fileld and layerld to identify the specific design element. This tool returns the rules and results of the site and page. The rules is a markdown file, you must follow the rules and use the results to analyze the site and page.

mcp__getComponentGenerator

Users need to actively call this tool to get the component development workflow. When Generator is mentioned, please actively call this tool. This tool provides a structured workflow for component development following best practices. You must provide an absolute rootPath of workspace to save workflow files.

mcp__getFlutterGenerator

Users need to actively call this tool to get the Flutter component development workflow. When Flutter Generator or Flutter Component is mentioned, please actively call this tool. This tool provides a structured workflow for Flutter component development following best practices. It includes MasterGo DSL to Flutter Widget mapping rules, screen adaptation with flutter_screenutil, and feature-based architecture guidance. It also downloads all image resources from the design file to local disk, rewrites CSS and DSL references to point at Flutter asset paths, and generates an asset manifest. You must provide an absolute rootPath of workspace to save workflow files.

mcp__extractSvg

Extract SVG data from MasterGo design files. This tool retrieves the DSL from a design layer, finds all PATH nodes (typically inside INSTANCE/icon components), resolves their color references, and generates SVG markup strings. You can provide either: 1. fileId and layerId directly, or 2. a short link (like https://{domain}/goto/LhGgBAK) Pagination: When there are many icons, use the first call without "page" to get totalCount. Then call again with page=0, page=1, etc. (page starts at 0, pageSize defaults to 20, max 100). If hasMore is false, you've fetched all pages.

mcp__applyDesign

Finalize generated design code: replace ALL placeholders (SVG icons + long text) with real high-precision data from the design cache, then write the final file directly to disk. WHAT it does: 1. Replaces every `@@SVG:{svgShortKey}@@` placeholder with the real high-precision `<svg>` markup from the SVG cache (character-for-character exact, no rounding). 2. Replaces every `T{sectionIndex}|{nodeId}` text placeholder with the real long text from the text cache. 3. Detects fabricated (hand-written) `<path d="...">` that were NOT injected via placeholders — reports them as errors. 4. Writes the finalized code directly to `{outDir}/{outputFileName}` on disk. CRITICAL — outDir is MANDATORY: Always provide outDir so the finalized code is written directly to disk. This ensures the server-injected data reaches the file WITHOUT any LLM re-processing. Do NOT copy the code back into your response and re-output it — that causes precision loss. The file written by this tool IS the final deliverable. PLACEHOLDER FORMATS: - SVG icons: `@@SVG:{svgShortKey}@@` — svgShortKey comes from the PATH node's svgShortKey field in the section DSL. Example: <span class="icon">@@SVG:S0#0@@</span> - Long text: `T{sectionIndex}|{nodeId}` — appears in TEXT nodes whose text was too long for inline DSL. Example: <p>T3|1:1234:5678</p> The server escapes the injected data according to the `targetLang` parameter: - `html` (default, also for Vue templates): place the placeholder in element content (`<span>@@SVG:S0#0@@</span>`, `<p>T3|1:2</p>`). SVG is inserted as-is; long text is HTML-escaped (& < >). - `dart` (Flutter): place the placeholder inside a single-quoted string literal (`SvgPicture.string('@@SVG:S0#0@@')`, `Text('T3|1:2')`). SVG/text are escaped for that string (\ ' newline). Pass `targetLang: "dart"`. Pick targetLang to match the code you generated, and place placeholders in that language's standard position shown above. You can provide either: 1. fileId and layerId directly, or 2. a short link (like https://{domain}/goto/LhGgBAK) IMPORTANT: Call this tool with the COMPLETE code string. After the tool writes the file, you are DONE — do NOT output or edit the code further.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mastergo magic mcp": {
            "mastergo-magic-mcp": {
                "command": "npx",
                "args": [
                    "-y",
                    "@mastergo/magic-mcp",
                    "--token=your_token",
                    "--url=https://mastergo.com/"
                ],
                "env": {
                    "NPM_CONFIG_REGISTRY": "https://registry.npmjs.org/"
                }
            }
        }
    }
}

McpServers

{
    "mastergo-magic-mcp": {
        "command": "npx",
        "args": [
            "-y",
            "@mastergo/magic-mcp",
            "--token=your_token",
            "--url=https://mastergo.com/"
        ],
        "env": {
            "NPM_CONFIG_REGISTRY": "https://registry.npmjs.org/"
        }
    }
}

MasterGo Magic MCP

Ask DeepWiki

MasterGo Magic MCP is a standalone MCP (Model Context Protocol) service designed to connect MasterGo design tools with AI models. It enables AI models to directly retrieve DSL data from MasterGo design files.

Key Features

- Retrieves DSL data from MasterGo design files
- Runs directly with npx
- No external dependencies required, only Node.js environment needed

Tutorial

- https://mastergo.com/file/192644601973042

Example Prompts

Once the MCP server is connected, you can use the following prompts in your AI chat:

Extract SVG and preview in HTML:

Extract SVG and preview in HTML: https://{domain}/file/{fileId}?layer_id={layerId}

Restore a design to code:

Restore design: https://{domain}/file/{fileId}?layer_id={layerId}

Replace {domain}, {fileId}, and {layerId} with your actual values. You can also use short links:

Restore design: https://{domain}/goto/{shortLink}

Restore a design and save as an HTML file:

Restore design, save as HTML file: https://{domain}/file/{fileId}?layer_id={layerId}

You can also use short links:

Restore design, save as HTML file: https://{domain}/goto/{shortLink}

Usage

Obtaining MG_MCP_TOKEN

1. Visit https://mastergo.com
2. Enter personal settings
3. Click the Security Settings tab
4. Find the personal access token
5. Click to generate the token

Permission Requirements

Important: If the tool is connected but returns a "no permission" error, please check the following conditions:

1. Account Version Requirement:
- Requires Team Edition or higher MasterGo account
- Personal free edition does not support MCP tool access

2. File Location Requirement:
- Design files must be placed in Team Projects
- Files in draft box cannot be accessed via MCP tools

Command Line Options

npx @mastergo/magic-mcp --token=YOUR_TOKEN [--url=API_URL] [--rule=RULE_NAME] [--proxy=PROXY_URL] [--format=FORMAT] [--header "Key: Value"] [--debug] [--no-rule]

Parameters:

- --token=YOUR_TOKEN (required): MasterGo API token for authentication
- --url=API_URL (optional): API base URL, defaults to http://localhost:3000
- --rule=RULE_NAME (optional): Add design rules to apply, can be used multiple times
- --proxy=PROXY_URL (optional): HTTP/HTTPS proxy URL (e.g., http://127.0.0.1:7890), also supports HTTPS_PROXY / HTTP_PROXY environment variables
- --header "Key: Value" (optional): Custom HTTP request header, can be used multiple times. Quote the value when it contains spaces. Custom headers override the defaults — including Content-Type and the auth token — so match the default key exactly when overriding. Also settable via the MG_EXTRA_HEADERS environment variable as a JSON object (e.g. MG_EXTRA_HEADERS='{"X-Custom":"val"}'); CLI headers take precedence over env.
- --format=FORMAT (optional): Default output format for design-data tools — one of json (default), yaml, tree. An explicit per-call format tool parameter overrides this. Also settable via the DEFAULT_FORMAT environment variable.
- --debug (optional): Enable debug mode for detailed error information
- --no-rule (optional): Disable default rules

You can also use space-separated format for parameters:

npx @mastergo/magic-mcp --token YOUR_TOKEN --url API_URL --rule RULE_NAME --proxy PROXY_URL --format FORMAT --header "Key: Value" --debug

Environment Variables

Alternatively, you can use environment variables instead of command line arguments:

- MG_MCP_TOKEN or MASTERGO_API_TOKEN: MasterGo API token
- API_BASE_URL: API base URL
- RULES: JSON array of rules (e.g., '["rule1", "rule2"]')
- DEFAULT_FORMAT: Default output format for design-data tools (json | yaml | tree); the --format argument and an explicit per-call format tool parameter take precedence.
- HTTPS_PROXY / https_proxy / HTTP_PROXY / http_proxy: HTTP(S) proxy URL (the --proxy argument takes priority)

Tool Output Format

The design-data tools (mcp__getDesignSections, mcp__getDsl, mcp__getDesignSvgs, mcp__getDesignTexts, mcp__extractSvg, mcp__getMeta) accept an optional format parameter that controls how the payload is serialized. It defaults to json, or to the value set via --format / DEFAULT_FORMAT (see Command Line Options).

| Value | Description |
| --- | --- |
| json | Default. Compact JSON — useful when piping output into tools that expect JSON. Byte-identical to the prior behavior. |
| yaml | Fewer tokens than JSON for typical designs (flat layouts with repeated values benefit most). |
| tree | Experimental compact format. Structural keys (id, name, type) are encoded positionally on each node line, and style values stay deduplicated in a globalVars block. Designs with heavy style reuse see the largest token savings. |

The format is chosen per tool call by the AI model. To influence it, mention the desired format in your prompt, for example:

Restore design, use tree format: https://{domain}/file/{fileId}?layer_id={layerId}

Notes:

- tree applies to all six tools' responses: mcp__getDesignSections (section list and per-section DSL), mcp__getDsl, mcp__getDesignSvgs, mcp__getDesignTexts, mcp__extractSvg, and mcp__getMeta. mcp__getMeta falls back to JSON under tree because its rules field is markdown (the tree layout would corrupt the markdown's headings/code blocks); other payloads render as tree. Truly unknown shapes also fall back to JSON — no data is ever mis-formatted.
- For mcp__getDesignTexts, json is recommended for maximum verbatim-text fidelity — though all formats round-trip without data loss.
- All formats round-trip without data loss. An invalid or omitted format value falls back to json.

Installing via Smithery Marketplace

Smithery is an MCP server marketplace that makes it easy to install and manage MCP services.

Method 1: Install via Smithery Website

1. Visit Smithery Marketplace
2. Click the "Connect" or "Install" button
3. Select your MCP client (e.g., Claude Desktop, Cursor, etc.)
4. Follow the prompts to complete installation and configuration

LINGMA Usage

Search for LINGMA in the VSCode extension marketplace and install it.

image-20250507174245589

After logging in, click on [MCP tools] in the chat box.

image-20250507174511910

Click on [MCP Square] at the top to enter the MCP marketplace, find the MasterGo design collaboration tool and install it.

image-20250507174840456

After installation, go back to [MCP Servers], and edit our MCP service to replace it with your own MasterGo token.

image-20250507175005364

Finally, switch the chat mode to agent mode in the chat interface.

image-20250507175107044

cursor Usage

Cursor Mcp usage guide reference: https://docs.cursor.com/context/model-context-protocol#using-mcp-tools-in-agent

You can configure the MCP server using either command line arguments or environment variables:

Option 1: Using command line arguments

{
  "mcpServers": {
    "mastergo-magic-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@mastergo/magic-mcp",
        "--token=<YOUR_TOKEN>",
        "--url=https://mastergo.com"
      ],
      "env": {}
    }
  }
}

Option 2: Using environment variables

{
  "mcpServers": {
    "mastergo-magic-mcp": {
      "command": "npx",
      "args": ["-y", "@mastergo/magic-mcp"],
      "env": {
        "MG_MCP_TOKEN": "<YOUR_TOKEN>",
        "API_BASE_URL": "https://mastergo.com"
      }
    }
  }
}

Option 3: Using SSE (Streamable HTTP)

No local installation required. The MCP server runs remotely and is accessed via SSE:

{
  "mcpServers": {
    "mastergo-magic-mcp": {
      "type": "http",
      "url": "https://mastergo.com/mcp/xf/sse",
      "headers": {
        "x-mg-useraccesstoken": "<YOUR_TOKEN>"
      }
    }
  }
}

cline Usage

Option 1: Using command line arguments

{
  "mcpServers": {
    "@master/mastergo-magic-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@mastergo/magic-mcp",
        "--token=<YOUR_TOKEN>",
        "--url=https://mastergo.com"
      ],
      "env": {}
    }
  }
}

Option 2: Using environment variables

{
  "mcpServers": {
    "@master/mastergo-magic-mcp": {
      "command": "npx",
      "args": ["-y", "@mastergo/magic-mcp"],
      "env": {
        "MG_MCP_TOKEN": "<YOUR_TOKEN>",
        "API_BASE_URL": "https://mastergo.com"
      }
    }
  }
}

Open Code Usage

Open Code uses a mcp configuration block with type: "local" and command array:

{
  "mcp": {
    "mastergo-magic-mcp": {
      "type": "local",
      "command": [
        "npx",
        "-y",
        "@mastergo/magic-mcp",
        "--token=<YOUR_TOKEN>",
        "--url=https://mastergo.com"
      ],
      "environment": {
        "NPM_CONFIG_REGISTRY": "https://registry.npmjs.org/"
      },
      "enabled": true
    }
  }
}

Project Structure

src Directory

The src directory contains the core implementation of the MasterGo Magic MCP service:

- index.ts: Entry point of the application that initializes the MCP server and registers all tools
- http-util.ts: Utility for handling HTTP requests to the MasterGo API
- types.d.ts: TypeScript type definitions for the project

src/tools

Contains implementations of MCP tools:

- base-tool.ts: Base class for all MCP tools
- get-dsl.ts: Tool for retrieving DSL (Domain Specific Language) data from MasterGo design files
- get-component-link.ts: Tool for retrieving component documentation from links
- get-meta.ts: Tool for retrieving metadata information
- get-component-workflow.ts: Tool providing structured component development workflow for Vue and React components, generating workflow files and component specifications

src/markdown

Contains markdown files with additional documentation:

- meta.md: Documentation about metadata structure and usage
- component-workflow.md: Component development workflow documentation guiding structured component development process

Local Development

1. Run yarn and yarn build to install dependencies and build the code
2. Find the absolute path of dist/index.js
3. Add local MCP configuration with your token

"mastergo-mcp-local": {
  "command": "node",
  "args": [
    "absolute/path/to/dist/index.js",
    "--token=mg_xxxxxx",
    "--url=https://mastergo.com",
    "--debug"
  ],
  "env": {}
},

4. Restart your editor to ensure the local MCP is enabled

After successful execution, you can debug based on the local running results. You can build your own MCP service based on your modifications.

We welcome your code contributions and look forward to building MasterGo's MCP service together.

License

ISC

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.