Guidance Lark Mcp

io.github.guidance-ai由 GitHub 帳號 guidance-ai 發布v0.1.2更新於 Oct 24, 2026

Validate and test llguidance grammars with batch testing and documentation

已驗證STDIO僅桌面開發者工具AI 與機器學習

概覽

AI 產生的概覽

本機 MCP 伺服器,用來驗證與批次測試 llguidance 的 Lark 文法,並提供語法文件與可選的文法約束生成。

可以做什麼
  • 用 llguidance 內建驗證器檢查 Lark 文法是否完整、一致
  • 依 JSON 測試檔對文法執行批次驗證測試,回傳通過/失敗統計與失敗詳情
  • 從官方儲存庫取得 llguidance 文法語法文件
  • 可選:以受文法約束的 OpenAI 相容模型生成文字,讓輸出符合文法
適用情境
適合與 AI 助理一起反覆建構或除錯 llguidance Lark 文法,例如把語言規格中的規則改寫成 Lark,並用範例輸入反覆測試直到全部通過。
執行需求
以 Python 套件透過 stdio 在本機執行,可用 uvx 或 pip 安裝。文法驗證、批次測試與文件功能不需任何憑證。可選的生成工具需要 ENABLE_GENERATION=true 以及 OPENAI_API_KEY,或 Azure OpenAI 的 AZURE_OPENAI_ENDPOINT、AZURE_OPENAI_API_KEY 等設定,或搭配 azure 擴充套件使用 az login。取得文件與呼叫模型後端需要網路存取。
安裝前請注意
可選的生成工具會把提示送到第三方模型後端,並依設定的金鑰產生 API 費用。OPENAI_API_KEY、AZURE_OPENAI_API_KEY 等憑證需寫入用戶端設定的 env 中。批次測試會讀取你提供的本機 JSON 測試檔路徑。伺服器本身不寫入資料,但生成內容由外部服務商產生。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Guidance Lark Mcp,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

MCP Grammar Tools

MCP server for validating and testing llguidance grammars (Lark format). Provides grammar validation, batch test execution, and syntax documentation — ideal for iteratively building grammars with AI coding assistants.

Installation

With uvx (recommended)

bash
uvx guidance-lark-mcp

With pip

bash
pip install guidance-lark-mcp

From source

bash
cd mcp-grammar-toolspip install -e .

MCP Client Configuration

GitHub Copilot CLI

You can add the server using the interactive /mcp add command or by editing the config file directly. See the Copilot CLI MCP documentation for full details.

Option 1: Interactive setup

In the Copilot CLI, run /mcp add, select Local/STDIO, and enter uvx guidance-lark-mcp as the command.

Option 2: Edit config file

Add the following to ~/.copilot/mcp-config.json:

json
{  "mcpServers": {    "grammar-tools": {      "type": "local",      "command": "uvx",      "args": ["guidance-lark-mcp"],      "tools": ["*"]    }  }}

This gives you grammar validation and batch testing out of the box. To also enable LLM-powered generation (generate_with_grammar), add ENABLE_GENERATION and your credentials to env:

json
"env": {  "ENABLE_GENERATION": "true",  "OPENAI_API_KEY": "your-key-here"}

For Azure OpenAI (with Entra ID via az login), use guidance-lark-mcp[azure] and set the endpoint instead:

json
"args": ["guidance-lark-mcp[azure]"],"env": {  "ENABLE_GENERATION": "true",  "AZURE_OPENAI_ENDPOINT": "https://your-resource.openai.azure.com/",  "OPENAI_MODEL": "your-deployment-name"}

See Backend Configuration for all supported backends.

After saving, use /mcp show to verify the server is connected.

VS Code

json
{  "mcpServers": {    "grammar-tools": {      "type": "local",      "command": "uvx",      "args": ["guidance-lark-mcp"],      "env": {        "ENABLE_GENERATION": "true",        "OPENAI_API_KEY": "your-key-here"      },      "tools": ["*"]    }  }}

Claude Desktop

json
{  "mcpServers": {    "grammar-tools": {      "command": "uvx",      "args": ["guidance-lark-mcp"],      "env": {        "ENABLE_GENERATION": "true",        "OPENAI_API_KEY": "your-key-here"      }    }  }}

Usage

Available Tools

  1. validate_grammar — Validate grammar completeness and consistency using llguidance's built-in validator.

    json
    {"grammar": "start: \"hello\" \"world\""}
  2. run_batch_validation_tests — Run batch validation tests from a JSON file against a grammar. Returns pass/fail statistics and detailed failure info.

    json
    {  "grammar": "start: /[0-9]+/",  "test_file": "tests.json"}

    Test file format:

    json
    [  {"input": "123", "should_parse": true, "description": "Valid number"},  {"input": "abc", "should_parse": false, "description": "Not a number"}]
  3. get_llguidance_documentation — Fetch the llguidance grammar syntax documentation from the official repo.

  4. generate_with_grammar (optional, requires ENABLE_GENERATION=true) — Generate text using an OpenAI model constrained by a grammar. Uses the Responses API with custom tool grammar format, so output is guaranteed to conform to the grammar. Requires OPENAI_API_KEY environment variable. See Backend Configuration for Azure and other endpoints.

Backend Configuration

The generate_with_grammar tool uses the OpenAI Python SDK, which natively supports multiple backends via environment variables:

BackendRequired env varsOptional env vars
OpenAI (default)OPENAI_API_KEYOPENAI_MODEL
Azure OpenAI (API key)AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_KEYAZURE_OPENAI_API_VERSION, OPENAI_MODEL
Azure OpenAI (Entra ID)AZURE_OPENAI_ENDPOINT + az loginAZURE_OPENAI_API_VERSION, OPENAI_MODEL
Custom endpointOPENAI_API_KEY, OPENAI_BASE_URLOPENAI_MODEL

The server auto-detects which backend to use:

  • If AZURE_OPENAI_ENDPOINT is set → uses AzureOpenAI client (with Entra ID or API key)
  • Otherwise → uses OpenAI client (reads OPENAI_API_KEY and OPENAI_BASE_URL automatically)

The server logs which backend it detects on startup.

Example: Azure OpenAI (API key)

json
{  "mcpServers": {    "grammar-tools": {      "type": "local",      "command": "uvx",      "args": ["guidance-lark-mcp"],      "env": {        "ENABLE_GENERATION": "true",        "AZURE_OPENAI_ENDPOINT": "https://my-resource.openai.azure.com",        "AZURE_OPENAI_API_KEY": "your-azure-key",        "OPENAI_MODEL": "gpt-4.1"      },      "tools": ["*"]    }  }}

Example: Azure OpenAI (Entra ID / keyless)

Requires az login and the azure extra: pip install guidance-lark-mcp[azure]

json
{  "mcpServers": {    "grammar-tools": {      "type": "local",      "command": "uvx",      "args": ["guidance-lark-mcp[azure]"],      "env": {        "ENABLE_GENERATION": "true",        "AZURE_OPENAI_ENDPOINT": "https://my-resource.openai.azure.com",        "OPENAI_MODEL": "gpt-4.1"      },      "tools": ["*"]    }  }}

Example Workflow

Build a grammar iteratively with an AI assistant:

  1. Start with the spec — paste EBNF rules from a language specification
  2. Write a basic grammar — translate a few rules to Lark format
  3. Validate — use validate_grammar to check for missing rules
  4. Write tests — create a JSON test file with sample inputs
  5. Batch test — use run_batch_validation_tests to find failures
  6. Fix & repeat — refine the grammar until all tests pass

Example Grammars

The examples/ directory includes sample grammars built using these tools, with Lark grammar files, test suites, and documentation:

  • GraphQL — executable subset of the GraphQL spec (queries, mutations, fragments, variables)

Troubleshooting

Server fails to connect in Copilot CLI / VS Code?

MCP clients like Copilot CLI only show "Connection closed" when a server crashes on startup. To see the actual error, run the server directly in your terminal:

bash
uvx guidance-lark-mcp

Or with generation enabled:

bash
ENABLE_GENERATION=true OPENAI_API_KEY=your-key uvx guidance-lark-mcp

Common issues:

  • Missing credentials — ENABLE_GENERATION=true without a valid OPENAI_API_KEY or AZURE_OPENAI_ENDPOINT. The server will still start and serve validation tools; generate_with_grammar will return a descriptive error.
  • Azure Entra ID — make sure you've run az login and are using guidance-lark-mcp[azure] (not the base package).
  • Slow first start — uvx needs to resolve and install dependencies on first run, which may exceed the MCP client's connection timeout. Run uvx guidance-lark-mcp once manually to warm the cache.
  • Updating to a new version — uvx caches packages, so after a new release you may need to clear the cache and restart your MCP client:
    bash
    uv cache clean guidance-lark-mcp

Development

bash
git clone https://github.com/guidance-ai/guidance-lark-mcpcd guidance-lark-mcpuv syncuv run pytest tests/ -q

來源:README.md,提交 65f1350

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.2最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分