Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .mcpx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
},
"fff": {
"command": "/home/user/.local/bin/fff-mcp",
"args": []
"args": [],
"mcpx": {
"readOnlyTools": ["find_files", "grep", "multi_grep"]
}
},
"chrome-devtools": {
"command": "npx",
Expand Down Expand Up @@ -69,11 +72,17 @@
},
"fff-nix": {
"command": "/home/user/.local/bin/fff-mcp",
"args": ["/home/user/code"]
"args": ["/home/user/code"],
"mcpx": {
"readOnlyTools": ["find_files", "grep", "multi_grep"]
}
},
"fff-worktree": {
"command": "/home/user/.local/bin/fff-mcp",
"args": ["/home/user/.local/share/opencode/worktree"]
"args": ["/home/user/.local/share/opencode/worktree"],
"mcpx": {
"readOnlyTools": ["find_files", "grep", "multi_grep"]
}
},
"codedb": {
"command": "node",
Expand Down
15 changes: 15 additions & 0 deletions home/common/mcpx-settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,32 @@
];
"command" = "npx";
};
# readOnlyTools (#6116): fff-mcp publishes no tool annotations, so
# the specification's defaults made every search a possibly
# destructive write and the write-policy gate (default ask)
# refused them all in headless/API sessions, where the
# confirmation question has no answerer. All three fff tools are
# searches; the operator declares them read-only here.
"fff" = {
"args" = [ ];
"command" = "/home/user/.local/bin/fff-mcp";
"mcpx" = {
"readOnlyTools" = [ "find_files" "grep" "multi_grep" ];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the cascade binary alongside the new configuration

On the configured fleet deployment, services.mcpx.package deliberately uses the cascade's package rather than this checkout's build (home/common/default.nix:1163–1168). However, flake.lock still pins that cascade's mcpx-src to 031cde20f71c2fafa068c47b69e68175b72994a5, whose parser lacks ReadOnlyTools and rejects unknown mcpx keys using DisallowUnknownFields. A fleet switch therefore feeds this new configuration to an incompatible daemon, preventing it from starting. Update the cascade source pin alongside this configuration so the selected service binary includes the new parser support.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by the cascade pin bump tracked in #6492: developing-today-forks/opencode#1911 bumped the fork mcpx-src pin 031cde2 → bcc0901 (the first code rev line whose parser carries ReadOnlyTools, via your finding PR #6265 merge 4e6cdb9), and #6750 bumped code's opencode pin to the fork merge rev, moving the transitive mcpx-src node to bcc0901. Verified on the laptop: the cascade build at the new pin parses the live rendered mcpx config, while the old-parser binary refuses the same file with server "fff": its "mcpx" block has no key "readOnlyTools". Full evidence on #6492.

};
};
"fff-nix" = {
"args" = [ "/home/user/code" ];
"command" = "/home/user/.local/bin/fff-mcp";
"mcpx" = {
"readOnlyTools" = [ "find_files" "grep" "multi_grep" ];
};
};
"fff-worktree" = {
"args" = [ "/home/user/.local/share/opencode/worktree" ];
"command" = "/home/user/.local/bin/fff-mcp";
"mcpx" = {
"readOnlyTools" = [ "find_files" "grep" "multi_grep" ];
};
};
"gopls-mcp-server" = {
"args" = [
Expand Down
36 changes: 36 additions & 0 deletions pkgs/mcpx/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,42 @@ annotation-trust rules unchanged -- and the floor never weakens a
`deny`. Under `ask` the policy has already asked once, so no call is
asked about twice.

### Operator-declared read-only tools (`readOnlyTools`)

The gate reads a tool's classification from its annotations, and many
real servers publish none -- fff, whose tools are all searches, is
one. The specification's defaults then make every call a possibly
destructive write, so under `ask` a headless caller (an API session,
a script -- the normal fleet mode) can never run them at all: the
confirmation question has no answerer, and every call comes back as
the gate's error (#6116).

The operator can declare specific tools read-only in a server's
`mcpx` block, by exact name:

```json
{ "mcpServers": { "fff": { "command": "...", "mcpx": { "readOnlyTools": ["find_files", "grep", "multi_grep"] } } } }
```

A declared tool is classified read-only whatever its annotations say
(or do not say): the write policy does not gate it in any mode, and
the destructive floor does not ask about it. The declaration is the
operator's own word in their own configuration, which is why it is
trusted -- a server cannot declare its own tools read-only this way,
and a remote server's annotations still clear nothing (#2191). Names
are exact, never patterns, and the declaration covers only the tools
listed: a tool the server adds later, under a new name, is gated by
the defaults until the operator lists it too. Listing a tool that
actually writes is the operator's mistake to make -- and theirs
alone; nothing infers the list.

When the gate does refuse a call -- an unanswered confirmation, a
denied write -- the refusal is typed, not a generic execution
failure: HTTP 403 with a `code` in the error body
(`confirmation_required` for an unconfirmed call,
`write_policy_denied` for a policy denial), so a caller can tell
"the gate refused this" apart from "the tool ran and failed".

This gate is an operator consent gate, not the autonomy dial
(`docs/decisions/0002-autonomy-dial.md`): the dial bounds what mcpx
does on its own, the write policy bounds what a caller may do to the
Expand Down
6 changes: 5 additions & 1 deletion pkgs/mcpx/docs/consumer.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ idle time, pid — because a choice without that is not a choice.

**Destructive confirmation** (`elicit.confirmDestructive`, off). Before a call
to a tool that may be destructive: annotated `destructiveHint: true`, or (the specification's default) not annotated `readOnlyHint: true` or `destructiveHint: false`. This is the step a
human-driven client has and a script does not.
human-driven client has and a script does not. A tool the operator
declared in the server's `readOnlyTools` (#6116) is pre-authorized
and never asked about: the declaration is the answer, given in
configuration ahead of time, which is the only answer a headless
caller can give.

The two disagree about what a silent deadline means, deliberately. An
unanswered disambiguation takes `elicit.disambiguateDefault`, which is `new` —
Expand Down
42 changes: 42 additions & 0 deletions pkgs/mcpx/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ type Extras struct {
// server alone: ask, allow or deny (#1979). Empty means inherit the
// daemon mode.
WritePolicy string `json:"writePolicy,omitempty"`
// ReadOnlyTools names tools the operator declares read-only for
// this server (#6116): exact tool names, no patterns. The
// declaration is the operator's own word in their own config --
// the one classification input mcpx trusts outright, unlike a
// server's annotations, which a remote server can lie about
// (#2191). Many real servers publish no annotations at all (fff
// is one), and the specification's defaults then read every call
// as a possibly destructive write, so under policy.write=ask a
// headless caller -- which has nobody to answer the gate's
// question -- could never run a search tool. A declared tool is
// classified read-only by the write policy gate and clears the
// elicit.confirmDestructive floor. A tool that is not listed
// keeps the specification's defaults exactly; listing a tool
// here is a claim the operator is responsible for, and it never
// extends to a tool added later under a new name.
ReadOnlyTools []string `json:"readOnlyTools,omitempty"`
// ArgumentRules constrains calls by their arguments (#1986): keys
// are tool patterns matched exactly as Tools/ExcludeTools match,
// values are JSON Schema objects a call's arguments must validate
Expand Down Expand Up @@ -503,6 +519,11 @@ type Resolved struct {
// daemon policy.write setting (#1979).
WritePolicy string

// ReadOnlyTools is this view's operator-declared read-only tools
// (#6116): the pool block's names and the server's own, resolved
// at Resolve time. See Extras.ReadOnlyTools.
ReadOnlyTools []string

// ArgumentRules is this server's compiled argument rules (#1986):
// the pool block's rules and the server's own, compiled at Resolve
// time so a bad pattern or schema is a load-time error. Consumed by
Expand All @@ -515,6 +536,22 @@ type Resolved struct {
Runtime func(name string) (string, bool)
}

// DeclaresReadOnly reports whether the operator declared this tool
// read-only for this server in local configuration (#6116). Exact
// names only: a pattern here could silently widen to a tool the
// operator never saw, which is the failure the gate exists to stop.
func (r *Resolved) DeclaresReadOnly(tool string) bool {
if r == nil {
return false
}
for _, name := range r.ReadOnlyTools {
if name == tool {
return true
}
}
return false
}

// SecretNames are the secrets this server requires: its own list and every
// tool's requiresSecret, sorted, without repeats.
func (r *Resolved) SecretNames() []string {
Expand Down Expand Up @@ -875,6 +912,7 @@ func (c *Config) Resolve(name string) (*Resolved, error) {
Tools: allow,
ExcludeTools: deny,
WritePolicy: pick(ex.WritePolicy, d.WritePolicy),
ReadOnlyTools: append(append([]string{}, d.ReadOnlyTools...), ex.ReadOnlyTools...),
ArgumentRules: rules,
Profiles: append(append([]string{}, d.Profiles...), ex.Profiles...),
Tags: append(append([]string{}, d.Tags...), ex.Tags...),
Expand Down Expand Up @@ -1116,6 +1154,10 @@ func mergeExtras(near, far Extras) Extras {
near.StartTimeout = pick(near.StartTimeout, far.StartTimeout)
near.Namespace = pick(near.Namespace, far.Namespace)
near.WritePolicy = pick(near.WritePolicy, far.WritePolicy)
// Declarations accumulate across layered files, as
// ExtraIncludeTools does: a nearer file adds its servers' tools
// to the farther file's list rather than replacing it (#6116).
near.ReadOnlyTools = concat(far.ReadOnlyTools, near.ReadOnlyTools)
near.Description = pick(near.Description, far.Description)
near.Prelude = pick(near.Prelude, far.Prelude)
if len(near.Tools) == 0 {
Expand Down
52 changes: 52 additions & 0 deletions pkgs/mcpx/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,55 @@ func TestResolveCarriesTags(t *testing.T) {
t.Fatalf("resolved toolTags = %v", r.ToolTags)
}
}

// #6116: readOnlyTools in a server's mcpx block resolves onto the
// view, by exact name: a listed tool is declared read-only, an
// unlisted one is not, and a server with no declaration declares
// nothing.
func TestResolveCarriesReadOnlyTools(t *testing.T) {
c := &config.Config{MCPServers: map[string]*config.Server{
"a": {Name: "a", Command: "x", Mcpx: &config.Extras{
ReadOnlyTools: []string{"find_files", "grep"},
}},
"b": {Name: "b", Command: "x"},
}}
r, err := c.Resolve("a")
if err != nil {
t.Fatal(err)
}
if !r.DeclaresReadOnly("find_files") || !r.DeclaresReadOnly("grep") {
t.Fatalf("resolved readOnlyTools = %v, want find_files and grep declared", r.ReadOnlyTools)
}
if r.DeclaresReadOnly("wipe") {
t.Fatal("an unlisted tool must not be declared read-only")
}
rb, err := c.Resolve("b")
if err != nil {
t.Fatal(err)
}
if rb.DeclaresReadOnly("find_files") {
t.Fatal("a server with no readOnlyTools declared a tool read-only")
}
}

// The declaration survives the JSON wire form, which is how an
// operator actually writes it.
func TestReadOnlyToolsFromJSONConfig(t *testing.T) {
dir := t.TempDir()
p := write(t, dir, "c.json", `{
"mcpServers": {
"fff": { "command": "fff-mcp", "mcpx": { "readOnlyTools": ["find_files"] } }
}
}`)
c, err := config.Load(p)
if err != nil {
t.Fatal(err)
}
r, err := c.Resolve("fff")
if err != nil {
t.Fatal(err)
}
if !r.DeclaresReadOnly("find_files") {
t.Fatalf("readOnlyTools from JSON did not resolve: %v", r.ReadOnlyTools)
}
}
17 changes: 16 additions & 1 deletion pkgs/mcpx/internal/daemon/callerr.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ func (r *Registry) repairAutonomy(ctx context.Context) string {
// finding as data, for a caller that would rather act on a field than parse
// a sentence -- which is also what a repair step needs to start from.
type CallErrorBody struct {
Error string `json:"error"`
Error string `json:"error"`
// Code is the machine-readable kind of a daemon-side refusal
// (#6116): "confirmation_required" when the confirmation gate
// refused a call nobody confirmed, "write_policy_denied" when
// the write policy refused it. Empty for every other failure --
// a tool that ran and failed carries Upstream instead -- so a
// caller can branch on the gate without parsing Error's text.
Code string `json:"code,omitempty"`
Diagnostics []diagnose.Diagnostic `json:"diagnostics,omitempty"`
// Upstream is the JSON-RPC error the server answered with, when the
// failure was one. A relay needs the code and data, not the sentence:
Expand Down Expand Up @@ -227,6 +234,14 @@ func callDiagnostics(err error) []diagnose.Diagnostic {

func callErrorBody(err error) CallErrorBody {
body := CallErrorBody{Error: err.Error(), Diagnostics: callDiagnostics(err)}
var notConfirmed ErrNotConfirmed
var writeDenied ErrWriteDenied
switch {
case errors.As(err, &notConfirmed):
body.Code = "confirmation_required"
case errors.As(err, &writeDenied):
body.Code = "write_policy_denied"
}
if code, msg, ok := upstreamFault(err); ok {
body.Upstream = &UpstreamError{Code: code, Message: msg, Data: upstreamData(err)}
}
Expand Down
42 changes: 40 additions & 2 deletions pkgs/mcpx/internal/daemon/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ func describeInstance(in pool.InstanceStatus) string {
// ---- confirm a destructive call ----

// ErrNotConfirmed is returned when a destructive call was not approved.
//
// It is a typed refusal, not a tool failure (#6116): failureStatus
// answers it 403 and callErrorBody carries code
// "confirmation_required", so a caller -- above all a headless one,
// which can never answer the question -- can tell "the gate refused
// this call" apart from "the tool ran and failed" (a 502 with an
// upstream error) instead of quoting the gate text as a result.
type ErrNotConfirmed struct {
Tool string
Reason string
Expand All @@ -434,7 +441,27 @@ func (e ErrNotConfirmed) Error() string {
// An unanswered question refuses the call. That is the opposite of the
// disambiguation default, and for the opposite reason: there, doing nothing
// is safe; here, doing nothing is the destructive thing.
func (r *Registry) confirmDestructive(ctx context.Context, p *pool.Pool, tool string, cc config.CallContext) error {
// declaredReadOnly reports whether the operator declared this tool
// read-only for this server in local configuration (#6116): the
// per-server readOnlyTools list, read from the requested server's
// view for the same reason the write policy override is -- pools are
// shared between aliases, and the declaration belongs to the name
// the caller asked for. The operator's own declaration is trusted
// outright, as the locally declared stdio server's annotations are
// (#2191); a server cannot declare its own tools read-only this way.
func (r *Registry) declaredReadOnly(server, tool string) bool {
view, ok := r.View(server)
return ok && view.DeclaresReadOnly(tool)
}

func (r *Registry) confirmDestructive(ctx context.Context, p *pool.Pool, server, tool string, cc config.CallContext) error {
if r.declaredReadOnly(server, tool) {
// The operator declared this tool read-only (#6116): a
// pre-authorized call, not a destructive one, so there is
// nothing to confirm -- in any session mode, including a
// headless one with nobody to answer.
return nil
}
if !r.consumer.ConfirmDestructive || r.broker == nil {
return nil
}
Expand Down Expand Up @@ -566,7 +593,8 @@ func (r *Registry) applyWritePolicy(ctx context.Context, p *pool.Pool, server, t
tools = fresh
}
for _, candidate := range tools {
if candidate.Name == tool && policy.Classify(candidate.Annotations).ReadOnly {
if candidate.Name == tool && (policy.Classify(candidate.Annotations).ReadOnly ||
r.declaredReadOnly(server, tool)) {
return policy.Decision{}, false
}
}
Expand Down Expand Up @@ -655,6 +683,16 @@ func (r *Registry) applyWritePolicy(ctx context.Context, p *pool.Pool, server, t
break
}
}
if r.declaredReadOnly(server, tool) {
// The operator declared this tool read-only in local
// configuration (#6116). That declaration outranks the
// server's annotations -- including their absence, which
// the specification's defaults read as a possibly
// destructive write and which is what gated manifestly
// read-only search tools (fff.find_files) in headless
// sessions, where the gate's question has no answerer.
class = policy.Classification{ReadOnly: true}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor read-only declarations when recording unknown outcomes

When an operator-declared read-only tool without readOnlyHint times out or loses its connection after dispatch, callWithLedger in registry.go still classifies it using only the annotation-based toolReadOnly helper. Consequently, a declared search such as fff.grep returns ErrUnknownOutcome and persists a server-wide block on subsequent non-read-only calls until manually cleared, despite the new declaration classifying it as read-only here. Apply the requested server's declaration to the post-dispatch ledger classification as well, not just the gate and existing-block exemption.

Useful? React with 👍 / 👎.

}

decision := policy.Evaluator{}.Evaluate(policy.Input{
Mode: parsed,
Expand Down
10 changes: 9 additions & 1 deletion pkgs/mcpx/internal/daemon/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,7 @@ func failureStatus(err error) int {
var hidden HiddenTool
var secret SecretRequired
var denied ErrWriteDenied
var notConfirmed ErrNotConfirmed
var argDenied ErrArgumentRuleDenied
var unknownOutcome ErrUnknownOutcome
switch {
Expand All @@ -2227,6 +2228,13 @@ func failureStatus(err error) int {
// The write policy refused the call: a permission answer, not
// a bad request and not an upstream failure.
return http.StatusForbidden
case errors.As(err, &notConfirmed):
// The confirmation gate refused the call (#6116): nobody
// confirmed it -- in a headless session, nobody could. That
// is a permission answer like the write policy's, not an
// upstream failure; answering 502 here made the gate
// indistinguishable from a tool that ran and broke.
return http.StatusForbidden
case errors.As(err, &secret):
// A conflict with the state of the daemon, not a fault in the request
// and not a failure of the server: it can succeed once a value exists.
Expand Down Expand Up @@ -2432,7 +2440,7 @@ func (r *Registry) resolveAndGuard(ctx context.Context, p *pool.Pool, server, to
// Not asked by the write policy: the destructive floor still
// gets its say. Under ask the policy already asked once, and
// asking twice about one call would be noise, not consent.
if err := r.confirmDestructive(ctx, p, effTool, cc); err != nil {
if err := r.confirmDestructive(ctx, p, server, effTool, cc); err != nil {
return config.ResolvedScope{}, "", nil, err
}
}
Expand Down
Loading