Skip to content

feat(rails): MCP, app naming and approval previews in the Rails adapter - #52

Closed
ahmad-ajmal wants to merge 9 commits into
mainfrom
feat/transports-rails
Closed

ahmad-ajmal wants to merge 9 commits into
mainfrom
feat/transports-rails

Conversation

@ahmad-ajmal

Copy link
Copy Markdown
Collaborator

The Rails adapter catches up with the reference: the app serves MCP, refuses a call meant for another app, and holds an approval to what the person was shown. It is stacked on #45, #46 and #48: review the Rails commits only until those merge.

What changes

  • Identity publishes transports (from manifest.json) and mcpUrl. A malformed list stops the app from starting; a list without mcp serves no endpoint.
  • X-A2App-App naming another app: 409 app_mismatch.
  • MCP at POST /api/_a2app/mcp/<app id>: the spec's ten tools, word for word. Each call is one request through this adapter's own router. MCP 2026-07-28 and the three handshake revisions, without sessions. No new dependency.
  • Approvals: reason on every 428; a key works only for the caller that asked; a refused key comes with one that works; preview on an operation, with the approval tied to its answer.
  • Starter: clear-done names list-done.
  • Two things it needed. Header values are read as text, as Node reads them: SQLite kept an idempotency key sent as a header apart from the same key sent as a tool argument, so they never matched. Stored keys are converted when the database opens. And the adapter is built at boot, so a declaration it refuses stops the app instead of failing its first request.

Tests

  • ruby lib/a2app_adapter.rb --selftest: ok on Ruby 3.3 (run in the official Docker image: Ruby isn't installed here). Checks were tried against 29 deliberate breakages, all caught.
  • 321 requests sent to this adapter and the reference in each mode: differences traced to the test harness.
  • conformance/starter/run.mjs against a running app: 85/85 in each auth mode, nothing skipped. conformance/multi-user/run.mjs: 77/77.
  • Official MCP clients (@modelcontextprotocol/sdk 1.32.2; @modelcontextprotocol/client 2.4.0 default, auto and pinned to 2026-07-28) in both modes: write, guard refusal, approval, delete.
  • pnpm --filter @a2app/conformance test: 148/148 (it scaffolds and checks every blueprint). CI does not run this adapter's own tests.

Differences from the reference

  • The empty 202 carries Rails' default content type.
  • Already there, left alone: the app's credential hint isn't length-bounded as the reference bounds it. From reading only: Rails' method-override header may be honored on adapter routes; worth its own look.
  • Not run: the Vue build (untouched).

…ose by that order

manifest.json may carry `transports`, an ordered list of cli, mcp and http. The
first is the app's primary channel and the rest are fallbacks; without it the
order is cli, mcp, http. Entries are kinds, never addresses. The gate checks it,
the builder may edit it, toolkit-sync keeps it, `scaffold --transport` puts one
first, and inspect reports it.

Identity gains optional `transports` and `mcpUrl` (published by adapters in a
later change). Arriving by CLI at an app that asks for another transport first
says so. Skills, AGENTS.md and the README say how to choose, and how to operate
over plain HTTP when there is no CLI.

Spec: spec/v0_2/transports.md.
…ame its app

adapter-core serves the app as an MCP server at POST /api/_a2app/mcp/<app id>.
Each tool call is one request through the adapter's own router, so the guard,
scopes, approval, idempotency, rate limits and audit are the ones HTTP callers
meet. Ten tools, the same in every app (spec/v0_2/mcp-tools.json); MCP
2026-07-28 and, without sessions, the three handshake revisions before it. The
caller is a credential, never a browser session.

HTTP callers may name the app they mean (X-A2App-App); another app answers 409
app_mismatch. The CLI names a verified remote app on every call, and reads
identity without its credential. Identity publishes `transports` and `mcpUrl`.

Conformance class D covers the binding, and the starter conformance checks it
against a running app on any stack.
Agents given only a task and an app picked the right transport each time, and
stopped at every refusal. What slowed them is fixed: tools take an entity or
operation by its own name, a declared operation is preferred over a raw write,
the HTTP routes are listed in full, what to do when a scope or an approval is
missing and the person can't be reached, and an MCP server that answers
app_mismatch is another app's.
A destructive operation may name a read-only `preview` that says what it would
do. Its answer comes with the 428, and the key covers it: when the answer
changes, nothing runs, and the caller is shown the new one. Anything else that
changes leaves the approval standing.

Two fixes for every destructive operation: a key works only for the credential
that asked, and a refused key always comes with one that works. A 428 says why
(`reason`: asked, changed, spent, mismatch).

The gate and the adapter refuse a preview that is not one. The sidecar runs an
adopted app's own read route. The CLI shows the preview before the line that
would run the call. The react-node starter's clear-done names list-done.

Spec: spec/v0_2/approvals.md.
The Ruby port of the reference's transports and approvals: identity publishes
the declared transports and the MCP address, a call that names another app is
refused, and the app answers MCP by sending each tool call through its own
router. A 428 says why, its key works for the caller that asked, and a
destructive operation may name a preview its approval is held to; the starter's
clear-done names list-done.

Header values are read as text, as Node reads them, so an idempotency key is
one key over HTTP and MCP (SQLite kept the two apart); keys stored before are
converted. The adapter is built at boot, so a declaration it refuses stops the
app instead of failing its first request.
The read-only check used the name as written and the route decodes it, so a
percent-encoded name ("clear%2Ddone") passed the check and ran. The name is
decoded once, checked, and sent as that one segment. Scopes always applied; what
was missing is the promise a harness relies on when it runs a read-only tool
without asking. Found by the Go port's comparison run.
As in the reference: the read-only check used the name as written and the route
decodes it, so a percent-encoded name passed the check and ran. The name is
decoded once, checked, and sent as that one segment.
@ahmad-ajmal

Copy link
Copy Markdown
Collaborator Author

Replaced by #57, with the same code. The branch is kept.

@ahmad-ajmal

Copy link
Copy Markdown
Collaborator Author

Update: the native adapters are now on the branch feat/native-adapters, not in #57. No PR is open for it yet.

@ahmad-ajmal

Copy link
Copy Markdown
Collaborator Author

The native adapters now have one PR: #58.

@ahmad-ajmal
ahmad-ajmal deleted the feat/transports-rails branch December 2, 2026 11:18
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