Validate

io.github.machinegrade由 GitHub 帳號 machinegrade 發布v0.1.2更新於 Nov 2, 2026

Deterministic validation for AI-generated artifacts: JSON Schema, OpenAPI response, SQL syntax.

已驗證Streamable HTTP可網頁執行開發者工具資料與分析

概覽

AI 產生的概覽

驗證 AI 產生的產物——依 JSON Schema 驗證 JSON、驗證 OpenAPI 回應內容、檢查 SQL 語法——並回傳確定性的通過/失敗結論。

可以做什麼
  • 依 JSON Schema 驗證 JSON 產物並彙整所有錯誤
  • 依 OpenAPI 規格中指定路徑、方法與狀態碼的回應 schema 驗證回應內容
  • 依指定方言檢查 SQL 字串的語法錯誤
  • 回傳包含是否有效、錯誤清單與耗時的結論,以及剩餘呼叫次數
適用情境
當助理產生 JSON、API 回應或 SQL,並希望在據此行動或交付前做一次便宜、確定性的檢查,而不是呼叫完整的 LLM 評審時適用。
執行需求
可使用託管的遠端端點,或透過 stdio 執行本機 npm 套件 @machinegrade/validate。呼叫工具需要 API 金鑰,透過 SANDBOX_API_KEY 或 X-Api-Key 標頭提供;免費金鑰需以電子郵件向服務的金鑰端點申請。本機使用時以 SANDBOX_URL 指定 API 基礎位址。需要能連線至該服務的網路。
安裝前請注意
呼叫工具需要與電子郵件綁定的 API 金鑰;免費額度為每月 500 次、每分鐘 60 次,超過每月上限會回傳需要付費的錯誤。超出免費額度後的按次付費方案仍在規劃中。產物與契約會傳送到第三方託管服務,請勿傳送金鑰或敏感資料。服務處於早期階段,可能停止營運,但承諾公告後金鑰仍可使用 90 天。

安裝

在 SourceWeft 中

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

Web executable,透過 Streamable HTTP。 遠端服務在工作區中設定後即可從網頁執行環境執行。

交給代理程式安裝

把這段提示詞貼上到 Claude Code、Codex、Cursor 等代理程式,或 SourceWeft 對話中。代理程式會讀取該伺服器的安裝指南,先向你展示發布者、端點和登入方式,經你同意後再把它新增到你的客戶端。金鑰不會寫進任何命令。

閱讀 https://sourceweft.com/mcp/io.github.machinegrade%2Fvalidate/install.md,並按其中說明把這個 MCP 伺服器接入我的客戶端。修改任何設定之前,先告訴我它的發布者、端點和登入方式,等我確認。不要把 API 金鑰寫進命令或我會提交的檔案;問我金鑰應從哪裡取得。

檢視代理程式所依據的安裝指南

其他 MCP 客戶端

把它新增到你客戶端的 mcpServers 設定中。

{
  "mcpServers": {
    "validate": {
      "type": "http",
      "url": "https://api.machinegrade.dev/mcp"
    }
  }
}

README

machinegrade validate

Validate AI-generated artifacts against a contract before you act on them:

  • json_schema — validate artifact against a JSON Schema (all errors collected).
  • openapi_response — validate a response body against the response schema for a given path + method + status in an OpenAPI spec.
  • sql — check a SQL string for syntax errors in a given dialect.

Every check returns a verdict, not an error: {valid, errors, latency_ms}, HTTP 200 whether the artifact is valid or not. Only genuinely wrong requests (bad key, unsupported type, malformed body, over your limit) get typed HTTP errors.

Live at https://api.machinegrade.dev — free tier, self-service key, try it in 30 seconds (first example below). Built on Hono; the same codebase runs on Cloudflare Workers (production) and plain Node (local dev), and is MIT-licensed if you'd rather self-host.

Why

Agents that generate JSON, API responses, or SQL need a fast, cheap, machine-checkable pass/fail before they ship the result — cheaper than a full LLM-as-judge call, and deterministic.

Run it locally

bash
npm installnpm run dev# machinegrade validate listening on http://localhost:8787

3 runnable examples

1. curl

bash
# Get an API key (live service — works as-is)curl -s -X POST https://api.machinegrade.dev/keys \  -H 'content-type: application/json' \  -d '{"email": "[email protected]"}'# => {"key":"sk_..."}
# Validate a JSON artifact against a JSON Schemacurl -s -X POST https://api.machinegrade.dev/v1/validate \  -H 'content-type: application/json' \  -H 'X-Api-Key: sk_...' \  -d '{    "type": "json_schema",    "artifact": {"name": "Ada", "age": 30},    "contract": {      "schema": {        "type": "object",        "required": ["name", "age"],        "properties": {"name": {"type": "string"}, "age": {"type": "number"}}      }    }  }'# => {"valid":true,"errors":[],"latency_ms":1}

2. Python (requests)

python
import requests
base = "http://localhost:8787"
key = requests.post(f"{base}/keys", json={"email": "[email protected]"}).json()["key"]
resp = requests.post(    f"{base}/v1/validate",    headers={"X-Api-Key": key},    json={        "type": "sql",        "artifact": "SELECT id, name FROM users WHERE id = 1",        "contract": {"dialect": "mysql"},    },)print(resp.status_code, resp.headers.get("X-Calls-Remaining"), resp.json())

3. MCP config snippet

mcp/server.ts exposes a single tool, validate, that forwards to POST /v1/validate. Point an MCP-compatible client at it:

json
{  "mcpServers": {    "machinegrade-validate": {      "command": "npx",      "args": ["tsx", "mcp/server.ts"],      "cwd": "/path/to/validate",      "env": {        "SANDBOX_URL": "http://localhost:8787",        "SANDBOX_API_KEY": "sk_..."      }    }  }}

Connect remotely

The production service also exposes an MCP endpoint directly — no local process, no npm install — via streamable HTTP at:

POST https://api.machinegrade.dev/mcp

It's the same single validate tool as the stdio adapter above. initialize and tools/list work without a key (discovery is anonymous); tools/call requires X-Api-Key (issue one via POST /keys, same as the REST API — the free tier and limits are shared).

With Claude Code:

bash
claude mcp add --transport http validate https://api.machinegrade.dev/mcp --header "X-Api-Key: sk_..."

The stdio adapter via npm (@machinegrade/validate, see above) remains available for local/offline use or clients without HTTP transport support.

Claude Desktop: one-click install

Download the latest .mcpb bundle from Releases and double-click it. Claude Desktop asks for an API key during install and stores it in the OS keychain (macOS Keychain, Windows Credential Manager) rather than in a config file — nothing lands in claude_desktop_config.json.

Issue a free key (500 calls/month) first:

bash
curl -s -X POST https://api.machinegrade.dev/keys \  -H 'content-type: application/json' \  -d '{"email": "[email protected]"}'

The bundle is a thin stdio client over the hosted API: ~34 KB, zero bundled dependencies. If you self-host, point the extension's API base URL setting at your own deployment and the tool talks to that instead.

API

See public/openapi.yaml for the full contract, or /v1/manifest for a machine-readable summary (types, limits, pricing, error codes) once the service is running. /llms.txt is a short pointer for LLM agents.

EndpointInOut
POST /keys{email}{key}
POST /v1/validateheader X-Api-Key, body {type, artifact, contract?}verdict, header X-Calls-Remaining
GET /v1/manifest—capability manifest
GET /statsheader X-Admin-Tokenfunnel: keys_issued, active_callers, repeat_callers_7d, limit_hits, paid_requests
POST /v1/paid-requestheader X-Api-Keyrecords interest in paid access
GET /openapi.yaml, GET /llms.txt—static docs
POST /mcpMCP streamable HTTP, header X-Api-Key for tools/callsee "Connect remotely" above

Pricing

  • Free tier: 500 calls/month per key, 60 calls/minute rate limit.
  • Paid tier: EUR 0.002/call beyond the free tier — opens soon. Request paid access via POST /v1/paid-request (requires X-Api-Key); you'll be notified when it's live.

Errors

Every error is typed JSON — {code, message, hint, docs_url} — never a free-form string:

CodeHTTP statusWhen
INVALID_KEY401X-Api-Key missing or unknown
LIMIT_EXCEEDED402Free-tier monthly limit (500 calls) exceeded
UNSUPPORTED_TYPE400type is not json_schema, openapi_response, or sql
MALFORMED_INPUT400Request body doesn't match the documented shape
RATE_LIMITED429More than 60 calls/minute for a key

A verdict ({valid, errors, latency_ms}) is never an error — an invalid artifact is a normal, expected outcome and returns HTTP 200.

Sending the artifact

artifact must be a JSON value, not a JSON-encoded string:

jsonc
{"type": "json_schema", "artifact": {"name": "Ada"}, "contract": {"schema": {"type": "object"}}}   // correct{"type": "json_schema", "artifact": "{\"name\": \"Ada\"}", "contract": {"schema": {"type": "object"}}}  // wrong

For type: "sql" the artifact is a string — the statement itself.

Because MCP callers stringify values often enough (and did so through Claude Desktop until the tool schema declared artifact's types), the service tolerates the wrong form narrowly: if artifact is a string, the type is json_schema or openapi_response, and the contract's top-level schema declares types that exclude string, the string is JSON-decoded before validation and the verdict carries "decoded_from_string": true. The field is additive; {valid, errors, latency_ms} is unchanged.

It deliberately does not decode otherwise, because a string artifact is often legitimate:

SentContract schemaResult
"42"{"type": "number"}decoded to 42, valid: true, decoded_from_string: true
"42"{"type": "string"}left alone, valid: true
"{\"a\":1}"{"type": "string"}left alone, valid: true
"{\"a\":1}"{"required": ["a"]}left alone — no top-level type, intent unknown

Storage

src/storage.ts defines a Storage interface with two implementations:

  • MemoryStorage — full in-memory implementation, used for npm run dev and the test suite.
  • D1Storage — real Cloudflare D1 binding, backed by schema.sql (keys, events tables). Used in production; the Workers entry point in src/index.ts builds it from the DB binding on first request.

Apply schema.sql to a new D1 database with:

bash
wrangler d1 execute machinegrade-validate-db --file=schema.sql          # localwrangler d1 execute machinegrade-validate-db --file=schema.sql --remote # production

Testing

bash
npm test          # vitest run, in-process via app.request(), MemoryStoragenpm run typecheck # tsc --noEmit

Tests cover: key issuance, happy + fail cases for each validator, typed 401/400/402/429 errors, the metering limits (both injectable in tests so they don't require looping hundreds of real requests), and /stats funnel counts.

Deploy

The service runs on Cloudflare Workers (Hono + D1 + Workers Static Assets). To self-host on a fresh Cloudflare account:

bash
wrangler d1 create machinegrade-validate-db   # copy the returned database_id into wrangler.tomlwrangler d1 execute machinegrade-validate-db --file=schema.sql --remotewrangler secret put ADMIN_TOKENwrangler deploy

Then bind a custom domain (e.g. api.machinegrade.dev) to the Worker via the Cloudflare dashboard or wrangler. CI can deploy on push to main once CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID repo secrets are set and the deploy job in .github/workflows/ci.yml is uncommented.

Two things worth knowing about the Workers port:

  • GET /openapi.yaml and GET /llms.txt are served by the ASSETS binding ([assets] in wrangler.toml, pointing at public/) — Cloudflare serves them directly, without invoking the Worker. The routes in src/index.ts are a fallback for local Node dev/tests, where there's no ASSETS binding.
  • The json_schema and openapi_response validators use @cfworker/json-schema, not ajv: ajv compiles schemas via new Function(...), which the Workers runtime disallows, and schemas here arrive dynamically per request (from the caller), so they can't be precompiled at build time either.

Status

Early stage, honestly so: this service is live and free-tier usage is real, and we're measuring whether it earns a paid tier. What you can rely on:

  • The API contract (/v1/validate request/response shapes, typed error codes, verdict semantics) is stable — breaking changes only with a versioned path (/v2/...), never silently.
  • The free tier (500 calls/month) stays.
  • If we ever sunset the service, keys keep working for 90 days after the announcement, and the validators are open source in this repo — you can self-host the same behavior.

Feedback and integration stories are the most valuable thing you can give us right now: open an issue or use POST /v1/paid-request if you need more than the free tier.

來源:README.md,提交 5dbe141

工具

1

validate

Validate an artifact against a contract (json_schema | openapi_response | sql) via the machinegrade validate API.

輸入參數type必填artifact必填contract

版本歷史

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

評分

已滿足適用檢查項的 100%

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

  • 近 30 天內可連通必需25 分
  • 已宣告認證方式必需10 分
  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分