feat: support context decorator in MCP controllers#458
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces context parameter injection support for MCP (Model Context Protocol) prompts, tools, and resources. It updates metadata builders, metadata models, and the MCPServerHelper to resolve and inject the context parameter index. Additionally, it integrates AsyncLocalStorage in the service worker register to store and retrieve the fetch context. The feedback recommends adding error handling to the unawaited transport.handleRequest call to prevent unhandled promise rejections, and using optional chaining when validating the ctx object in test fixtures to avoid potential runtime TypeErrors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (16)
📝 WalkthroughWalkthroughThis PR adds ChangesMCP Context Parameter Injection
Sequence Diagram(s)sequenceDiagram
rect rgba(173, 216, 230, 0.5)
Note over MCPControllerRegister,MethodInfoUtil: Metadata build time
MCPControllerRegister->>MCPControllerToolMetaBuilder: build(clazz, method)
MCPControllerToolMetaBuilder->>MethodInfoUtil: getMethodContextIndex(clazz, method)
MethodInfoUtil-->>MCPControllerToolMetaBuilder: contextParamIndex
MCPControllerToolMetaBuilder-->>MCPControllerRegister: MCPToolMeta { contextParamIndex }
end
rect rgba(144, 238, 144, 0.5)
Note over MCPControllerRegister,ControllerMethod: Request invocation time
MCPControllerRegister->>MCPServerHelper: new MCPServerHelper({ getContext: () => currentContext })
MCPServerHelper->>MCPServerHelper: buildToolArgs(args, toolMeta, hasSchema)
MCPServerHelper->>MCPServerHelper: getContext?.() → ctx
MCPServerHelper->>MCPServerHelper: newArgs[contextParamIndex] = ctx
MCPServerHelper->>ControllerMethod: Reflect.apply(method, target, newArgs)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
core/controller-decorator/src/impl/mcp/MCPControllerPromptMetaBuilder.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. core/controller-decorator/src/impl/mcp/MCPControllerResourceMetaBuilder.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. core/controller-decorator/src/impl/mcp/MCPControllerToolMetaBuilder.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.
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. Comment |
Checklist
npm testpassesAffected core subsystem(s)
Description of change
Summary by CodeRabbit
Release Notes
New Features
@Context() decorator.Tests