laya-mcp
laya-mcp is a local MCP server that provides bounded, probabilistic decision-making via Core ML models, with tools for single/batch decisions, conservative filtering, and model introspection.
info: Report server/backend/model versions, platform, compute units, capabilities, limits, and runtime metrics (e.g., initialization time, inference counts).
decide: Make one bounded decision (binary, choice, or ordered_score) from context/question, returning result, confidence, probabilities, token usage, latency, and escalation flag.
batch_decide: Process multiple decisions in one request using shared or per-item contexts; supports fail-fast or partial error handling, compact/detailed responses, and aggregate metrics.
filter: Conservatively retain relevant candidates by excluding only high-confidence irrelevant items; returns selected candidates plus reduction metrics, with optional per-candidate diagnostics.
Lazy model loading: Server starts fast; model loads on first inference and stays resident; supports local-only mode and configurable compute units.
Strict validation: Rejects inputs that would be truncated, and no implicit truncation occurs.
Structured logs on stderr: JSON logs, keeping stdout clean for MCP stdio transport.
Safe and bounded: No cloud fallback, no filesystem mutation, no autonomous loops; decisions are probabilistic signals, not authorization or safety judgments.
Provides local decision-making capabilities powered by Apple's Core ML and ANE, enabling bounded text classification, scoring, and filtering for applications on Apple Silicon.
Integrates with Hugging Face to load a Core ML model checkpoint, supporting local model inference for decision-making tasks.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@laya-mcp batch decide which of these three commits are risky"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
laya-mcp
laya-mcp is a persistent local Model Context Protocol
server for bounded decisions powered by
Laya-CoreML. It lazily loads one local
Core ML model on the first inference request and keeps it resident for the process.
Codex CLI ──────┐
Claude Code ────┼── MCP stdio ──> laya-mcp ──> Laya-CoreML ──> Core ML / ANE
Other clients ──┘The core server contains no client-specific behavior. Client examples live under
examples/, and client notes live under docs/.
Status
The current server provides:
fast MCP startup and tool discovery without model initialization;
one model load per server process, on first use, with serialized inference;
a stable generic
info,decide,batch_decide, and conservativefiltertool surface;public
binary,choice, andordered_scoredecision semantics;structured confidence, probabilities, token usage, and inference latency;
explicit rejection before inference if an input would be truncated;
serialized access to the resident Core ML model;
JSON logs on stderr, leaving stdout exclusively for MCP stdio messages.
Milestones 2–4 add exact Laya 0.1 token accounting, deterministic reusable chunk
planning, composition/throughput benchmarks, stable decision primitives, and the
conservative context-reduction filter primitive. See
docs/laya-capabilities.md and
docs/token-efficiency.md, plus
docs/filtering.md.
This is alpha software. Laya decisions are probabilistic signals, not authorization, safety, legal, medical, or financial judgments.
Related MCP server: decidealot
Requirements
Apple Silicon Mac
macOS 15 or newer for the default ANE checkpoint
Python 3.12 or 3.13 (3.12 is the currently validated project environment)
The default aac6fef/laya-multilingual-coreml-ane-w8 checkpoint supports a maximum of
96 total tokens across the question, options, and context. Call info rather than
hard-coding that limit if you configure another model.
Install
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install -e '.[dev]'On the first inference request, Laya-CoreML may download the configured Hugging Face
model before loading it. Inference is local after the model is present. To require a cached model
or local model directory, set LAYA_MCP_LOCAL_FILES_ONLY=true or set
LAYA_MCP_MODEL to that directory.
Run the stdio server:
laya-mcpDo not print application output to stdout when using stdio transport. Server logs are structured JSON on stderr.
Tools
info
Reports the laya-mcp and backend versions, configured model, initialization state,
platform, Python version, Core ML compute units, known model limits, and process-local
metrics. The initialization duration is for this process on this machine.
decide
Arguments:
context: the small bounded text to evaluate;question: the decision instruction;decision: optional object withkind(binary,choice, orordered_score) and, for non-binary decisions, at least twooptions;confidence_threshold: optional number from 0 through 1;request_id: optional caller-defined correlation ID.
Example arguments:
{
"context": "player_controller.gd contains movement, jumping, acceleration and player animation logic.",
"question": "Is this file relevant to fixing a player movement bug?",
"request_id": "decision-17",
"confidence_threshold": 0.8
}The result includes the normalized result, model confidence, threshold outcome, applicable probability distribution, model/backend identifiers, local token usage, and measured inference latency.
batch_decide
batch_decide accepts ordered items with unique IDs. Use either:
shared_contextwith item contexts omitted; oran independent
contexton every item withshared_contextomitted.
The default fail_fast policy validates every item before inference and fails the
whole call if any item is invalid. partial returns an explicit error entry in the
original position for every failed item. No item is silently omitted.
Compact responses are the default and omit probability maps and per-item latency.
Set response_detail to detailed when those fields are needed. Backend/model
identifiers and aggregate metrics appear once at the response envelope.
{
"shared_context": "Choose components relevant to a movement regression.",
"confidence_threshold": 0.75,
"items": [
{"id": "a", "question": "Is the player controller relevant?"},
{"id": "b", "question": "Is the audio mixer relevant?"}
]
}This is MCP/API batching, not concurrent or fused model inference. The default ANE
backend evaluates each question independently while holding the same serialization
lock used by decide.
The server does not read files: clients must provide bounded context.
filter
filter accepts a criterion and ordered {id, text} candidates. It returns only
retained candidates by default, which keeps rejected classification records out of
the primary agent's context. Candidates are excluded only when Laya returns a
binary negative result with confidence at or above the rejection_threshold (the
default is 0.9). Relevant, uncertain, oversized, and failed candidates are
retained. Use response_detail: "detailed" for per-candidate diagnostics.
{
"criterion": "Relevant to fixing player acceleration behavior",
"rejection_threshold": 0.9,
"candidates": [
{"id": "movement", "text": "player controller handles acceleration"},
{"id": "audio", "text": "audio mixer loads music"}
]
}Filtering reports candidate reduction and serialized MCP payload sizes. Those are
local MCP payload measurements, not Codex/Claude token savings. See
docs/filtering.md for the conservative policy and benchmarks.
Configuration
Variable | Default | Meaning |
|
| Hugging Face ID or local directory |
| unset | Optional model revision |
|
| Disable model downloads/lookups |
| model default |
|
|
| Structured stderr log level |
Model loading is lazy: process startup, tool discovery, and info do not load model
weights. The first decide, batch_decide, or filter call pays the cold
initialization cost; later calls reuse the resident model. The original development
machine measured about 30–32 seconds for initialization and about 7–10 ms for warm
inference. These are local observations, not universal performance claims.
Client setup
Generic MCP:
docs/mcp.mdCodex CLI:
docs/codex.mdClaude Code:
docs/claude-code.mdAgent usage patterns:
docs/coding-agents.mdEvaluation results:
docs/evaluation.mdSynthetic policy-routing evaluation:
docs/policy-routing-evaluation.mdPre-registered policy-routing criteria:
evaluation/policy-routing-success-criteria.mdModel comparison:
docs/model-comparison.mdLifecycle measurements:
docs/lifecycle.mdRelease checklist:
docs/release.mdCodex end-to-end evaluation:
docs/codex-evaluation.md
Development
python -m pytestThe real-model benchmark is opt-in and runs only on a compatible Apple Silicon machine:
python benchmarks/token_composition.py
python benchmarks/token_efficiency.py --output /tmp/laya-token-efficiency.json
python benchmarks/evaluate_milestone5.py --output evaluation/results/milestone5.jsonUnit and MCP integration tests use fake backends and do not load model weights. A
real lifecycle smoke test should be run on a compatible Apple Silicon Mac before
release; see docs/release.md.
The Milestones 5–6 quality evaluations are intentionally advisory; see
docs/evaluation.md before using filter for automatic
context exclusion.
Design constraints
no cloud LLM fallback;
no autonomous action loop;
no filesystem mutation or command execution;
no implicit input truncation;
every decision remains bounded and independently token-validated;
backend and MCP transport remain separate so other local Laya backends can be added.
Evidence and limitations
Demonstrated: local Core ML inference, the generic MCP decision API, API batching, deterministic token preflight, conservative failure handling, and MCP interoperability. The W8 default is supported by the tested hardware/workloads and is not a universal quality or latency guarantee.
Experimental: filter, context-reduction workflows, and agent delegation patterns.
Not demonstrated: automatic Codex or Claude token savings, safe silent context
exclusion, improved coding-agent task quality, or calibrated confidence. See the
negative results in docs/evaluation.md and
docs/codex-evaluation.md. The synthetic policy-routing
experiment also found that validator-enforced Laya avoided invalid execution but
did not outperform deterministic Python heuristics; it does not justify production
policy routing. See docs/policy-routing-evaluation.md
and the raw held-out results in evaluation/results/policy-routing/final-json.json.
License
Apache-2.0. Laya-CoreML and model weights are separate dependencies with their own licenses, notices, and model cards.
Available Tools
4 toolsbatch_decideARead-onlyIdempotent
Make ordered bounded decisions in one MCP request.
Supply shared_context and omit item contexts, or omit shared_context and
give every item its own context. This is API batching, not parallel inference.
Inputs: items (required), failure_policy, shared_context, response_detail, +1 more. Returns: items, model, backend, metrics, +2 more
decideARead-onlyIdempotent
Make one bounded decision using the resident local model.
Decision kinds are binary, choice, and ordered_score. The server only
signals needs_escalation; the caller remains responsible for any escalation.
Inputs: context (required), question (required), decision, request_id, +1 more. Returns: model, result, backend, details, +8 more
filterBRead-onlyIdempotent
Conservatively retain relevant, uncertain, failed, and oversized candidates.
Only a sufficiently confident irrelevant result excludes a candidate. The
default response returns selected candidate text and aggregate metrics; use
detailed for per-candidate diagnostics.
Inputs: criterion (required), candidates (required), response_detail, rejection_threshold. Returns: details, metrics, summary, failures, +2 more
infoARead-onlyIdempotent
Report server, resident backend, model, platform, limits, and metrics.
Inputs: no named parameters. Returns: model, backend, metrics, version, +6 more
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
decide and batch_decide are clearly the single-item and batch variants of the same operation, while filter is a distinct conservative retention workflow. An agent might briefly hesitate between filter and repeated decide calls for relevance tasks, but the descriptions make each tool's purpose specific enough to avoid serious ambiguity.
Most names are short, lowercase, action-oriented commands: info, decide, filter. batch_decide is the main deviation because it introduces an underscore and a compound form, but the naming remains readable and the relationship to decide is obvious.
Four tools is well-scoped for this server's purpose: server introspection, single decisions, batched decisions, and candidate filtering. Each tool covers a distinct core workflow without redundancy or unnecessary surface area.
The tool surface covers the full apparent workflow: checking server state and limits, making a single bounded decision, making batched decisions, and conservatively filtering candidates. Escalation is intentionally left to the caller, so there are no obvious dead ends or missing operations.
Maintenance
Related MCP Connectors
AI Reasoning Cache & Consensus Layer with 11 MCP tools via Streamable HTTP.
Governed data discovery, exact queries, decisions, simulations, and runtime utilities over MCP.
Independent statistical feature evaluation for machine learning and forecasting. ML Referee tests up to 1,000 candidate features in one run against a declared baseline, helping researchers and AI agents decide which inputs to pursue, which bounded feature repairs merit further testing, and where more evidence is needed—without a separate ablation run for every feature. Use the MCP tools to discover input schemas, check access and credits, preflight a dataset, obtain a quote, submit an authorized evaluation, and retrieve structured results and reports. Results are scoped to the submitted evidence and evaluation design; they do not guarantee future model performance. Invite-only beta with manual approval. Public tool discovery requires no authentication; account and evaluation tools require OAuth through approved client connections and available evaluation credits. Connect directly to https://api.mlreferee.com/mcp. Website: https://mlreferee.com Request beta access: https://mlreferee.com/beta Agent setup and documentation: https://mlreferee.com/agents
Private-by-default, local-first memory/context/task orchestrator for MCP apps and agents.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables coding agents to offload quick judgment calls like shipping readiness, file triage, and claim verification to a fast local MCP server with calibrated confidence and safe fallbacks.8MIT
- AlicenseNot gradedqualityBmaintenanceEnables local typed decision-making over MCP Streamable HTTP, running Laya and Von models to turn arbitrary state into choice, score, and yes/no answers with probabilities.3Do What The F*ck You Want To Public
- AlicenseAqualityBmaintenanceProvides fast, offline typed decision tools (classify, score, check, triage) to agents via the Model Context Protocol, enabling safe local inference across 100+ languages with calibrated confidence and no text generation.821 PyPIMIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to run local, CPU-only inference for decision tasks such as choosing among labels, estimating yes/no probability, and scoring ordered descriptions. Exposes these capabilities through MCP tools, REST/Swagger endpoints, and a browser test console without GPUs, paid APIs, or databases.Apache 2.0