Skip to content

Refactor: Move MCP and A2A parsing to core/parse - #1701

Merged
huang195 merged 11 commits into
rossoctl:mainfrom
huang195:refactor/core-parse-1503
Nov 7, 2026
Merged

huang195 merged 11 commits into
rossoctl:mainfrom
huang195:refactor/core-parse-1503

Conversation

@huang195

@huang195 huang195 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Part of #1437: the P6 item of #1503 (#1688 closed #1503). Phase 2 of the Praxis prep. The inference parser follows in a second PR, stacked on this one.

What this changes

  • New core/parse/mcp and core/parse/a2a. They take plain values and return core/model types:
    • mcp.ParseRequest(method, path, headers, rawBody, paths) and mcp.ParseResponse(body, ext) bool.
    • a2a.ParseRequest(path, headers, rawBody) and a2a.ParseResponse(body, ext).
    • They are built from phase 1's parseMCPRequest and parseA2ARequest, and from the response code of each plugin.
  • The mcp-parser and a2a-parser plugins become thin wrappers (hooks.go). They keep config, Context wiring, the "first response wins" rule, Skip/Observe and their log lines. Their exported API does not change.
  • parsercommon moves from core/plugins/internal/ to core/internal/, because Go's internal rule stops core/parse from importing it there. It now imports core/model, not core/pipeline.
  • One fixture helper, core/internal/parsefixture, replaces the three copies in the parser plugins' fixtures_test.go. It owns the -update flag.
  • Import bans. core/model/imports_test.go now also checks that core/parse/{mcp,a2a} reach neither core/pipeline nor cost/settle / cost/pricing.

How to review

Most new lines are moved code. Read with git diff -M --color-moved main....

Old New Git shows
plugins/a2aparser/plugin.go parse/a2a/a2a.go rename (68%)
plugins/a2aparser/plugin.go (plugin half) plugins/a2aparser/hooks.go new file
plugins/mcpparser/plugin.go (plugin half) plugins/mcpparser/hooks.go rename (50%)
plugins/mcpparser/plugin.go (parse half) parse/mcp/mcp.go new file
plugins/internal/parsercommon/* internal/parsercommon/* renames

With rename detection the diff is +746 / −997 in 29 files.

Behaviour

  • No event, extension or golden changes. The 33 fixture subtests pass, and no testdata/ file changed.
  • Log text changes only for client-controlled values that contain a control rune or a newline. In each new file, every such value is wrapped in SanitizeLogValue.
  • A2A ParseResponse reads the summary before the session id. The old order was the other way. The two steps write different fields, and neither reads what the other writes.

Checks run

  • go vet, gofmt -l and go mod tidy -diff with GOWORK=off in all 8 workspace modules, and tidy -diff in the 3 demos modules.
  • go test -count=1 ./... in core and cmd/agentop.
  • cmd/cortex vet with the full, local, lite and fullcpex profiles. cmd/cortex-envoy build with envoy. core vet with fullcpex.
  • The ban tests fail when a scratch cost/settle import is added to core/parse/a2a.
  • pre-commit run on every changed file.

Deferred review nits

  • core/parse/{mcp,a2a} have no tests of their own. The plugin tests and the goldens cover them.
  • The ban test checks core/pipeline and the cost packages, not core/plugins/.... No such import exists.
  • parsefixture.Run skips an MCP or A2A case that has no request.headers. The old MCP and A2A helpers did the same. Only the inference test checks for this file now. The check can move into Run later.
  • TestFixtureCasesAreComplete writes the response file names again. They are also the keys of parsefixture.responseTypes. A new response type makes the test fail until its list changes.

Assisted-By: Claude (Anthropic AI) [email protected]

Go's internal rule lets only packages under core/plugins/ import
core/plugins/internal/parsercommon. The parser libraries of rossoctl#1503
go in core/parse/, so they cannot import it from there.

This commit moves the package to core/internal/parsercommon with
git mv. It also does these changes:

- Change TokenUsage.Fill to take *model.InferenceExtension. The
  package then does not import core/pipeline.
- Change the import path in the three parser plugins, their tests
  and cpex/cmf_presentation.go. gofmt sorts the new path into a
  different place.
- Update the comments that name the old place: the package
  comment, cost/usage/usage.go, cost/pricing/rates.go and
  cost/pricing/incompletereason_test.go.

There is no change in behaviour.

Part of rossoctl#1437.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
The fixture tests of mcp-parser, a2a-parser and inference-parser had
their own copies of checkFieldPaths, endHead, sseFrames and most of
runFixture. This commit puts one copy in the new package
core/internal/parsefixture. Only tests import it.

- parsefixture.Run runs each case directory that has a
  request.headers file. The caller gives the parser and the
  extension to compare.
- The package owns the -update flag. The three test files do not
  define it now.
- TestFixtureReadersWithoutBlankLine moves to the new package.

The same 33 fixture subtests pass before and after this change, with
the same names. No file under testdata changes, also with -update.

Part of rossoctl#1437.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
rossoctl#1503 asks for parser libraries that take plain values and give
core/model types. This commit moves the MCP parse code from the
mcp-parser plugin to the new package core/parse/mcp.

- git mv moves plugin.go to core/parse/mcp/mcp.go. The plugin half
  is in the new file core/plugins/mcpparser/hooks.go.
- parseMCPRequest is now mcp.ParseRequest.
- The new mcp.ParseResponse reads one response into the extension.
  It sets Err or Result. It returns false when the body has no
  JSON-RPC result or error. The JSON-RPC types stay unexported.
- The plugin keeps the hooks, the config, the "first response wins"
  rule and the log and Observe rows. recordResponse replaces
  applyMCPResponseRPC for the log and the Observe row.
- plugin_test.go uses the string literals of the two synthetic
  method names, because the constants are in the library now.

SanitizeLogValue now wraps these log values: the method and body of
"mcp-parser: payload", the data of "mcp-parser: skipping malformed
SSE data frame", and the method and message of the two response
logs. The log text changes only for a value with a control rune or
a newline. The exported API of mcpparser does not change. The 11
mcp fixture cases pass with no change to testdata.

Part of rossoctl#1437.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
This commit moves the A2A parse code from the a2a-parser plugin to
the new package core/parse/a2a, as the previous commit did for MCP.

- git mv moves plugin.go to core/parse/a2a/a2a.go. The plugin half
  is in the new file core/plugins/a2aparser/hooks.go.
- parseA2ARequest is now a2a.ParseRequest.
- The new a2a.ParseResponse reads the response summary, then
  captures the session id when the extension has none. OnResponse
  and OnResponseFrame both call it, for a whole body and for one
  frame.
- The plugin keeps the hooks, the Skip and Observe rows and
  logA2AFinalized.

OnResponse captured the session id before the summary. ParseResponse
does the summary first. The two steps write disjoint fields, and
neither step reads a field that the other step writes. The doc
comment of ParseResponse tells this.

SanitizeLogValue now wraps the method, sessionId, role and messageId
of "a2a-parser: extracted", and the kind and content of "a2a-parser:
part". The log text changes only for a value with a control rune or
a newline. The exported API of a2aparser does not change. The 13
a2a fixture cases pass with no change to testdata.

core/README.md gets a parse/ row. It names MCP and A2A only, because
inference is not in core/parse yet.

Part of rossoctl#1437.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
rossoctl#1503 says that the parser libraries must not import cost/settle or
cost/pricing. They must also build without the plugin engine, as the
core/model data packages do. This commit extends
core/model/imports_test.go to check both rules.

- core/parse/mcp and core/parse/a2a are in dataOnly, so they must not
  reach core/pipeline.
- The new TestParsersDoNotImportPricing fails when a parser library
  reaches cost/settle or cost/pricing, also through another package.
- The two tests share one go list loop, checkDeps.
- Blank imports of the two packages make the test rebuild when they
  change, so the test cache cannot hide a violation.

Check: a scratch file in core/parse/a2a with an import of cost/settle
makes both tests fail and name core/parse/a2a.

Part of rossoctl#1437.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
parsercommon moved to core/internal, so every package in core can
import it now. Some comments still told the old rule.

- cost/pricing/rates.go and cost/pricing/incompletereason_test.go
  tell why each mirror of parsercommon exists, and that the package
  can import parsercommon now. The code does not change.
- cost/usage/usage.go and parsercommon/kindbits_usage_test.go do not
  say that the kind-bits test is the one place both sets are visible.
  parsercommon/kindbits_usage_test.go also says "outside core", not
  "outside core/plugins".
- parsefixture.go tells that a test package that imports it must not
  define its own -update flag, because two definitions panic at init.

Part of rossoctl#1437.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
git shows core/plugins/a2aparser/hooks.go as a new file. The diff of
core/plugins/mcpparser/hooks.go (renamed from plugin.go) also shows
its debug logs as added lines. CodeQL reads such lines as new log
calls, so this commit wraps their client-controlled values in
SanitizeLogValue:

- a2aparser: the sessionId, finalStatus and error of "a2a-parser:
  response parsed".
- mcpparser: the method and body of "response detail" and
  "streaming frame", the method of "ignoring a later response
  frame", and the frame of "response frame carried no JSON-RPC
  result/error".

The log text changes only for a value with a control rune or a
newline.

It also fixes a comment in core/parse/a2a: extractStreamResponse
folds each event as ParseResponse does for one frame. OnResponseFrame
is in another package now.

Part of rossoctl#1437.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
The previous commit wrapped four debug-log values in
core/plugins/mcpparser/hooks.go. These lines did not change in the
move from plugin.go. The wraps put the similarity of the two files
below the 50% that git needs to show a rename. git then showed
plugin.go as deleted and hooks.go as a new file, and the diff of
the PR became twice as large.

This commit removes those four wraps. The log values are the same
as on the base. The wraps in a2aparser/hooks.go, a new file, stay.

Part of rossoctl#1437.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 30 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a42e098-f89c-4efb-8d03-7d359dfe110a
Commits

Reviewing files that changed from the base of the PR and between d41332a and 7c55834.

Files selected for processing: 29

  • core/README.md
  • core/cost/pricing/incompletereason_test.go
  • core/cost/pricing/rates.go
  • core/cost/usage/usage.go
  • core/internal/parsefixture/parsefixture.go
  • core/internal/parsefixture/parsefixture_test.go
  • core/internal/parsercommon/encoding.go
  • core/internal/parsercommon/kindbits_usage_test.go
  • core/internal/parsercommon/parsercommon.go
  • core/internal/parsercommon/sse.go
  • core/internal/parsercommon/tokenusage.go
  • core/internal/parsercommon/tokenusage_test.go
  • core/model/imports_test.go
  • core/parse/a2a/a2a.go
  • core/parse/mcp/mcp.go
  • core/plugins/a2aparser/fixtures_test.go
  • core/plugins/a2aparser/hooks.go
  • core/plugins/a2aparser/plugin_test.go
  • core/plugins/cpex/cmf_presentation.go
  • core/plugins/inferenceparser/anthropic.go
  • core/plugins/inferenceparser/anthropic_test.go
  • core/plugins/inferenceparser/fixtures_test.go
  • core/plugins/inferenceparser/plugin.go
  • core/plugins/inferenceparser/responses.go
  • core/plugins/inferenceparser/responses_test.go
  • core/plugins/inferenceparser/splittokens_test.go
  • core/plugins/mcpparser/fixtures_test.go
  • core/plugins/mcpparser/hooks.go
  • core/plugins/mcpparser/plugin_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@huang195
huang195 marked this pull request as ready for review November 7, 2026 13:00
@huang195
huang195 requested a review from a team as a code owner November 7, 2026 13:00
rossoctl#1699, the PR this branch was stacked on, is merged. Bring the branch up to date with main.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Fixes review: parsefixture.Run skips a capture with no request.headers, and it reads a missing response file as an empty body.
Files:
- core/plugins/inferenceparser/fixtures_test.go

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Fixes review: the Usage comment said that pricing can import parsercommon. That import makes a test import cycle.
Files:
- core/cost/pricing/rates.go

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

The refactor does what it says. I diffed the moved code against main function by function: mcp.ParseRequest / parseResponse are byte-identical to parseMCPRequest / parseMCPResponse apart from the rename, pipeline.→model. and the added SanitizeLogValue wraps. The A2A response half (extractResponseSummary … parseA2AParts) is identical apart from types and one comment. The A2A ParseResponse reorder is safe: the summary writes FinalStatus/TaskID/Artifact/ErrorMessage, and the session-id capture writes only SessionID. mcp.ParseResponse + recordResponse give the same Err/Result/Observe results as applyMCPResponseRPC, including a body that carries both error and result. No new typed decoder fields, so no strictness regression for wrong-typed client bodies.

What I verified locally (GOWORK=off, head d1d390e):

  • go vet and gofmt -l are clean on parse/, internal/, the three parser plugins and model/. go test passes for those packages and for pipeline/ (33 fixture subtests).
  • The ban tests catch a violation: a scratch cost/settle import in parse/a2a fails both tests, and a scratch cost/pricing import in parse/mcp fails TestParsersDoNotImportPricing.
  • No stale plugins/internal/parsercommon imports remain. The only mention left is a historical plan doc.
  • cost/usage and cost/ledger fail locally, but they fail the same way on main (DST/date-sensitive tests on today's date). These failures did not come from this PR.

One suggestion inline: the shared fixture runner is looser than the old inference-parser runner was. It is not blocking.

Optional follow-up, not for this PR: the response detail / streaming frame debug logs in mcpparser/hooks.go still log the raw body. You kept that on purpose so git shows the file as a rename, and that matches main. A small follow-up could wrap them once the rename has landed.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (core/parse, core/internal, parser plugins, import-ban tests), Docs (README, comments)
Agent/IDE config (.claude/.vscode): none
Commits: 9 commits, all signed-off: yes
CI status: passing

}
}
if respFile == "" {
respFile, contentType = "response.json", "application/json"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: For inference-parser, this shared runner is looser than the runner it replaces. The old inferenceparser/fixtures_test.go globbed testdata/*/* and then failed hard on three things: a missing request.headers, a missing request.json (os.ReadFile + t.Fatal), and a case with no response file ("no response.sse, response.json or response.html"). Now:

  • Run globs <pattern>/request.headers, so a capture dir without a headers file is silently skipped. I checked: a testdata/claude-code/zz-nohead/ holding only request.json gives ok.
  • A missing response file falls back to an empty application/json body here, and readBody turns a missing request.json into an empty body. With -update, a half-copied capture would quietly write a golden from an empty response, not fail.

The defaults suit the hand-built MCP/A2A cases (empty bodies are real cases there). They hide mistakes for the real inference captures. One cheap fix is to let the caller opt in, e.g. a RequireBodies bool option, or a check in the inference TestFixtures that every testdata/*/* dir has request.headers and one response file.

@huang195
huang195 merged commit cc18885 into rossoctl:main Nov 7, 2026
41 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 7, 2026
@huang195
huang195 deleted the refactor/core-parse-1503 branch November 7, 2026 13:34

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

Re-review of the 2 commits since my approval at d1d390e. I re-read the full diff too. Nothing else changed since then: d1d390e..7c55834 touches only inferenceparser/fixtures_test.go and the pricing.Usage comment.

  • c1f3a290 (TestFixtureCasesAreComplete) answers my earlier suggestion about the looser shared runner. I checked that it really fails: a scratch testdata/claude-code/zz-probe/ that holds only request.json fails with two errors, one for the missing request.headers and one for the missing response file. On the real tree it passes, because all 9 captures have headers and one response file. One small gap is noted inline (request.json), and it is not blocking.
  • 7c558348 (the rates.go comment) is correct now. I added a scratch import _ ".../core/internal/parsercommon" to cost/pricing, and go vet ./internal/parsercommon/ reports import cycle not allowed in test through kindbits_usage_test.go → cost/usage (apportion.go) → cost/pricing. That matches the new comment exactly.

What I verified locally (GOWORK=off, head 7c55834): go vet and gofmt -l are clean on cost/pricing, plugins/inferenceparser, internal/... and parse/.... go test passes for the three parser plugins, internal/parsefixture, internal/parsercommon, model, pipeline and cost/pricing. (plugins/tokenbroker/client timed out in TestClient_AcquireToken_DNSFailure. That is the sandbox DNS through the egress proxy, it is unrelated to this PR, and it passes in CI.)

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (fixture completeness test, pricing doc comment; full diff re-checked against the prior review)
Agent/IDE config (.claude/.vscode): none
Commits: 11 commits, all signed-off: yes
CI status: passing

if v, ok := bytes.CutPrefix(line, []byte("data:")); ok {
data = append(data, bytes.TrimPrefix(v, []byte(" ")))
n := 0
for _, name := range []string{"response.sse", "response.json", "response.html"} {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: My earlier comment listed three ways a half-copied capture slips through. This test covers two of them, request.headers and the response file. A capture that has no request.json still passes here, and readBody turns the missing file into an empty request body, so -update would write a golden from it. All 9 current captures have the file, so nothing is wrong today. If you want it covered, one more os.Stat(filepath.Join(dir, "request.json")) next to the headers check would do it. Fine to skip.

huang195 added a commit to huang195/kagenti-extensions that referenced this pull request Nov 7, 2026
rossoctl#1701, the PR this branch was stacked on, is merged. Bring the branch up to date with main.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
huang195 added a commit that referenced this pull request Nov 7, 2026
Bring in main (#1699 merged) through the base branch, P3a (#1701).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Turn the MCP, A2A and inference parsers into libraries, with saved real-traffic test cases

2 participants