Skip to content

feat(platform): read and change organization settings over MCP - #4685

Merged
yannickmonney merged 36 commits into
mainfrom
feat/mcp-settings
Oct 10, 2026
Merged

yannickmonney merged 36 commits into
mainfrom
feat/mcp-settings

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What this adds

A coding agent connected to Tale's MCP endpoint can read and change organization settings with three tools: get_settings, plan_settings and apply_settings. It can do whatever the role of the person whose API key it uses allows, through the same writers and checks as the app. Every change is audited as that person's, via: mcp. A plan shows each change's diff, effects and risk before anything is written, and apply_settings is compare-and-set on the hashes the agent read.

Kinds served

  • provider, provider-credential (credentials that read their key from an environment variable), governance, knowledge-embedding, branding, deployment.
  • Project-scoped: project-instructions, agent-instructions, agent-tools, agent-model, task-instructions, task-review-context.
  • The automation kinds stay with save_automation, deploy_automation and set_trigger, and each says so.

How

  • The CLI's native resource model (schema, identity, declaration rules, convergence) moved to @tale/shared/config/platform-resources, so the CLI and the platform share one copy. A golden test holds the shared configuration hash to the backend's.
  • The writers were lifted out of their routes first; each route's existing tests still pass unchanged, with a characterization test first where a route had none. Embedding-model changes now write an audit row; they wrote none before.
  • A settings registry (backend/domains/mcp/settings/*) routes each kind to a handler beside its native writer. A coverage guard joins every Settings page to the kinds that cover it.
  • Secrets never cross the door. A credential found anywhere in a stored setting is masked on read, and the mask sent back keeps it. A secret in an argument is refused (SECRET_ARGUMENT_REFUSED), using the same detector the automation engine refuses a document with: one copy, lib/shared/secret-scan.ts.
  • Reference topic tale://docs/settings (get_docs {topic: "settings"}), plus the instructions and skill lines.
  • Contract 3.30.0, with fingerprints, snapshots and OpenAPI regenerated.

Where it differs from the design (each covered by a test or spec card)

  • Over MCP, the embedding model itself changes only while the knowledge base is empty, so vectors from two models never meet in one search (MCP-R28).
  • A branding file name an agent sets must name an image already uploaded.
  • Provider credentials with a key or a subscription are "made in Tale only" until the agent-request flow (PR-B2) exists. Over MCP they can still be listed and deleted.
  • Task-scoped kinds are read by id only. Project and agent kinds are listed page by page over the projects the caller can read.

Merged with main

  • main's agent-model and task-review-context managed kinds are now declarable and served over MCP, through main's own writers.
  • The engine's credential patterns and this branch's lifted scanner were merged into one detector.
  • The failed-run instruction line is main's.

Proof (local, on the merged tree)

  • Typecheck: platform, shared and CLI.
  • Platform server suite: 1,295 files / 19,482 tests.
  • Settings UI: 1,666 tests. i18n: 520. Shared: 931. Docs: 688.
  • lint:links, lint:manual, format, lint (17/17), knip.
  • CLI: 3,037 tests, of which 3 fail identically on plain main on this machine (bun audit engine, two TLS transport tests).
  • Integration lanes on fresh Postgres: checkMcpSettingsConfig (its first run), checkMcpAuthoringParity, checkMcpDiscovery, checkMcpResourcesPrompts, checkMcpEras, checkManagedAutomationConfiguration, the provider-credential and embedding lanes, checkBrandingAndTeams, checkPolicySweeps, checkSandboxSettingsViews, and the task-review lanes all pass. checkGovernance (its retention agentRuns check), checkGovernanceEnforcement and checkGovernanceSettingsTail fail identically on plain main on this machine.

Manual boxes MCP-F9, MCP-B1 and MCP-B2 need a real coding agent.

Findings outside this PR, for follow-up:

  • Policy changes have no audit-log label.
  • In the app, switching to an embedding model of the same width on a non-empty knowledge base keeps the old vectors.

The CLI's valueHash and the platform's managedConfigurationHash are two
copies of one identity: CLI plans and receipts compare against the
native `hash` / `expectedHash` the platform computes. Before either moves,
a golden corpus pins both to the same digests (numbers, -0, NaN, unicode,
escapes, numeric and unsorted keys, nested values) and records where they
part on purpose: null is a digest for the CLI and an absent resource for
the platform, and a value JSON cannot hold (undefined) is refused by the
CLI and written as null by the platform.

The two older parity checks in managed-resources.test.ts move into the
new suite unchanged.
The platform's native configuration identity moves to @tale/shared:
`configurationHash(value)` (SHA-256 of key-sorted JSON) beside the pure
`stableStringify` it hashes. The platform's stable-stringify module now
re-exports the shared serializer, and `managedConfigurationHash` wraps
`configurationHash` (null still means an absent resource). The shared
resource model and the MCP settings tools build on the same function.

The golden corpus moves to the shared package; `configuration-hash.test.ts`
holds the shared function to it, and the CLI's parity suite holds all
three — the shared hash, the platform's wrapper and the CLI's own
`valueHash` — to the same digests. The CLI keeps `valueHash` for its
releases, plans and receipts: it refuses a value JSON cannot hold where
the platform writes null, and a recorded CLI digest must never move.

The engine purity guard now scans the shared serializer and allows its
subpath; the platform's test inputs hash the file it reads.
The resource model that `tale config platform` and managed deployments
declare moves out of the CLI into @tale/shared, so the MCP settings tools
can build on the same objects: `@tale/shared/config/platform-resources`
holds the resource union, each resource's identity, a declaration's
cross-resource rules and the convergence test, comparing
`configurationHash` digests (the platform's own identity, equal to the
CLI's on every JSON value). It sits outside the browser-safe `schemas/`
because it hashes with Node's crypto.

The CLI keeps what is its own: `parsePlatformConfiguration` with its
usage error, the target and the reviewed plan file. The schema and
convergence cases move to the shared suite with the synthetic fixture;
the CLI keeps its usage-error and deployment-spec cases. The shared
schema already refuses a field parsing would discard, so the CLI's second
check of it goes.
`@tale/shared/schemas/settings-kinds` describes, once for the platform,
the docs and the CLI, the settings the MCP settings tools take: one
descriptor per kind with its scope, the Settings pages where a person
makes the same change, its operations and one-shot acts, the pointers of
its secret values, its base risk, its place in the apply order and an
agent-facing description. It starts with the kinds a declaration already
names (providers and their environment credentials, governance policies,
the knowledge embedding, branding, the deployment and a project's
managed instructions and tools); the automation kinds stay with the
automation tools, each with the reason.

It also names every page of Settings by its path, the join key the
platform's coverage guard holds to the settings rail, and the effects a
planned change can carry with the risk each adds.

The suite holds the kinds marked cli to the CLI's resource union, both
at compile time and as parsed, so the CLI never declares a kind the
platform does not describe; orders, areas and secret pointers are
checked as well.
…ared

The detector behind `SECRET_IN_DOCUMENT` (known credential shapes, and an
opaque word under a member named like a credential) moves out of the
engine's document validator into `lib/shared/secret-scan.ts`, so the MCP
settings tools can refuse a key pasted into a setting the same way the
engine refuses one pasted into an automation. `findSecrets` answers every
hit with its dotted path, its pointer and the kind of credential, never
the value; the validator still reports the first five.

The module is pure, and the engine purity guard scans it and allows it
as a sanctioned helper. No behaviour changes: the validator's own suites
pass unchanged, and the new suite pins each shape, the member-name rule,
the locations and that no hit carries a value.
How an MCP surface turns what a domain writer threw into the refusal an
agent reads — a spent budget as RATE_LIMITED with the wait, a coded
AppError in its own words, a domain error with its code, hint and data,
anything else left to be answered as a fault — moves out of the tool
call into `backend/domains/mcp/refusals.ts`, so the settings tools read
their writers' refusals by the same rule. No behaviour changes.
The core of the MCP settings tools, in `backend/domains/mcp/settings/`:
a registry of one handler per settings kind, each reading through its
kind's native read path and writing through its native writer, and the
generic layer every kind shares.

- get: without kinds, the catalog (each kind's scope, operations, acts,
  risk, Settings pages, whether this deployment serves it and what the
  caller's role may do); with kinds, each readable resource with its key
  and native hash, secrets masked; a refused read is answered beside the
  others, never as an empty list.
- plan: each change against a fresh read — create, update, delete, act
  or unchanged — with a member-by-member diff (masked), its effects and
  its risk (the highest of the kind's base risk and its effects'), or the
  refusal; a resource changed twice in one call is refused the second
  time. Planning never writes.
- apply: compare-and-set is mandatory — every changed resource names the
  hash it expects (null for a create), checked before anything is read;
  every change is planned again and every hash compared before the first
  write, so a refusal or a moved resource applies nothing
  (SETTINGS_STALE with the current hash). Changes then run in their
  kinds' order, each writer re-checking its hash under its own lock; the
  first failure stops the rest and the answer lists what landed, what
  failed and what was skipped. A writer that loses the race reads as
  SETTINGS_STALE; one that breaks answers only the request id.
- secrets: a secret reads as {masked, preview}; a change may send that
  masked value back to keep what is stored, and nothing else in a
  secret's place; every string it sends goes through the credential
  detector (SECRET_ARGUMENT_REFUSED names where, never the value).

No kind is registered yet: each arrives with its handler beside its
writer. The suites drive the layer through an in-memory registry whose
writers check hashes the way the native ones do.
Three tools in a new `settings` group put the settings core behind the
MCP endpoint:

- `get_settings` answers the catalog of setting kinds, or the resources
  of the kinds asked for with their keys and native hashes, secrets
  masked;
- `plan_settings` plans up to 32 changes and writes nothing;
- `apply_settings` applies them compare-and-set (`expected` names every
  changed resource's hash), asks the person before every call and draws
  from a new `rest:settings` budget (30 a minute, 60 at once), charged
  after the arguments pass.

A change names its kind, its id and its op; what a kind does not take —
an op, an action, a missing config — is refused with every other
problem as INVALID_ARGUMENTS before anything is read. The server
instructions gain the settings loop; the MCP tab lists the group in
English, German and French; the endpoint page documents the tools, the
access rule and the new codes, and the rate-limit page the budget, in
all three languages. Spec cards MCP-R11 (a call applies only when each
setting is still what was read) and MCP-R12 (no secret in or out) are
held by the core's suites.

Contract 3.28.0: the MCP fingerprint, the schema and skill snapshots and
the OpenAPI document move with it; no REST operation changes. No kind is
served yet, so every kind reads as unavailable until its handler lands
beside its writer.
A new guard reads the settings rail — its rows, and the tabs of the rows
that open tabs (governance, metrics, API) — and holds every page to one
story. A settings kind names the page among its areas, or
`backend/domains/mcp/settings/coverage.ts` says what an agent cannot
change there yet (planned) or why the page holds nothing to change (not
exposed). It also holds the shared list of Settings pages to the rail in
both directions, the mobile overview to the desktop rail, and one story
per page, each reason a sentence.

Ten pages are covered by the kinds described so far, the MCP page holds
nothing to change, and the other twenty-two say what is missing. A page
added to the rail without its story fails the guard.
The policy read and save moved from the governance door into
policy-writer.ts: who may read which policy, the checks a change passes
(its workflow, the role, the expected hash, the schema, the standard
agent's runtime, the sandbox capacity) and the audited write with the file
last. The door answers its refusals exactly as before; another caller can
now check and save a policy by the same rules.
The branding door had no test of its own: a characterization pins the role
gate the Branding page meets (owners and admins; anyone else refused with
ORG_FORBIDDEN and the capability named, before anything is read or saved),
what a save hands the writer and how a writer's refusal is answered. The
gate becomes BRAND-R5, out of the spec's Not yet.
…vice

assertBrandingWriter holds the org-settings capability check the branding
door ran inline, with the same ORG_FORBIDDEN refusal and sentence, so any
caller of the branding writer meets the gate the Branding page meets.
embedding-save.ts now holds who may manage the knowledge configuration,
the save of the embedding model with its compare-and-set, and what follows
it: the documents that failed for want of a model and those without a
vector of the new width go back in the queue, and the websites scan again.
The data-residency door answers exactly as before.
The AI providers page's refresh had no test: a characterization pins what
it answers today. Every provider the organization resolves with a live
model source is listed with its model count, fetched afresh with the
organization's listing key; a failed fetch reads as zero models with its
reason; a member is refused before any catalog is fetched.
management.ts holds who may manage an organization's AI providers and the
refresh of every live model catalog the organization resolves, which the
AI providers door ran inline. The door answers exactly as before.
…l uses

embedding-follow.ts holds which credential edits the resolver reads and
what follows one the embedding model resolves (the documents that failed
on it re-queued, the websites scanning again), which the AI providers door
ran inline after each save. The door answers exactly as before.
Saving an embedding model that differs from the stored one, and removing a
stored one, now each leave one audit row naming the person, with the model
before and after (knowledge_embedding.saved / .removed), written in the
transaction that writes the file, so a failed row writes nothing. A save of
the stored model, or a removal of none, leaves no row. Until now a change of
the model left no trace in the audit log. KNOW-R19, with the labels in en,
de and fr.
A kind's handler now answers what the caller may do through the database
when its gate needs it (access takes the call's context), and the kinds
share one kit beside the registry: the refusal a handler throws, a config
read through the kind's schema that names a field the schema would drop,
the identity of a resource, pages of a listing and the caller as the
writers record them. The handlers are composed in handlers.ts, which
serves none yet.
…nt reads

A settings read masked only the places a kind declares secret, but a
person can paste a key into a policy's header or an instruction in Tale,
and those settings declare none. A read now also masks every string the
credential detector recognises, the detector that already refuses one on
the way in, and a change may send such a mask back to keep what is stored
there; a mask anywhere Tale masked nothing is refused. MCP-R12 says so.
The governance kind reads and changes one policy per key through the
policy writer the Settings pages use: a member reads the policies any
member may read and changes none, an owner or admin every one; a change is
checked as the save checks it (schema, a field the policy lacks, the
standard agent's runtime, the sandbox capacity) and audited by the writer.
A plan says who a change may lock out or sign out and which human approval
it removes. The retention and data subject request policies stay with
their staged workflows in Tale. MCP-R10.
The knowledge-embedding kind reads and saves the organization's model
through the writer the Data residency page uses, behind its owner-or-admin
gate, with its compare-and-set, its audit row and the documents and
websites that follow a save. As a declaration the CLI applies, a change of
the model itself is taken only while the knowledge base is empty, so two
models' vectors never meet in a search; the similarity floor and the
serving limits change at any time. The check a save runs is lifted out of
the writer so a plan runs it too. MCP-R28.
The branding kind reads and saves the accent colour and the image file
names through the writer the Branding page uses, behind its owner-or-admin
gate, with its compare-and-set and its audit row. A file the old colour
field still carries reads as the page shows it, so a read sent back
changes nothing. Images are uploaded in Tale, so a file name a change sets
must name one the organization has uploaded.
The deployment kind reads and saves this deployment's own settings through
the writer the operator's settings use, behind the same gate: an owner or
admin of any organization reads them, an address on the editor allowlist
changes them. Its version conflict is answered as every other stale
setting is, with the hash stored now, and a plan says when a new sandbox
runtime takes effect only after a restart.
…save

checkProviderDefinition answers a definition as the save checks it (its
shape under its name, a name no shipped provider has, endpoints without
credentials that pass the host policy) and providerCredentialCount how many
credentials still name a provider, so a plan can ask both without writing.
The save and the deletion answer exactly as before.
The provider kind reads, saves and removes the providers an organization
defined through the writers the AI providers page uses, behind its owner,
admin or developer gate, with their checks, history and audit rows. A plan
says when a change sends the organization's requests to another endpoint,
refuses removing a provider credentials still name, and the
refresh-catalogs act reads one provider's catalog afresh without repeating
what the provider answered. The catalog refresh is split per provider so
the act and the page's refresh share it.
The provider-credential kind lists every credential of the organization by
provider and name, never with its secret, and creates, edits and removes
them through the writers the AI providers page uses, behind its owner,
admin or developer gate; the documents and websites follow a credential
the embedding model resolves, as after a save on the page. As a
declaration the CLI applies, only a credential that reads its key from an
environment variable is created or changed; one with a key or a
subscription is entered in Tale and may only be removed here. A removal
checks the hash the agent read inside its serializable transaction.
The project-instructions, agent-instructions, agent-tools and
task-instructions kinds read and change through the managed writers a
declaration applied by the CLI goes through, behind each project's and
task's own rules, which a plan checks before anything is written: an
editor role on a project that is not archived, an agent Tale does not
manage, a task the person may work on. Project and agent settings list by
page over the projects the person reads; a task is read by its id. Every
kind the descriptors name is now served, and the composition's type holds
it so.
checkMcpSettingsConfig drives the MCP door against a real database in an
organization of its own: every kind is served, the catalog says what each
role may do, and an owner's agent changes a policy, the branding, a
provider, its environment credential, the embedding model and a project's
instructions, each leaving its page's audit row stamped as coming through
apply_settings, while a member's agent and a stale read are refused. A
credential pasted into a stored policy never leaves a read through a real
kind and survives its masked round trip. MCP-R14 names a setting changed
among the writes it audits; the spec's Not yet now lists the pages no kind
covers.
get_docs takes the topic settings (also tale://docs/settings): how a
change is read, planned and applied, every kind with its config's fields
from the schema its writer checks, every governance policy, what each
effect of a plan means and every refusal, held to the codes the handlers
raise. The server instructions point at it, and the Tale skill gains a
Settings section, its refusal rows and the rule to ask before
apply_settings. The settings contract moves to 3.30.0, the next minor
free across the open branches, with the fingerprints and snapshots.
A new page, Settings over MCP, in English, German and French: what each
kind of setting holds and who may change it, what stays in Tale, how an
agent reads, plans and applies a change with the hash it read, the
effects a plan names, secrets and the refusals an agent meets. Its kinds
table is held to the served kinds by a test. The MCP endpoint page names
the settings reference among the resources and links the page, and the
admin overview tells admins their agents can change many settings.
The MCP suite gains a section for settings: MCP-F9 changes the branding
and turns on password rotation through Claude Code, judging the plan's
effect, the question before apply_settings, the pages after a reload and
the audit rows' Coding agent source; MCP-B1 holds a member's agent to
what a member may change; MCP-B2 refuses a key pasted into the system
prompt without repeating it. The suite's cost moves to 15 boxes. The
error-code map provokes every settings refusal, and the coverage map
names the tests that own the settings tools and kinds.
Only the kit's own config parser calls them, so knip reported them as unused exports.
@yannickmonney
yannickmonney merged commit debac57 into main Oct 10, 2026
@yannickmonney
yannickmonney deleted the feat/mcp-settings branch October 10, 2026 09:34
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
A database restart during an MCP tool call was reported to error
tracking at error level, once per failing call, and the agent got
INTERNAL_ERROR. The catch blocks of callTool (#4592) and of the settings
writer loop (#4685) answered every non-refusal as a fault without asking
db/unavailable.ts, which the REST and app doors have used since #3506.

Both now ask databaseUnavailableCause first, through one helper in
domains/mcp/refusals.ts: such a call writes one warning line, reports
nothing and answers DATABASE_UNAVAILABLE with data.retryAfterMs 5000,
the REST door's Retry-After. A settings write answers it beside what
landed; a resource read, the resource list and a prompt answer -32603
with the code and the wait, never "resource not found". It counts as a
refusal, not a failure. Any other failure keeps INTERNAL_ERROR and its
report, a bare socket error no database client stamped included.

The MCP spec gains MCP-R43 (MCP-R8's example used a database outage as
its fault), the manual suite MCP-B3 and the error-code rows, the Tale
skill, the settings reference and the docs the code, and the contract
moves to 3.50.0.

Closes #4771
tale-review-bot pushed a commit that referenced this pull request Oct 30, 2026
A database restart during an MCP tool call was reported to error
tracking at error level, once per failing call, and the agent got
INTERNAL_ERROR. The catch blocks of callTool (#4592) and of the settings
writer loop (#4685) answered every non-refusal as a fault without asking
db/unavailable.ts, which the REST and app doors have used since #3506.

Both now ask databaseUnavailableCause first, through one helper in
domains/mcp/refusals.ts: such a call writes one warning line, reports
nothing and answers DATABASE_UNAVAILABLE with data.retryAfterMs 5000,
the REST door's Retry-After. A settings write answers it beside what
landed; a resource read, the resource list and a prompt answer -32603
with the code and the wait, never "resource not found". It counts as a
refusal, not a failure. Any other failure keeps INTERNAL_ERROR and its
report, a bare socket error no database client stamped included.

The MCP spec gains MCP-R43 (MCP-R8's example used a database outage as
its fault), the manual suite MCP-B3 and the error-code rows, the Tale
skill, the settings reference and the docs the code, and the contract
moves to 3.50.0.

Closes #4771
Task: TALE-149
yannickmonney pushed a commit that referenced this pull request Oct 30, 2026
A database restart during an MCP tool call was reported to error
tracking at error level, once per failing call, and the agent got
INTERNAL_ERROR. The catch blocks of callTool (#4592) and of the settings
writer loop (#4685) answered every non-refusal as a fault without asking
db/unavailable.ts, which the REST and app doors have used since #3506.

Both now ask databaseUnavailableCause first, through one helper in
domains/mcp/refusals.ts: such a call writes one warning line, reports
nothing and answers DATABASE_UNAVAILABLE with data.retryAfterMs 5000,
the REST door's Retry-After. A settings write answers it beside what
landed; a resource read, the resource list and a prompt answer -32603
with the code and the wait, never "resource not found". It counts as a
refusal, not a failure. Any other failure keeps INTERNAL_ERROR and its
report, a bare socket error no database client stamped included.

The MCP spec gains MCP-R43 (MCP-R8's example used a database outage as
its fault), the manual suite MCP-B3 and the error-code rows, the Tale
skill, the settings reference and the docs the code, and the contract
moves to 3.50.0.

Closes #4771
Task: TALE-149
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
A database restart during an MCP tool call was reported to error
tracking at error level, once per failing call, and the agent got
INTERNAL_ERROR. The catch blocks of callTool (#4592) and of the settings
writer loop (#4685) answered every non-refusal as a fault without asking
db/unavailable.ts, which the REST and app doors have used since #3506.

Both now ask databaseUnavailableCause first, through one helper in
domains/mcp/refusals.ts: such a call writes one warning line, reports
nothing and answers DATABASE_UNAVAILABLE with data.retryAfterMs 5000,
the REST door's Retry-After. A settings write answers it beside what
landed; a resource read, the resource list and a prompt answer -32603
with the code and the wait, never "resource not found". It counts as a
refusal, not a failure. Any other failure keeps INTERNAL_ERROR and its
report, a bare socket error no database client stamped included.

The MCP spec gains MCP-R43 (MCP-R8's example used a database outage as
its fault), the manual suite MCP-B3 and the error-code rows, the Tale
skill, the settings reference and the docs the code, and the contract
moves to 3.50.0.

Closes #4771
Task: TALE-149
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant