SuperAPIAI Directory

ClefMCP

github.com · Other AI tools

ClefMCP is a local MCP server that exposes Cloudflare's Clef-Flash decision model (9B, Apache-2.0) to AI agents via llama.cpp, providing structured decisions with probability outputs, with all inference performed offline. It can also use YAML configuration to perform batch classification on JSONL/CSV datasets, returning probabilities and explicit review results rather than generative text. It requires Node.js 20+ and sufficient memory (16 GB recommended for Q4_K_M); the default model download is about 6 GB, after which it can run offline.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)

About this tool

Purpose

ClefMCP targets decision points in AI agent loops, such as next actions, routing, classification, severity, yes/no judgments, and other tasks that require repeated queries. It runs Cloudflare's Clef-Flash decision model (9B, Apache-2.0) locally and provides structured decision tools to clients via MCP (stdio); it can also be used for reusable batch classification of JSONL/CSV datasets. Inference never leaves the local machine.

Main capabilities

  • MCP decision tool clef_decide: returns strictly structured results, including probability distributions, model-reported confidence (when provided at runtime), and token usage, without generating prose-style answers. A single call can submit up to 64 questions in a batch, scored in one forward pass.
  • Batch classification: define tasks with YAML profiles and classify JSONL/CSV records one by one. The model is loaded only once for the entire batch, with no separate daemon required.
  • Result status:classified indicates that all configured thresholds pass;needs_review retains the suggestion and full distribution but sets label to null, for reasons including low_probability, low_margin, tie, low_confidence, missing_confidence. A complete tie always requires review.
  • Resumable runs: file output generates private results.jsonl and results.jsonl.meta.json; the sidecar records fingerprints of the input, profile, model, runtime, and format; resuming requires all to match.
  • MCP prompts and resources: the server ships with prompts for four decision shapes and three read-only resources (no model required).
  • Scripts and hooks: invoke the same model in one shot without an MCP client; stdout outputs strict JSON, errors are written to stderr as structured JSON, and exit code 2 means invalid input, 3 means model not installed, 4 means runtime missing.
  • Daemon mode:clef-mcp daemon keeps the model hot-loaded on an owner-only accessible (0600) Unix socket under CLEF_HOME, unloading after CLEF_DAEMON_IDLE seconds of idleness (default 600);decide --daemon can respond in well under a second, falling back to cold start when no daemon is present.
  • Runtimes: llama.cpp and MLX are two local runtime implementations of the same ClefRuntime interface (load/decide/unload/health), switched via CLEF_RUNTIME=mlx; both use the same POST /v1/systemone contract.

Usage

Requires Node.js 20+ and sufficient memory (16 GB recommended for Q4_K_M). The default model download is about 6 GB, after which inference is offline.

Installation and startup:

  • clef-mcp starts the MCP server over stdio; only install downloads model/runtime files.
  • You can also use npx -y clef-mcp instead of a global install;npx -y clef-mcp install --setup Combine model installation and client registration.
  • After updating, restart the MCP client and any existing daemon; already installed models do not need to be downloaded again.

Batch classification example: save the task as support-routing.yaml, prepare tickets.jsonl (one object per line) or tickets.csv with a header, and runnable files are also provided under examples/classify/. The examples are data supplied with the records and do not train or modify model weights. Unknown fields, duplicate YAML keys, aliases, merge keys, unsupported tags, and non-JSON values are rejected; label IDs and profile names use the same character rules, with a limit of 128 characters; missing selected fields produce a row error.

Format and limits: JSONL accepts objects, ignores blank lines, and supports UTF-8 BOM/CRLF; CSV supports quoted commas, escaped quotes, and multiline fields, the header must be non-empty and unique, the column count must be consistent, and cells remain strings (preserving IDs such as 001). The format is inferred by default from .jsonl/.csv, stdin defaults to JSONL, and other extensions require --format. Profiles and logical records are limited to 1 MiB, YAML nesting is limited to 64 levels, selected/CSV fields are limited to 1000, and examples are limited to 20; the model context is 16k tokens, and selected fields and examples share that context. Oversized JSONL lines are recorded as row errors; corrupt or oversized CSV syntax stops the run.

Model selection priority: --model <id> overrides the model in the input document, which overrides CLEF_MODEL (default clef-flash); the same applies to --daemon.

Use cases

  • Routing, classification, severity, and yes/no judgments in agent loops.
  • Reusable batch classification of datasets.
  • As a PreToolUse guard: when the model judges a command to be destructive (p ≥ 0.9), block it and prompt the agent to ask the user; this gate is advisory by design. In the example, it once intercepted a history-rewriting force push (p=0.94).
  • One-off decision calls in CI jobs and shell scripts.

Limitations and caveats

  • The threshold is a routing policy, not a calibrated accuracy guarantee; check it on representative labeled data before automating decisions. Classification does not grant authorization or perform actions.
  • Winning probability, probability margin, and modelreported confidence are different quantities.
  • Invalid JSONL objects and missing fields produce status: "error" rows and processing continues; runtime failures stop the run and are not converted into review decisions. Output contains identifiers and results, not copies of the original records.
  • Resuming skips the committed contiguous prefix (including committed error rows) and does not retry those errors; an incomplete final write is discarded, and corruption in complete lines is rejected. Resuming requires regular file input and --output; resuming from stdin/stdout is not supported. A local lock prevents concurrent writes; active, foreign-host, or unverifiable locks are preserved.
  • Each ordinary decide call is a cold start (including model loading, several seconds), suitable for gates and triage; repeated calls should use the daemon.
  • Input exceeding the 16k token model context is rejected with a prompt to reduce state.
  • No public network service, telemetry, or account; MCP uses stdio, inference uses local loopback HTTP, and the optional daemon uses a local Unix socket. Models are downloaded via HTTPS and checksum-verified only on explicit install. State content is passed to the model as data, and the server never executes it or interprets it as instructions.
  • Models/runtime are stored in CLEF_HOME; classification also reads the provided input/profile paths and writes to explicit output/checkpoint paths; setup/doctor checks or updates supported client configurations.
  • The managed runtime is an official llama.cpp build, and the version can be pinned with CLEF_LLAMA_RELEASE_TAG.
  • Quality gate: a 30-case evaluation dataset (coding/safety/classification/routing/yes-no) achieved an 86.7% pass rate on the live model, available clef-mcp evals Run it yourself.
  • The code is Apache-2.0; the Clef/Clef-Flash models are copyright Cloudflare, Apache-2.0; the llama.cpp runtime is owned by its authors, MIT licensed.
Up/Down to navigate · Enter to open · ESC to closeBrowse all tools