MCP Server and CLI
mloda ships an MCP server, mloda-mcp, so agents can discover features, plan
requests and, when you allow it, run them. The mloda command line calls the same functions, so whatever an agent
sees you can reproduce locally.
Install
The server needs the mcp extra; the mloda command needs nothing beyond mloda itself.
pip install "mloda[mcp]"
Add it to Claude Code, or to any client that starts MCP servers over stdio:
claude mcp add mloda -- mloda-mcp --config /abs/path/mloda.toml
{ "mcpServers": { "mloda": { "command": "mloda-mcp", "args": ["--config", "/abs/path/mloda.toml"] } } }
mloda mcp serve is the same server. Plugins are whatever is installed in the server's environment when it starts;
agents cannot install or load plugins.
Configure
Settings live in the [mcp] table of mloda.toml. Without --config, ./mloda.toml is used if it exists;
--no-config ignores it. Relative paths resolve against the file.
[mcp]
mode = "plan" # "plan" (default) or "execute"
compute_frameworks = ["PythonDictFramework"]
max_rows = 100000 # refuse requests that may read or return more rows (see below)
deny_feature_groups = ["CustomerEmailFeatureGroup"]
alternatives = { customer_email = ["customer_id"] }
preview_allows = ["public", "internal"]
max_preview_rows = 20
inline_data = false # allow inline request data (trusted callers only)
# result_paging = false # let callers page through truncated previews
# max_inline_values = 1000 # refuse inline data with more values (default: no limit)
# max_inline_chars = 10000 # refuse inline data with more string characters (default: no limit)
plan_ttl = "24h"
# default_classification = "internal" # label for unlisted leaf columns (default: unclassified)
# allow_options = ["window"] # option keys a request may set (default: none)
[mcp.sources.sales]
files = ["data/sales.csv"]
[mcp.classification]
customer_id = "personal"
income = "internal"
segment = "public"
[mcp.credentials.db] # a credential handle: field = env var name, or { file = path }
token = "DB_TOKEN"
sqlite = { file = "secrets/wh_path" }
[mcp.options] # default group options for every requested feature
model = "small"
[mcp.context_options] # default context options for every requested feature
timeout = 30
MLODA_MCP_MODE, MLODA_MCP_MAX_ROWS, MLODA_MCP_MAX_INLINE_VALUES, MLODA_MCP_MAX_INLINE_CHARS and
MLODA_MCP_COMPUTE_FRAMEWORKS override the file. MLODA_MCP_SIGNING_KEY
signs plan ids; without it every process uses a random key, so a plan id is valid only in the process that issued it.
[mcp.options] and [mcp.context_options] are operator defaults merged under each requested feature; a feature's own
value wins. They are not subject to allow_options and their values never appear in results. Values are strings,
numbers, booleans, lists or tables (no TOML dates or times), and in_features is not allowed.
[mcp.credentials.<handle>] registers a credential for groups that read it with read_credential and for database
sources. The table holds environment variable names and file paths, never values. Startup fails, naming the handle and
the field, if a variable is unset, empty or blank or a file is missing, empty or blank. A field value must be an
environment variable name (letters, digits and _, not starting with a digit); a name with . or - fails
startup, while an underscore-only token such as sk_live_abc still passes the rule. An empty field name is refused.
Handle names are free-form (for example pii-hmac-key), non-empty, without control characters, and may not start with
_auto_ or equal a source alias. The unset or blank error names the handle and field, not the variable. Secret files
are read again for every request, so a rotated file takes effect without a restart; an environment variable needs a
restart. A group declares its handle option with credential_handle_spec; set it in
[mcp.options].
A credential that cannot be read is left out. Requests whose plan has a source that binds a credential (even one named
by data_access_handle), and explains and describes that do not resolve, fail until it is back; other requests keep
working, including a group that reads only its declared, readable handles. The log names the handle when it becomes
unreadable and again when it is back. A column that a file and a credential source both serve may resolve to the file
meanwhile, also for a request that reads declared credentials. The short-value warning appears at startup, when a value
changes, and when a handle is readable again. restrict_sources does not narrow credentials. A database source binds
the only registered credential; with several, set data_access_handle in [mcp.options].
Tools
| Tool | What it does |
|---|---|
mloda_search_features |
Lists FeatureGroups and source aliases matching a query, one page at a time |
mloda_describe_feature |
Resolves one feature name and lists the options of its FeatureGroup |
mloda_explain_request |
Validates and plans a request without reading data; returns the plan and a plan_id |
mloda_run_request |
Runs a plan_id; only offered when mode = "execute" |
mloda_fetch_rows |
Pages through a run result by result_id; only offered when mode = "execute" and result_paging = true |
A run whose preview is truncated returns a result_id, and each truncated table's preview a next_cursor.
mloda_fetch_rows returns pages of the preview-allowed columns only (limit up to max_preview_rows) and never
re-runs the plan. Results expire after 15 minutes and share a total size cap (oldest evicted
first; a result over the cap gets no result_id). Anyone holding a result_id can fetch its rows, like a plan id
within the same server. An unknown or expired id is plan_invalid. Paging lets a caller
read every row of the previewable columns, so it is off by default.
The resource mloda://schema/feature-request is the JSON Schema of a request. A request is the
feature configuration JSON plus optional filters, source restrictions and inline data:
{
"features": ["customer_id", {"name": "income", "options": {}}],
"filters": [{"feature": "segment", "op": "eq", "value": "a"}],
"restrict_sources": ["sales"],
"data": {"Inline": {"token": ["007", "", "12"]}}
}
data is optional inline data, {"<set>": {"<column>": [values]}}. It needs inline_data = true under [mcp]
(default off) and a set name that is not a source alias. Values travel in the signed, unencrypted plan id and are echoed in the normalized_request of explain. Inline
columns are unclassified, so the preview is empty unless you classify them in [mcp.classification]. Use it for trusted
callers only, since row counts over caller-chosen values can reveal plugin data;
deny_feature_groups = ["ApiDataFG"] turns it off entirely.
max_inline_values and max_inline_chars (integers, at least 1) refuse oversized inline data as limit_exceeded
before planning and again on run. Inline data is also capped by the plan id size (16384 JSON characters).
Every result is a one-line summary followed by the result as JSON, which is also the structured content. A failed
call has isError set and one error shape: {"error": {"code", "message", "details", "audit_id"}} with the codes
validation_failed, policy_denied, limit_exceeded, plan_invalid, plan_stale, missing_input_feature and
internal. Details point at the request by JSON pointer, with a suggestion when a close name exists. A
missing_input_feature detail holds feature_group, feature and missing_inputs (never the available columns). A variant_not_allowed detail holds feature_group and variants, plus a fix of {"allow_variants": [...]} only when the group lists every variant blocking some framework and the caller may set allow_variants. It is reported at the requested feature when an input is variant-blocked or a chained implementation pin hits a blocked implementation. Competing consumers over a variant-blocked input give one variant_not_allowed detail per competing consumer whose input is variant-blocked, whose feature_group names the consumer. An input the request never names (neither as a feature nor in in_features) that cannot be resolved is reported as unresolved at the requested feature, without the input's name or a suggestion.
Each step record of an explain result carries contract_version, divergences and allowed_variants (see Divergence Records).
What stays on the server
Credentials a group reads at run time with read_credential stay here too (see Runtime access versus match-time binding).
- Credentials are registered by the operator, never listed by search or describe, and never settable by a request: a
declared handle option is refused even when listed in
allow_options. - Sources are named by alias only. Paths, connection details, data-access objects and option values never appear in a
result, and a request cannot set data-access options (such as
data_access_handleorconnection_handle). - A request may set only the option keys listed in
allow_options(default: none). Any other key inoptions,group_optionsorcontext_options, nestedin_featuresconfigs included, is refused aspolicy_deniedby JSON pointer, never by value. Data-access keys stay refused even when listed. Options encoded in a chained feature name are not covered.mloda explainandmloda runare local and not restricted.mloda_describe_featureshowscaller_settablefor each option and refuses option keys not inallow_options. - A plugin marks a key it never wants from a caller (a base URL, an API key) with
PropertySpec(..., caller_settable=False). MCP requests andmloda_describe_featurerefuse that key aspolicy_deniedeven whenallow_optionslists it, and describe showscaller_settable: false. The match is by key name across all installed plugins. A declared credential handle option is always refused this way. A planned feature name that binds the key through the plugin's name pattern is refused too, even when[mcp.options]sets it, at/features/<i>for a requested name and/featuresfor a planned one.[mcp.options]defaults and the local CLI may still set it. - Denied FeatureGroups are disabled before matching, so their code does not run; the agent sees
policy_deniedand the alternatives you configured. Requested names,indexcolumns,in_featuressource names and filter columns are checked before planning. Any planned feature name the deny list matches, such as a chained name over a denied column, is refused after planning; a request whose planning stops on a denied name, or after resolving one, is refused the same way. Configured source groups that probe through theINPUT_DATA_MATCHhook (all of core's) never serve a denied name, so planning, running and describe answer the same whether or not a source has the column. runre-plans the request: validation, policy, filters and row limits are checked again, and a plan that resolves differently is refused asplan_stale.- With
max_rowsset, a request is refused aslimit_exceededwhen a configured source has more rows or cannot be counted (a CSV is counted exactly only when read onPythonDictFramework), when it reads data that a FeatureGroup loads itself (never countable), and, afterrun, when a result table has more rows. - The preview holds only columns whose classification is in
preview_allows. A derived feature takes the strictest classification of its inputs unless you classify it yourself. Unclassified columns are withheld. keep_index: truein a request requiresindex. Index columns are classified like any column.- A filter on a column the preview withholds is refused as
policy_denied: row counts would reveal its values. - Descriptions and previewed values come from plugins and data: the server marks them untrusted.
- Each call writes one audit record to the
mloda.interfaces.mcplogger, without argument values. The principal is the local OS user. Unexpected failures log a traceback without exception messages.
default_classification replaces unclassified for every leaf column without its own entry, including columns a
FeatureGroup loads itself; derived features still take the strictest input. A permissive label such as public exposes
all of them in the preview, so prefer listing columns in [mcp.classification].
Upgrade note: MCP callers that set options are refused until you list the keys in allow_options.
Local HTTP
mloda-mcp --transport http --host 127.0.0.1 --port 8000
The server is at /mcp. Bound to loopback, it accepts only loopback Host and Origin headers.
There is no authentication: a non-loopback host exposes the server to the network (the CLI warns). All clients share one principal (the OS user) and one set of plan ids.
To embed it, call mloda.interfaces.mcp.server.create_app(settings, env=env, host=...), which returns a
Starlette app; call enable_process_wide_log_masking() yourself first, as mloda mcp serve does.
Pass data_access_collection= to add connections and credentials built in code; a handle that duplicates one of the
[mcp.credentials] table is refused. A mounted sub-app's lifespan does not run, so run the returned app's lifespan or
serve it directly.
Not yet: approvals, cancellation, and remote HTTP with OAuth.
Command line
mloda demo # a bundled example, its result and plan
mloda explain request.json # the same JSON as mloda_explain_request
mloda explain request.json --format text # one line per step; errors stay JSON
mloda run request.json --max-rows 100000 --format jsonl
cat request.json | mloda explain -
mloda run request.json --full --format csv
mloda run income segment -o model=small -c timeout:=30
mloda --version prints the installed mloda version.
mloda run FEATURE ... -o KEY=VALUE -c KEY=VALUE builds the request from feature names: -o sets group options and
-c context options on every feature, and both repeat. A value is KEY=VALUE (string), KEY:=JSON (parsed JSON) or
KEY=@FILE (file text). A single target that is -, an existing file or ends in .json is a request file instead,
and -o or -c with it is an error.
--full returns every row and all columns, withheld ones included. max_rows still applies. The server never offers
it. mloda explain and mloda run do not refuse filters on withheld columns (the caller is local); mloda mcp serve
does.
mloda run executes regardless of mode, since you started it yourself, but applies the same limits and preview
rules. Exit codes: 0 success, 2 an error result or nothing could run (bad config, bad request, policy, limit, or a
FeatureGroup that failed while planning or running, reported as internal), 3 a completed run whose result
carries failed_rows, 1 any other failure. Every error result is also written to stderr as mloda: error: <message>.
A credential handle refusal (a misspelled or unset handle) shows its text, naming handles and keys only, in that message
and on stderr. The MCP server reports it as internal and logs the text with the audit id; describe does the same, and also reports a plugin raise that escaped resolution as internal, naming only its class.
A completed run result has a failed_rows list only when feature groups reported rows that got no value. Each entry has
column, reason (a short code), row_count, rows and truncated; rows holds at most 1000 positions unless
--full is used, and at most 100 entries are listed. The positions are rows of the feature group's own output. With
--format jsonl or csv the entries go to stderr as a short summary and stdout is unchanged.