SuperAPI AI Directory

validate

Deterministic validation of AI-generated artifacts: JSON Schema and OpenAPI response conformance and per-dialect SQL syntax, with typed verdicts and fix hints.

Open website

About this tool

Purpose

validate is used to deterministically validate AI-generated artifacts against a contract before adopting them. Agents that generate JSON, API responses, or SQL need a fast, cheap, machine-decidable pass/fail check before delivering results—it is cheaper than a full LLM-as-judge call, and it is deterministic.

Main capabilities

Supports three types of checks:

  • json_schema: Validate the artifact against a JSON Schema (collect all errors).
  • openapi_response: Validate the response body against the response schema for the given path + method + status code in the OpenAPI specification.
  • sql: Check a SQL string for syntax errors under the given dialect.

Each check returns a verdict, not an error: {valid, errors, latency_ms}, and returns HTTP 200 regardless of whether the artifact is valid. Only genuinely erroneous requests (wrong key, unsupported type, malformed request body, over quota) return typed HTTP errors. All errors are typed JSON: {code, message, hint, docs_url}, never free-form strings.

How to use

The service's online address is https://api.machinegrade.dev,提供免费层、自助密钥,可在 Try it within 30 seconds.

MCP integration: mcp/server.ts exposes a single tool, validate, which forwards to POST /v1/validate. You can point MCP-compatible clients at it. The production service also directly exposes an MCP endpoint, connectable remotely via streamable HTTP, with no local process and no npm install required. It is the same validate tool as the stdio adapter described above. initialize and tools/list work without a key (discovery is anonymous); tools/call requires X-Api-Key (issued via POST /keys, the same as for the REST API—the free tier and quota are shared).

Usage with Claude Code: can be used via the npm stdio adapter (@machinegrade/validate) for local/offline use, or for clients that do not support HTTP transport.

One-click install for Claude Desktop: download the latest .mcpb package from Releases and double-click it. During installation, Claude Desktop will ask for an API key and store it in the operating system keychain (macOS Keychain, Windows Credential Manager) rather than in a configuration file—it will not be written to claude_desktop_config.json. The package is a lightweight stdio client on top of the hosted API: about 34 KB, with zero bundled dependencies. If self-hosting, you can point the extension's API base URL setting at your own deployment.

Sending artifacts: artifact must be a JSON value, not a JSON-encoded string. For type: "sql", artifact is a string—the statement itself. Because MCP callers often stringify values, the service tolerates the incorrect form within a narrow scope: if artifact is a string, the type is json_schema or openapi_response, and the type declared by the contract's top-level schema excludes string, then the string is JSON-decoded before validation, and the verdict includes "decoded_from_string": true. This field is additional; {valid, errors, latency_ms} remain unchanged. In other cases decoding is deliberately not performed, because string outputs are often valid.

The full contract is in public/openapi.yaml, or at /v1/manifest after the service is running (machine-readable summary: types, limits, pricing, error codes). /llms.txt is a brief guide for LLM agents.

Applicable scenarios

Suitable for quick machine-decidable checks after an agent generates JSON, API responses, or SQL, and before delivering results.

Limits and notes

Free tier: 500 calls per key per month, 60 calls per minute rate limit. Paid tier: EUR 0.002/call after exceeding the free tier——coming soon. Paid access can be requested via POST /v1/paid-request (requires X-Api-Key); you will be notified when it goes live.

Storage: src/storage.ts defines the Storage interface, with two implementations: MemoryStorage (a complete in-memory implementation, used for npm run dev and the test suite); D1Storage (the real Cloudflare D1 binding, backed by schema.sql, containing the keys and events tables, used in production; the Workers entry point in src/index.ts builds it from the DB binding on the first request).

Test coverage: key issuance, success + failure cases for each validator, typed 401/400/402/429 errors, metering limits (both can be injected in tests, so there is no need to loop hundreds of real requests), and /stats funnel counts.

The service runs on Cloudflare Workers (Hono + D1 + Workers Static Assets). It can be self-hosted on a fresh Cloudflare account, then bind a custom domain (for example api.machinegrade.dev) to the Worker via the Cloudflare dashboard or wrangler. After setting CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID repository secrets and uncommenting the deploy job in .github/workflows/ci.yml, CI can deploy on push to main.

Workers porting, two things to know: GET /openapi.yaml and GET /llms.txt are served by the ASSETS binding ([assets] in wrangler.toml, pointing to public/)——Cloudflare serves them directly and does not invoke the Worker; the routes in src/index.ts are a fallback for local Node development/testing, where there is 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 does not support, and the schemas here arrive dynamically on each request (from the caller), so they also cannot be precompiled at build time.

Phase note: the service is in an early phase, online availability and free-tier usage are real, and it is being measured whether it can support a paid tier. What you can rely on: the API contract (/v1/validate request/response shapes, typed error codes, decision semantics) is stable——breaking changes will only happen through versioned paths (/v2/...), never silently; the free tier (500 calls per month) remains unchanged; if the service eventually goes offline, keys will remain usable for 90 days after the announcement, and the validators are open source in this repository——you can self-host the same behavior.