feat(mcp): cap financial-statement-analysis at the columns a filing presents - #1377
Conversation
…resents The second half of the MCP response economy. financial-statement-analysis was a median 24K characters per call in the Filing Ladder runs because it returned every period its hypercube holds: on the 3M FY2024 10-K income statement, 8 of 11 period keys were the quarterly figures from the notes, and the balance sheet carried 2021 and 2022 instants from the equity roll-forward. Each row also repeated the qname as `name` and three null fields. - an annual form (10-K / 20-F / 40-F) defaults the period filter to `annual` when the caller gave none; the balance sheet keeps the query's instant default and a 10-Q is left unfiltered, since its quarter and year-to-date columns share end dates and the cap bounds them alone - `periods` caps the distinct end dates kept, newest first — default 2 for the balance sheet, 3 for the flow statements, max 100 — and the result carries the period keys it kept plus `periods_omitted` and a tip to raise the cap when older dates were cut - fact rows drop `name` (the local part of `qname`) and null fields - `limit` now applies within the kept periods Local MMM FY2024 10-K, before -> after: income statement 50,043 -> 18,531 chars (174 -> 78 facts), balance sheet 25,617 -> 15,837, cash flow 30,938 -> 23,952. The REST view op is unchanged. Design: local/RoboSystems/specs/ai-operators/mcp-response-economy.md §3 (5) Claude-Session: https://claude.ai/code/session_01VQNt2hdNJqbJwfoSRshaXo
|
Change classification: normal — platform or application code changed. A normal change carries a documented automated review on this pull request before merge, in place of a second human approver. The |
|
@claude please review this PR |
|
Claude finished @jfrench9's task in 3m 0s —— View job Reviewing PR #1377
PR SummaryTitle: feat(mcp): cap financial-statement-analysis at the columns a filing presents Caps Existing Review FeedbackOnly a My ReviewIssues (should fix before merge)
Suggestions (non-blocking)
Questions
VerdictNEEDS_DISCUSSION — the implementation is clean, well-documented, and the described before/after measurements are convincing, but issue #1 (small explicit Note on environment: |
Review findings on the period cap (PR #1377): - The graph fetch took the caller's `limit` (x3, ceiling 1,000) and runs newest-first before the cap, so a small explicit `limit` could starve the cap of older periods with no `periods_omitted` to say so. The query now always takes the 1,000-row ceiling and `limit` applies after the cap; a fetch that hits the ceiling is flagged `rows_truncated` with a tip, since the oldest kept period may then be incomplete. - `name` was dropped on the assumption it is always the qname's local part. That held on every SEC row checked but not on a tenant graph, where rs-gaap elements carry a readable label there. `name` now stays when it differs from the local part and is dropped only when redundant. - `periods: 0` fell back to the default through `or`; it is now floored to 1 like any other out-of-range value, and only an absent argument takes the default. Claude-Session: https://claude.ai/code/session_01VQNt2hdNJqbJwfoSRshaXo
|
Decision: fix now, in c682d4c. All three points addressed.
@claude please re-review on the new commit. |
|
Claude finished @jfrench9's task in 1m 11s —— View job Re-reviewing PR #1377 (commit c682d4c)
Re-review of c682d4cAll three points from the prior review are fixed correctly. 1. 2. 3. Other callers unaffected: Minor, non-blocking: the Environment note: VerdictLGTM — the fix directly addresses the correctness gap (the query no longer lets a small |
Summary
The second half of the MCP response economy (
local/RoboSystems/specs/ai-operators/mcp-response-economy.md§3, change 5), following #1376.financial-statement-analysiswas a median 24K characters per call in the Filing Ladder runs because it returned every period its hypercube holds: on the 3M FY2024 10-K income statement, 8 of 11 period keys were the quarterly figures from the notes, and the balance sheet carried 2021 and 2022 instants from the equity roll-forward. Each fact row also repeated the qname asnameplus three null fields. The tool now answers with the columns a filing presents, and says what it left out.Changes
financial-statement-analysis—middleware/mcp/tools/financial_statement_tools.pydefault_period_type: when the caller gives noperiod_type, an annual form (10-K / 20-F / 40-F, per the resolver'sANNUAL_FORMS) defaults the filter toannual. The balance sheet keeps the query's instant default; a 10-Q is left unfiltered because its quarter and year-to-date columns share end dates, so the cap below bounds it without a filter. An explicitperiod_typestill wins.cap_periods: a newperiodsargument caps the distinct period end dates kept, newest first — default 2 for the balance sheet, 3 for the flow statements, max 100. The result carriesperiods(the keys the facts span, newest first) and, when older end dates were cut,periods_omittedwith a tip to raise the cap.compact_fact: rows dropname(always the local part ofqname— verified on the live output) and null fields.limitapplies within the kept periods (dedup → cap → limit).inputSchemastate all of the above.Docs —
middleware/mcp/README.md: the tool table cell and the paragraph beneath it describe the cadence default, the cap, and the row shape.Measured on the local MMM FY2024 10-K (before = every period, old row shape):
Not changed: the REST view op at
routers/extensions/roboledger/views.pystill returns every period and the full row model. This is a tool-layer change for the reader with the budget, as in #1376.Breaking Changes
None. MCP response body and tool definition only; no REST or SDK surface moves. Under the ChatGPT plugin's rule the new
periodsparameter is a definition change that rides the next plugin version's review, alongside #1376's parameters.Testing
just test-code— passed (ruff, format, basedpyright, cf-lint).tests/middleware/mcp/tools/test_financial_statement_tools.pyplus the description contract, manager helpers, MCP execute, and roboledger views suites — 335 passed. New tests cover the cadence default per form and statement, the cap (newest end dates, keys sharing an end date counting once, empty input), row compaction, and the tool end to end (annual default sent to the query, explicitperiod_typewinning, balance sheet not forced annual, the 3-period and 2-period defaults withperiods_omitted, theperiodsargument and its bound,limitwithin the kept periods).secgraph produced the table above.just test-allnot run in-session.Certification
🤖 Generated with Claude Code
https://claude.ai/code/session_01VQNt2hdNJqbJwfoSRshaXo