validate
Validate an artifact against a contract (json_schema | openapi_response | sql) via the machinegrade validate API.
type必填artifact必填contract
io.github.machinegrade由 GitHub 账号 machinegrade 发布v0.1.2更新于 Nov 2, 2026
Deterministic validation for AI-generated artifacts: JSON Schema, OpenAPI response, SQL syntax.
校验 AI 生成的产物——按 JSON Schema 校验 JSON、校验 OpenAPI 响应体、检查 SQL 语法——并返回确定性的通过/失败结论。
Web executable,通过 Streamable HTTP。 远程服务在工作区中配置后即可从网页运行时运行。
把这段提示词粘贴到 Claude Code、Codex、Cursor 等智能体,或 SourceWeft 对话中。智能体会读取该服务器的安装指南,先向你展示发布者、端点和登录方式,经你同意后再把它添加到你的客户端。密钥不会写进任何命令。
阅读 https://sourceweft.com/mcp/io.github.machinegrade%2Fvalidate/install.md,并按其中说明把这个 MCP 服务器接入我的客户端。修改任何配置之前,先告诉我它的发布者、端点和登录方式,等我确认。不要把 API 密钥写进命令或我会提交的文件;问我密钥应从哪里获取。把它添加到你客户端的 mcpServers 配置中。
{
"mcpServers": {
"validate": {
"type": "http",
"url": "https://api.machinegrade.dev/mcp"
}
}
}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.
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.
mcp/server.ts exposes a single tool, validate, that forwards to
POST /v1/validate. Point an MCP-compatible client at it:
The production service also exposes an MCP endpoint directly — no local process, no npm install — via streamable HTTP at:
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:
The stdio adapter via npm (@machinegrade/validate, see above) remains
available for local/offline use or clients without HTTP transport
support.
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:
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.
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.
POST /v1/paid-request (requires X-Api-Key);
you'll be notified when it's live.Every error is typed JSON — {code, message, hint, docs_url} — never a
free-form string:
A verdict ({valid, errors, latency_ms}) is never an error — an
invalid artifact is a normal, expected outcome and returns HTTP 200.
artifact must be a JSON value, not a JSON-encoded string:
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:
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:
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.
The service runs on Cloudflare Workers (Hono + D1 + Workers Static Assets). To self-host on a fresh Cloudflare account:
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.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.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:
/v1/validate request/response shapes, typed error
codes, verdict semantics) is stable — breaking changes only with a
versioned path (/v2/...), never silently.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
Validate an artifact against a contract (json_schema | openapi_response | sql) via the machinegrade validate API.
type必填artifact必填contract已满足适用检查项的 100%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
npm installnpm run dev# machinegrade validate listening on http://localhost:8787# 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}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()){ "mcpServers": { "machinegrade-validate": { "command": "npx", "args": ["tsx", "mcp/server.ts"], "cwd": "/path/to/validate", "env": { "SANDBOX_URL": "http://localhost:8787", "SANDBOX_API_KEY": "sk_..." } } }}POST https://api.machinegrade.dev/mcpclaude mcp add --transport http validate https://api.machinegrade.dev/mcp --header "X-Api-Key: sk_..."curl -s -X POST https://api.machinegrade.dev/keys \ -H 'content-type: application/json' \ -d '{"email": "[email protected]"}'{"type": "json_schema", "artifact": {"name": "Ada"}, "contract": {"schema": {"type": "object"}}} // correct{"type": "json_schema", "artifact": "{\"name\": \"Ada\"}", "contract": {"schema": {"type": "object"}}} // wrongwrangler d1 execute machinegrade-validate-db --file=schema.sql # localwrangler d1 execute machinegrade-validate-db --file=schema.sql --remote # productionnpm test # vitest run, in-process via app.request(), MemoryStoragenpm run typecheck # tsc --noEmitwrangler 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