Skip to content

Split vmcp auth/authz middleware for annotation flow#4115

Merged
JAORMX merged 2 commits intomainfrom
pr3-vmcp-annotation-flow
Mar 12, 2026
Merged

Split vmcp auth/authz middleware for annotation flow#4115
JAORMX merged 2 commits intomainfrom
pr3-vmcp-annotation-flow

Conversation

@JAORMX
Copy link
Copy Markdown
Collaborator

@JAORMX JAORMX commented Mar 12, 2026

Summary

  • The vmcp middleware chain previously composed auth+parser+authz into a single middleware, which meant authz ran before discovery could provide tool annotations. This splits auth and authz so authz runs after discovery, enabling annotation-aware authorization policies.
  • Builds on Add tool annotation context for Cedar/HTTP authz #4102 which added the annotation context plumbing and authorizer integration.

Type of change

  • New feature

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)

Changes

File Change
pkg/vmcp/auth/factory/incoming.go Modified: NewIncomingAuthMiddleware returns 4 values (auth, authz, handler, error) instead of 3. Auth+parser composed; authz returned separately.
pkg/vmcp/auth/factory/incoming_test.go Modified: Updated for 4-return signature, added test for separate authz return
pkg/vmcp/auth/factory/authz_not_wired_test.go Modified: Updated to compose auth and authz separately
pkg/vmcp/server/annotation_enrichment.go New: Middleware that reads tool annotations from discovery context and injects via WithToolAnnotations for authz
pkg/vmcp/server/annotation_enrichment_test.go New: Table-driven tests for backend tools, composite tools, passthrough cases
pkg/vmcp/server/server.go Modified: Added AuthzMiddleware field to Config; inserted authz and annotation-enrichment in middleware chain
cmd/vmcp/app/commands.go Modified: Updated call site for 4-return, passes AuthzMiddleware to server config

Does this introduce a user-facing change?

No — internal middleware reordering. Users benefit when Cedar policies reference tool annotations in vmcp, which now work because authz runs after discovery has populated annotations.

Special notes for reviewers

  • New middleware ordering: auth+parser → audit → discovery → annotation-enrichment → authz → handler. The key change is authz moved from before discovery to after.
  • Annotation enrichment is conditional: Only applied when AuthzMiddleware is configured. No overhead when authz is disabled.
  • Only enriches tools/call: The enrichment middleware is a no-op for all non-tools/call methods.
  • Backwards compatible: When no authz is configured, behavior is identical to before — authzMiddleware is nil and skipped.

Generated with Claude Code

@github-actions github-actions bot added the size/M Medium PR: 300-599 lines changed label Mar 12, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 81.53846% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.86%. Comparing base (cf8b6fa) to head (b2c76b0).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pkg/vmcp/server/server.go 0.00% 4 Missing and 2 partials ⚠️
pkg/mcp/parser.go 0.00% 2 Missing and 1 partial ⚠️
cmd/vmcp/app/commands.go 0.00% 2 Missing ⚠️
pkg/vmcp/auth/factory/incoming.go 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4115      +/-   ##
==========================================
+ Coverage   68.84%   68.86%   +0.01%     
==========================================
  Files         458      459       +1     
  Lines       46274    46324      +50     
==========================================
+ Hits        31859    31899      +40     
- Misses      11953    11959       +6     
- Partials     2462     2466       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

JAORMX and others added 2 commits March 12, 2026 09:35
The vmcp middleware chain previously composed auth+parser+authz into a
single middleware, which meant authz ran before discovery could provide
tool annotations. This splits them so authz runs after discovery.

- NewIncomingAuthMiddleware returns auth and authz separately (4 values)
- Add annotation enrichment middleware between discovery and authz
- Authz now sees tool annotations from discovered capabilities
- New middleware ordering: auth+parser → audit → discovery →
  annotation-enrichment → authz → handler

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update stale middleware-chain comments in server.go to reflect the new
ordering that includes annotation-enrichment and authz layers. Add an
early-return guard to ParsingMiddleware so the double-application (once
in auth, once in server.go for the no-auth case) skips re-reading the
request body. Use the mcp.MethodToolsCall constant instead of a string
literal to satisfy goconst, and add a clarifying comment on why
convertAnnotations intentionally omits Title.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@JAORMX JAORMX force-pushed the pr3-vmcp-annotation-flow branch from e423040 to b2c76b0 Compare March 12, 2026 07:35
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Mar 12, 2026
@JAORMX JAORMX merged commit 3dda4b5 into main Mar 12, 2026
49 of 51 checks passed
@JAORMX JAORMX deleted the pr3-vmcp-annotation-flow branch March 12, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants