Skip to content

Offer MCP as four tool families within 4 KB - #6706

Merged
Sinity merged 8 commits into
integrate-20261101from
mcp-surface-4kb
Nov 2, 2026
Merged

Sinity merged 8 commits into
integrate-20261101from
mcp-surface-4kb

Conversation

@Sinity

@Sinity Sinity commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Every agent session pays for MCP tools/list and the server instructions before it asks anything. The integration build sent a 401.6 KB tools/list (333 KB of it per-tool outputSchema) and 8.2 KB of instructions that repeated every tool description. This PR brings the two together under 4,096 bytes of compact JSON and keeps every MCP capability reachable.

What changed

  • Four tools instead of one per command. polylogue_read, polylogue_context, polylogue_note and polylogue_chat are generated from the command table (Command::tool, commands::Tool). The shape is common command-surface's tool family (feat: add async pipeline, schema registry, and synthetic corpus #78): a call is {operation, arguments, request_id, deadline}, and operation is required when a tool has several rows. arguments is the listed arguments of the tool's rows merged by name, with bare types. An argument that two rows type differently becomes an anyOf naming the rows. Each row checks its own arguments at dispatch. A comment marks the generator to be replaced by OperationTable::mcp_tools when Polylogue adopts feat: add async pipeline, schema registry, and synthetic corpus #78.
  • Unlisted arguments. Options agents rarely need are marked unlisted on their Arg. Examples: read's expansions, format and delivery; cost's month and model; attachment ranges; watch timing. They stay out of the schema but are accepted and checked. explain capabilities lists each row's tool, its complete argument schema, its unlisted arguments and its answer schema, plus the answer envelope's schema once. polylogue manual names every argument.
  • No outputSchema on any tool. Results keep structuredContent.
  • Instructions are a card (docs/agent-manual.md, 555 B as a JSON string). The full guidance moves to docs/agent-guide.md. polylogue manual prints the card, then the guide, then the generated operation reference.
  • Ready calls (next on read and attachment pages) now come in the tool's call form: {name: polylogue_read, arguments: {operation, arguments, request_id, deadline}}.
  • Hints. readOnlyHint comes from the tool's access, and every row of a tool shares that access. destructiveHint is never set. idempotentHint is set except on polylogue_chat, because chat send and backfill start begin a new browser action on every call. openWorldHint is set on polylogue_chat.

Deviations from the brief, agreed with the coordinator

  • timeline and cost stay polylogue_read operations. Their logical-day, calendar and per-model response pages have no query-language equivalent.
  • list is not an operation, since it is sessions where … through query. complete is not an operation either; the protocol's completion/complete covers it.
  • chat list and backfill list are in polylogue_read, not polylogue_chat, because a family's rows share one access.
  • The envelope carries only request_id and deadline. feat: add async pipeline, schema registry, and synthetic corpus #78 will emit only the envelope options a table declares. Rows built from flat arguments take a millisecond deadline only, and deadline: null is refused for them with a typed error.

Deleted

  • One tool per command: Command::mcp, Command::mcp_name and Command::typed_mcp_schema.
  • protocol::operations::McpArguments, replaced by ToolCall.
  • Per-tool outputSchema and the generated command reference in the instructions.
  • MCP's own kind-to-schema mapping. commands::kind_schema is now shared with explain.

Laws and tests

All in crates/polylogue/src/mcp/tests.rs unless noted. The laws are written in docs/agents.md.

  • mcp-surface-size: tools_and_instructions_fit_four_kilobytes.
  • mcp-covers-command-table: every_tool_operation_is_reachable_from_exactly_one_tool.
  • mcp-tool-access-is-uniform: tool_annotations_follow_the_command_table.
  • mcp-instructions-are-the-card: server_instructions_are_the_card_naming_every_tool.
  • mcp-arguments-are-listed-or-explained: every_argument_is_in_its_tool_schema_or_unlisted and typed_operations_declare_every_field_of_their_arguments.
  • mcp-operation-dispatch: a_tool_call_names_one_of_its_operations.
  • mcp-detail-on-demand: capabilities_publish_each_operation_with_its_tool_unlisted_arguments_and_answer, in explain/tests.rs.
  • Round trips through each removed tool now go through the family call. The shared helpers mcp::tests::call and call_as turn a command name into its family call. every_client_answers_the_same_request_identically runs list as a query call and complete through completion/complete, and compares both with the CLI and HTTP.

Changed expectations: mcp_schemas_follow_the_arguments compared each tool's inputSchema with the row's typed schema. It now checks the family schema, as docs/agents.md "MCP server" states: "The input schema lists, under arguments, the arguments of the tool's rows merged by name, each with its bare type".

Verification

  • compile job 474 (-p polylogue --tests): clean, no warnings.
  • focused job 482: 87 of 88 tests passed, including the size gate and reachability. The run hit the 30-minute job timeout after a 29-minute cold build, while read_pages::budgeted_mcp_output_contains_one_bounded_layout_and_no_duplicate_source_records, a long whole-byte read, was still running.
  • focused job 573 on the final head: see the follow-up comment.
  • Measured sizes come from a model of the generator over the command table; the size test asserts them in-process. tools/list is about 3.4 KB and the instructions 555 B, which is under the 4,096 B limit.
  • Not done: the live polylogue mcp measurement after deploy.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AcQETkbTfFMr1hgNJ8A3em

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ⚠️ Failed 2026-11-01T22:38:08.559559Z
We couldn’t complete this review. Comment @codex security review to try again.
0555be4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@Sinity Sinity left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ready-for-train: 2b3e2fc fixes the two web::tests::cancellation failures (ready_call refused operations without an MCP tool, so typed_url("sql") panicked); such ready calls now have a null MCP form. Focused job 608 queued behind the build pause.

Sinity and others added 7 commits November 2, 2026 06:32
Every agent session pays for tools/list and the server instructions before
it asks anything. The integration build sent 401.6 KB (333 KB of per-tool
outputSchema) plus 8.2 KB of instructions that repeated every description.

MCP now offers four tools, generated from the command table in the shape of
command-surface's tool families: polylogue_read, polylogue_context,
polylogue_note and polylogue_chat. A call is {operation, arguments,
request_id, deadline}; arguments are the rows' listed arguments merged by
name with bare types. Rarely needed options are marked unlisted: accepted,
checked by their row, and published by `explain capabilities`, which also
carries each row's answer schema and the answer envelope's schema. Tools
carry no outputSchema. The instructions are a hand-written card of at most
800 bytes; `polylogue manual` appends the generated operation reference.

list is a query form and complete is the protocol's completion method, so
neither is an operation. timeline and cost stay operations, since their
logical-day and per-model pages are not query results.

Deleted: one tool per command, McpArguments, Command::typed_mcp_schema,
Command::mcp_name and the generated reference in the instructions.

Tests that compared each tool's inputSchema with the row's typed schema now
check the family schema, as docs/agents.md "MCP server" states: "The input
schema lists, under `arguments`, the arguments of the tool's rows merged by
name, each with its bare type".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AcQETkbTfFMr1hgNJ8A3em
The full agent guidance moves to docs/agent-guide.md, which `polylogue
manual` prints between the card and the operation reference, instead of
being dropped. MCP tool schemas and `explain` share one kind-to-schema
mapping. polylogue_chat is not marked idempotent, since a chat or backfill
request starts a new browser action. A test ties each typed operation's
argument fields to its declared arguments, and the kept-result test passes
its retry identity beside the arguments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AcQETkbTfFMr1hgNJ8A3em
command-surface lists an array argument as {"type": "array"}; the item
type is in the row's schema that explain publishes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AcQETkbTfFMr1hgNJ8A3em
ready_call refused any operation without an MCP tool, so the HTTP and CLI
forms of a `sql`, `list`, `live` or `notices` call could not be built
(the web cancellation tests build their URLs this way). Such a call now
has a null MCP form and its other forms as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AcQETkbTfFMr1hgNJ8A3em

@Sinity Sinity left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ready-for-train: rebased onto c4ce025 (tree identical to train head 4f339bc); the two new train failures (ai_studio_import_and_drive_title..., claude_account_text::account_and_project_text_import...) pass locally on this tree in focused job 726.

@Sinity Sinity left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ready-for-train (coordinator: identical to train head 4f339bc; its two new failures pass locally and are on the known list)

The slot check took any free reader, and with the second slot idle it
returned before the server saw the disconnect, so the cancellation was
not yet observed. Holding the other slot, as the HTTP disconnect test
does, makes the check wait for the SQL read's slot, which is released
only after its cancellation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AcQETkbTfFMr1hgNJ8A3em

@Sinity Sinity left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ready-for-train: c626ea4 makes no_header_null_sql_has_no_implicit_read_cap_and_disconnect_still_cleans_up deterministic (holds the other reader slot so the slot check waits for the SQL read's own slot, released only after its cancellation); focused job 765: all 10 web::tests::cancellation tests and the ready-call test pass.

@Sinity Sinity left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ready-for-train (coordinator: lane's focused job 765 passed all 10 cancellation tests at this head)

@Sinity
Sinity merged commit ac25e8c into integrate-20261101 Nov 2, 2026
@Sinity
Sinity deleted the mcp-surface-4kb branch November 2, 2026 09:50
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