跳到正文
Skillpedia
网站与界面(前端)6.2k · #14398

mcp-artifact-integration

它能做什么

这项技能说明如何构建一个通过 MCP 调用 Lightdash 并显示查询结果的网页产物。适合想要展示实时 Lightdash 数据的自定义页面或应用的开发者。

适用场景

  • ✓当你想构建一个展示 Lightdash 查询结果的网页时。
  • ✓当你需要在产物中处理 Lightdash 查询的加载、错误和空数据状态时。
  • ✓当你想退回使用 Lightdash 查询的 CSV 数据的时候。

技能链接

https://github.com/lightdash/lightdash/blob/main/packages/backend/src/ee/services/ai/skills/builtInSkills/mcp-artifact-integration/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/lightdash/lightdash/blob/main/packages/backend/src/ee/services/ai/skills/builtInSkills/mcp-artifact-integration/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请构建一个 HTML 产物,以表格形式显示这个 Lightdash 指标查询的结果,并包含加载和错误状态。”

每周 5 个新技能,1 分钟读完。

工作原理

这项技能说明如何发起查询、保存其 ID 并轮询结果。它还说明如何读取响应,包括结构化内容和任何错误标记,以及如何正确显示每种状态。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Lightdash query results in HTML/React artifacts

Use this skill when creating an HTML/React artifact or app that calls Lightdash through Model Context Protocol (MCP). It describes the existing data contract; it does not add a new endpoint, SDK or browser bridge.

Choose and start the query

Choose run_metric_query for questions expressible in the semantic layer. Discover field IDs with grep_fields / get_metadata, and supply required parameters explicitly: omitted parameters may silently use defaults. Use run_sql for other read-only SELECT queries in the warehouse's dialect. Read each tool's schema for its effective row limit; deployment configuration can change the maximum.

Call the query-start tool once. Keep its query UUID and original project/agent scope for subsequent polling. The artifact should track its own loading, success, empty and error states; a pending query is not an empty dataset.

Read the result envelope

A full MCP CallToolResult can contain:

  • content: an array of typed content blocks. Query tools put CSV or status/error text in the first text block. Additional blocks can contain an applied-parameters note, queryUuid: <id>, [Scope: ...] or a compatibility warning.
  • structuredContent.result: the typed result, when exposed by the host. Prefer this over parsing CSV.
  • isError: a tool failure flag. Check it, but also inspect structuredContent.result.status: terminal query statuses can arrive without isError.
  • _meta: host/app metadata. Do not assume your artifact bridge exposes it.

Do not concatenate every content block into CSV. Do not parse an entire CallToolResult as row data. When the host exposes text only, follow the status text and parse only the data block with a real CSV parser (quoted delimiters, quotes and line breaks are legal). If the bridge discards necessary status or UUID information, show an integration error rather than guessing.

The companion result contracts gives the exact completed/running/terminal shapes and link semantics. Native MCP clients can read the resource; fallback clients can call read_skill_resource with name: "mcp-artifact-integration" and path: "resources/result-contracts.md".

Poll without re-executing

  1. Start the query once with run_sql or run_metric_query.
  2. Check isError first. For structured results, branch on result.status.
  3. running: retain the returned queryUuid, show "Query still running…", wait nextPollAfterMs, then call get_query_result with that same UUID and scope. Text-only clients use the UUID and wait instructions in the returned text. Never invent an ID or restart the original query to check progress.
  4. done: stop polling and render the data. An empty rows array is successful completion with zero rows, not a parsing failure.
  5. error, cancelled or expired: stop polling and display the returned error/status. These can be normal MCP results without isError: true.

Both the initial query-start call and each polling call can wait up to approximately 50 seconds server-side. Allow for that in the host bridge's timeout. This is not the warehouse execution timeout; warehouse timeouts come from the Lightdash connection. heartbeatAt records the latest Lightdash check that confirmed the query was still running, not a warehouse progress percentage.

If a polling call loses its connection or times out, retry only get_query_result with the same UUID, using bounded retries/backoff. Avoid overlapping polls; stop on terminal state, artifact teardown or user cancellation. Stopping local polling does not cancel warehouse execution. Ignore stale responses if the user starts a different query while an earlier call is in flight.

If the initial query-start call loses its response before you receive a UUID, do not automatically resubmit: the warehouse may already be executing it. Report that the outcome is unknown; a retry can duplicate execution.

Validation failures should be corrected before another query is started. Application/warehouse errors are terminal until corrected; do not put them into the transient polling retry loop.

Build your artifact's own visualization

Use completed query rows as data for your HTML table or React chart library. For metric results, rows use stable field IDs and fields provides metadata; CSV headers instead use display labels. Keep stable IDs for data access, use labels for presentation, and do not treat labels as un

常见问题

它会添加新的端点吗?

不会。技能描述的是现有的数据约定,不添加任何端点或 SDK。

我应该使用哪个查询工具?

对于语义层能回答的问题,使用指标查询工具;其他只读查询则使用 SQL 工具。

普通聊天也需要这个吗?

不需要。描述中说明,普通聊天或 Lightdash 内置的图表应用不需要它。

详情

作者的原始描述

Integrate Lightdash MCP query results into Claude-created HTML or React artifacts. Covers host bridges, response envelopes, polling, errors, CSV fallback and chart data. Not needed for ordinary chat or Lightdash's built-in chart app.

repo: lightdash/lightdash

热度

GitHub 星标
6.2k
排名
#14398
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能