Skip to content

feat(mcp): log the JSON-RPC method and tool name of each MCP call - #592

Merged
artempartos merged 1 commit into
developfrom
artempartos/fix-session-mid-run
Oct 28, 2026
Merged

artempartos merged 1 commit into
developfrom
artempartos/fix-session-mid-run

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Why

When an agent session ends mid-step, the first question is which Flow tools it called and when. The MCP request log line has carried the session (or the personal token's user) since #554, but not what the request was: params are dropped for /mcp and /action_mcp because tool arguments can hold secrets. Working out that a given request was finish_session meant matching broadcasts, signals and SQL to request ids by the second, and calls landing in the same second could not be told apart.

The JSON-RPC method and the tool name hold no secrets. This logs those two and nothing else.

What

  • MCPController#append_info_to_payload adds rpc (the JSON-RPC method) and, for tools/call, tool (params.name). The line reads … session=123 rpc=tools/call tool=finish_session.
  • Lograge adds them only for MCP paths. The credential endpoints and every other request log exactly what they did before.
  • Arguments are still never logged.
  • A value that does not look like a name ([\w./-]{1,128}) is dropped: it comes from the client and lands unescaped in a key=value line, so name: "x session=1" could otherwise forge a field.

Why this cannot break tool calls

  • No new parsing. Rails already parses the JSON body before the action runs, for the instrumentation payload (request.filtered_parameters). This reads the memoized result after the transport has answered, so the body stream the MCP transport reads is untouched.
  • A logging error cannot fail a call. append_info_to_payload runs in an ensure after the tool has executed, so a raise there would turn an executed call into a 500 and the agent would retry its side effects. The extraction rescues and logs nothing instead. A body that is not JSON exercises that path, and the test checks it is answered with the same -32700 as before this change.
  • The response is unchanged. Nothing here touches the response; the integration test runs a real tools/call through the endpoint and asserts both its result and the log fields.

Tests

  • test/integration/request_log_principal_test.rb: covers a real tool call (answered and logged), tools/list (method only), an unknown tool (the name the client asked for is logged), a forged name (dropped) and a body that is not JSON.
  • test/config/lograge_options_test.rb: rpc/tool reach the line for MCP paths only, and are absent when there are none.
  • Local run of every test file that goes through the MCP endpoint (20 files, 234 runs): 0 failures. 3 errors, all page-render tests that need a Vite build the worktree lacks; unrelated. rubocop and brakeman are clean. CI is the full verification.

🤖 Generated with Claude Code

MCP request logs carried the session or user but no params, so telling which
tools an agent session called meant matching side effects (broadcasts, signals,
SQL) to request ids by the second. The method and tool name hold no secrets;
the arguments, which can, are still never logged. A name that does not look
like one is dropped, since it lands unescaped in a key=value line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit 31164c8 into develop Oct 28, 2026
16 checks passed
artempartos added a commit to Hitin/flow that referenced this pull request Oct 28, 2026
* origin/develop:
  docs(workflows): describe workflows as sessions made of steps (AixleHQ#595)
  feat(workflows): open archived workflows read-only in the builder (AixleHQ#594)
  feat(task-comments): let authors delete their own recent comments (AixleHQ#593)
  feat(mcp): log the JSON-RPC method and tool name of each MCP call (AixleHQ#592)
  fix(board): show a run waiting for a session slot as Queued on its card (AixleHQ#591)
  feat(brand): use the new Aixle Flow lockup and route fonts through tokens (AixleHQ#590)
  feat(overview): show tokens used and session time instead of token cost (AixleHQ#589)
  fix(agents): pre-acknowledge Claude Code's cost-threshold notice (AixleHQ#587)
  test(playwright): QA helpers batch 2 (appRequest, readInertiaPage, shot, probeRoutes, signOut) (AixleHQ#586)
  test(playwright): plain-JS QA helpers for browser_run_code on staging (AixleHQ#584)
  feat(runners): add the runners table and the Runner model (AixleHQ#583)
  refactor(feature-flags): plain cached reads, no usage tooling (AixleHQ#579)

# Conflicts:
#	CHANGELOG.md
artempartos added a commit to Hitin/flow that referenced this pull request Oct 28, 2026
* origin/develop:
  docs(workflows): describe workflows as sessions made of steps (AixleHQ#595)
  feat(workflows): open archived workflows read-only in the builder (AixleHQ#594)
  feat(task-comments): let authors delete their own recent comments (AixleHQ#593)
  feat(mcp): log the JSON-RPC method and tool name of each MCP call (AixleHQ#592)
  fix(board): show a run waiting for a session slot as Queued on its card (AixleHQ#591)
  feat(brand): use the new Aixle Flow lockup and route fonts through tokens (AixleHQ#590)
  feat(overview): show tokens used and session time instead of token cost (AixleHQ#589)
  fix(agents): pre-acknowledge Claude Code's cost-threshold notice (AixleHQ#587)
  test(playwright): QA helpers batch 2 (appRequest, readInertiaPage, shot, probeRoutes, signOut) (AixleHQ#586)
  test(playwright): plain-JS QA helpers for browser_run_code on staging (AixleHQ#584)
  feat(runners): add the runners table and the Runner model (AixleHQ#583)
  refactor(feature-flags): plain cached reads, no usage tooling (AixleHQ#579)

# Conflicts:
#	CHANGELOG.md
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