Repository navigation
MCP follow-ups: propose_field scope, /mcp brake and thread caps, read-only pin, dev /mcp, live agent thread, class-aware note (#22) - #68
Merged
Conversation
…the draft-caller sibling check (#22) propose_field left a table that is neither live nor drafted to Apply, so an in-app turn or an MCP token could file a card for a table of another tenant or one that does not exist. It now answers ENTITY_NOT_FOUND, as propose_layout and propose_records do; a table proposed earlier in the turn or the MCP thread still takes a field. The sibling check of a dependent picklist already reads with the caller's context since #40, so on a delivered project it judges the builder's draft. Nothing pinned it: a unit test with a reader that shows the draft only to a ReadDraft Caller, in a turn and through RunTool, and an integration test over a real /mcp on a delivered project with the builder's draft value. The option-parity cases now name a table tenant-A has; two of them proposed onto tenant-B's table and were buffered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MCP and the in-app builder run every tool through toolExecutor; the tool names were pinned (read or propose_* only), but nothing stopped the executor from gaining a dependency that writes. The pin walks what the executor is built from, plus the probes it reaches by asserting its reader to AccessProbeCarrier, and fails on any interface method that is not a read verb and on any func or channel. A second test reads the package source so a new assertion on the reader must join the walk. A third proves the pin reports a writer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… card's size (#22) /mcp sits outside /api/v1, so none of the API's limiters reached it: every unauthenticated nxm_ guess cost an indexed SELECT with nothing slowing it, and a key holder had no request budget and could grow its thread without end, each proposal re-reading the whole thread. middleware.MCPRateLimit sits on the /mcp route, built on the API's sliding window. A token not yet seen working spends its client IP's lookup budget (APIKEY_PROBE_MAX_PER_MIN, as the nxk_ brake); a token the handler answered with a 2xx spends its own budget (DATA_RATE_LIMIT_PER_MIN, as an API key on the data plane), so the real agents behind one address never wait on a prober. A 401 forgets the token. Refusals are the canonical RATE_LIMITED 429. The thread takes at most 200 turns (THREAD_FULL, reads still work) and one proposal's row at most 256 KiB (PROPOSAL_TOO_LARGE); both refuse before anything is written. Tests: the brake in unit and against the real handler and token store on MySQL; the caps in mcpserver; main.go's wiring pinned like the other brakes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every MCP propose tool, and every proposal's result, told the agent that a human "applies it to drafts and publishes it". An access card is applied at once, behind a confirm; relationships, approvals, work queues and records take effect when applied too. The result note now reads the class of the card it filed (metaversion.ClassOf on its change envelope): a draft type goes to drafts once the project is delivered and reaches users when published; any other takes effect as soon as it is applied. The tool descriptions and the server instructions say only what holds for every class: a human reviews and applies the card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… agent (#22) On next dev with a relative API base, mcpEndpoint() prints the dev origin + /mcp, and nothing served it: a contributor copied a claude mcp add line that could not connect. The dev proxy behind app/api/v1/[...path] moves to lib/devProxy.ts, taking the upstream path, and app/mcp uses it too (GET, POST, DELETE: the streamable HTTP methods). Same rules as before: Origin stripped, the answer mirrored, 404 outside development; the demo's Caddy already routes /mcp to the API before Next. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The builder opens an MCP key's thread from Kết nối agent (MCP); when the agent proposed again, the open thread did not change until it was reopened. McpConnect now hands openThread the key's expiry. Until then the thread re-reads itself on focus and every 5 s while the tab is visible, and stops after 10 minutes with nothing new (a focus wakes it); an expired key stops it. Read-back turns keep their m_<seq> ids, so what the builder already applied stays applied across a re-read. A turn sent from this tab stops the re-read, because the server's copy would rename that turn's cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pin caught the method #23's fix added to the access probes. It is one SELECT of the admins and operators holding the named roles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oes (#22) Every TestMCP_ flow (scope matrix, parallel proposals, settled replay, revocations) now runs behind the brake at its default budgets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and the note says so (#22) Verifier LOW on #68: the note read only ClassOf's Kind, so a propose_relationship card (DirectUntraced, NewHidden) was told it "takes effect as soon as it is applied", while the customer sees a new N-N relation only after a publish, as the Studio card's footer says. A new table or field (Draft, NewHidden) was told it "goes to drafts", but it is created hidden. The note now has three effects: applies at once (access, approvals, work queues, records), created at apply and hidden from the customer until a publish (a new document of a NewHidden type), or goes to drafts (an edit of a draft type). Pinned per envelope kind the builder tools write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eplaces the message (#22) Verifier LOW on #68: the own-turn guard ran before the read. When a read was out as the builder pressed Enter, the server copy (without the new message) replaced the local turns and the message just sent vanished. The read now lands through a state updater that judges the turns as they are then, and drops itself if the builder sent a turn meanwhile. Tests pin the race and the three guards: a hidden tab does not read and showing it reads again, a turn of the builder's own stops the re-read, and a late read never lands in another thread opened meanwhile. Each was seen red with its guard removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tOrCreate (#22) Verifier LOW on #68: the source check matched only reader.(Name), so a package-qualified or pointer target (e.reader.(services.MetadataWriter), e.reader.(*readerWithAccessProbes).MetadataReader.(X)), an alias or a type switch slipped past; and Get*/Find* admitted GetOrCreate and FindOrCreate. The check now parses the package: every type assertion and type-switch case to anything but plain data must be listed with a reason (today AccessProbeCarrier, UserTokenLedger, *replayer). A method name passes only if it starts with a read verb and carries no write word anywhere in it. A sample source pins each shape the scan must catch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rakes see clients (#22) Verifier LOW on #68: behind Caddy every request reaches the API from Caddy's address, and TRUSTED_PROXY_CIDRS was unset, so every per-IP brake (login, SSO, failed nxk_ and nxm_ lookups) keyed one bucket for all clients: one prober spent everyone's budget. docker-compose.yml fixes the default network's subnet (10.213.47.0/24, NEXUS_SUBNET to change it) and the api trusts X-Forwarded-For from it. Caddy writes that header itself. Checked: docker compose config renders both, and a Caddy-only stack came up on 10.213.47.0/24 with Caddy at 10.213.47.2. Tests: behind the proxy a guesser no longer spends another client's budget, and a wiring test keeps the two compose defaults equal and parseable. Documented in .env.example, README and SECURITY.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
doxuta
added a commit
that referenced
this pull request
Oct 27, 2026
…ps at the logger #70 gave toolExecutor a *zap.Logger and AccessProbes two probes (PacksOf, AggregateScalar) on a base without #68's read-only pin, so main fails the pin since both landed. Both probes are SELECTs and are named as reads; the logger is a listed sink the walk does not enter, and the catch test proves a zapcore.Core reached another way is still reported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
doxuta
added a commit
that referenced
this pull request
Oct 27, 2026
…#72) * feat(ai): stream completions with usage and fold the stream into one answer (#30 item 8) The gateway asks for stream + stream_options.include_usage and folds the event stream back into the ChatResponse the agents, the recorder and replay already read: text and refusal text joined, tool-call arguments joined by index, finish/stop reasons and the last usage kept. A gateway that ignores stream and answers one JSON body is read as before. An error event, a stream cut before it finished or a non-JSON chunk is a 502; a stall is a 504. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): a streamed tool call without arguments reads as {} (#30 item 8) Claude streams no argument piece for a call that takes none, so the fold gave "" and 9router refused the next call that sent it back (400 tool_use.input: Input should be an object). A whole answer carries "{}"; the fold now does too. Found by the first live recorded turn. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(ai): foldStream errors carry their package prefix; doc reflowed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(bench): the measured cost of one app with streamed usage (#30 item 8) One recorded app-helpdesk turn on Claude Opus 5.5 through 9router: 107,305 input tokens (179 uncached, 103,158 cache read, 3,968 cache write) and 1,779 output, about $0.08 warm and $0.34 cold at list prices. The streamed prompt total is the whole input plus 9router's 2,000 per call; the cache split comes from 9router's own log because its OpenAI-shape usage drops it. The env example says calls are streamed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): size the default daily token budget in whole-input tokens (#30 item 8) Streamed usage moves sys_ai_runs.prompt_tokens from the uncached remainder to the whole input, about 17x on a builder turn (measured 115,084 tokens a turn, was ~8,000). The 200,000 default then admitted 2 builder turns a tenant a day instead of 26. 3,000,000 admits 27, pinned by a test against the measured turn. The budget is documented in .env.example and passed through docker compose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): a stream without its finish or its usage is a gateway error; an index-less tool call opens on a new id [DONE] alone no longer finishes an answer (partial tool arguments were accepted), and a stream that closes after the finish with neither its usage nor [DONE] is a 502 instead of an answer that escapes the budget. A proxy that streams parallel tool calls without an index gets one call per id instead of one merged call. .env.example says what happens with a gateway that rejects stream_options. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(ai): the read-only pin names PacksOf and AggregateScalar and stops at the logger #70 gave toolExecutor a *zap.Logger and AccessProbes two probes (PacksOf, AggregateScalar) on a base without #68's read-only pin, so main fails the pin since both landed. Both probes are SELECTs and are named as reads; the logger is a listed sink the walk does not enter, and the catch test proves a zapcore.Core reached another way is still reported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #22 asks for six MCP follow-ups, and a seventh was added in a comment. Each one is fixed or measured below. The verification proves every fix.
Items
propose_field: the caller's drafts, and the caller's tenantcheckAddFieldRefs(ctx, …)now receives the caller's context instead ofcontext.Background(). Nothing pinned it, so this PR adds tests:RunTool, the MCP entry point./mcpon a delivered project. The builder addsholdtostatusas a draft, and a dependent value keyed onholdis accepted.ENTITY_NOT_FOUND. This is the same answerpropose_layoutandpropose_recordsgive./mcp./mcpbrake and thread capsmiddleware.MCPRateLimitsits on the/mcproute inmain.goand is built on the API's sliding window (memRateLimiter).APIKEY_PROBE_MAX_PER_MIN, the same one thenxk_probe brake uses.DATA_RATE_LIMIT_PER_MIN. Real agents behind one address therefore never wait on a prober's budget.429 RATE_LIMITEDwithRetry-After.THREAD_FULLand tells the agent to ask for a new key. Reads still work.PROPOSAL_TOO_LARGE). Before this, the SDK's 4 MiB body limit was the only bound.TestMCP_integration router now carries the brake at its default budgets, asmain.godoes.main.gowiring is pinned like the other brakes.tools_readonly_pin_test.gowalks whattoolExecutoris built from, plus theAccessProbesit reaches throughAccessProbeCarrier. It fails on any interface method that is not a read verb, and on any func or channel.PrivilegedHolders, which Access follow-ups: propose_access asks only for named roles' admins, role audit rows name the role, list_roles grants (also MCP), ?app= ghost cell, ChangeList wraps (#23) #66 added. It is a SELECT, so it is now named in the allowlist (8846582).next dev/mcpapp/api/v1/[...path]moved tolib/devProxy.ts, which takes the upstream path.app/mcp/route.tsuses it for GET, POST and DELETE. It returns 404 outside development, as before.openThread.m_<seq>ids, so cards already applied stay applied.metaversion.ClassOffrom the card's change envelope:Item 6, measured on this branch after #58 and #66
ai.ToolDefinitions()sent per model call (26 tools)propose_entity,propose_field,propose_edit_field<…)tools/list(26 tools)No change was made to what the model reads:
propose_field.optionswould change what an MCP client sees when it loads tools one at a time (deferred tool search). It cannot be checked here without a live model.Verification
ENTITY_NOT_FOUNDbranch removed, pluscontext.Background()put back. Red in unit and in the MCP integration test.step 4: 401; want 429). Caps disabled: red. Wiring pin withProbeMax: 0: red.toolExecutor. Red./mcpproxied to/api/v1/mcp. Red.next dev --webpackwithNEXT_PUBLIC_API_BASE=/api/v1and its own API on a throwaway DB seeded byseed-demo.py. The "agent" was a plain JSON-RPC client; no model was called. Output:ui-shots.mjs): overflow 0, page errors 0.ai.ToolDefinitions()is unchanged (only the MCP-side note changed), and neither cassette callspropose_field. CI ran it anyway, and both the vi and en replays pass (below).Gates (last lines)
gofmt -l .→ emptygo vet ./...→ okgo test ./...→ exit 0go build ./cmd/server/→ okbash scripts/run-integration.sh -race -run '(?i)(mcp|propose|ratelimit|tool)' -timeout 50m ./internal/ai/ ./internal/mcpserver/ ./internal/handlers/ ./internal/middleware/→run-integration: PASS=511 SKIP=0 go-test-exit=0-race -run 'TestMCP_'→run-integration: PASS=20 SKIP=0 go-test-exit=0python3 scripts/check-orphan-endpoints.py --strict→✅ Không có endpoint mồ côi.npx tsc --noEmit→ oknpx vitest run --changed origin/main→Tests 1244 passed (1244)npx eslinton the 9 touched files → okCI on dbedc59, before the LOW fixes (all 7 checks pass)
-race)test -race, build, orphan gate)Verifier LOWs, fixed on this branch (48137c4, 7cf0b0f, ee988ab, 7b8217d)
NewHidden(48137c4). The note after a proposal now has three effects:TestProposedNote_FollowsTheChangeClassPerKindchecks 16 kinds of envelope.TestProbe_NotePerKind, relationship, field and entity now get the hidden-until-publish note.AccessProbeCarrier,UserTokenLedgerand*replayer.e.reader.(services.MetadataWriter);e.reader.(*readerWithAccessProbes).MetadataReader.(MetadataReader);GetOrCreate,FindOrCreateandListAndPurgefail.docker-compose.ymlfixes the network's subnet:10.213.47.0/24by default,NEXUS_SUBNETto change it.TRUSTED_PROXY_CIDRSset to that subnet. Caddy writesX-Forwarded-Foritself.docker compose configrendersTRUSTED_PROXY_CIDRS: 10.213.47.0/24andsubnet: 10.213.47.0/24, and both followNEXUS_SUBNET=10.99.1.0/24.10.213.47.0/24with Caddy at10.213.47.2.TestMCPRateLimit_BehindTheProxyEachClientHasItsOwnBudget).TestComposeTrustsItsOwnNetworkkeeps the two compose defaults equal and parseable..env.example,README.mdandSECURITY.md.Gates after the LOW fixes (7b8217d)
gofmt -l .→ emptygo vet ./...→ okgo test ./...→ exit 0go build ./cmd/server/→ okrun-integration.sh -race -run '(?i)(mcp|propose|ratelimit|tool)' -timeout 50m(ai, mcpserver, handlers, middleware) →run-integration: PASS=514 SKIP=0 go-test-exit=0check-orphan-endpoints.py --strict→✅ Không có endpoint mồ côi.tsc→ okvitest run --changed origin/main→Tests 1248 passed (1248)eslinton the 9 touched files → okNot done
propose_fieldon a table proposed in an earlier chat turn and not yet applied is now refused, aspropose_layoutalready does. Within one turn, or within one MCP thread, it is accepted.Closes #22
🤖 Generated with Claude Code