feat: add context parameter to prompt handlers#857
Conversation
Use signature introspection to support both old-style (args-only) and new-style (context, args) prompt handler signatures, matching the pattern used by tool handlers. Context is sourced from the existing per-request ContextVar and passed through to prompt handlers that accept it. Closes ArcadeAI#707 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… heuristic Fixes false positives where handlers with keyword-only params or extra defaulted params were incorrectly identified as context-accepting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6599bc2. Configure here.
| result = await self._prompt_manager.get_prompt( | ||
| message.params.name, | ||
| message.params.arguments if hasattr(message.params, "arguments") else None, | ||
| context=context, |
There was a problem hiding this comment.
Context not forwarded through Prompts.get() call path
Medium Severity
The _prompt_manager.get_prompt call in context.py:557 (Prompts.get()) was not updated to pass the context parameter, even though self._ctx (the Context object) is readily available. Prompt handlers that accept context will receive None when invoked through this path (e.g., a tool calling a prompt via context.prompts.get()), while the same handler called via the MCP protocol (_handle_get_prompt) correctly receives context.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6599bc2. Configure here.
|
This pull request has been automatically marked as stale because it has had no activity for 14 days. It will be closed in 14 days if no further activity occurs. If this is still relevant, please leave a comment or remove the stale label. |
|
This pull request has been closed due to inactivity. Feel free to reopen it if it is still relevant. |


Summary
Closes #707
contextparameter to prompt handlers for SDK parity with TypeScriptinspect.signatureintrospection to detect handler arity, supporting both old-style(args)and new-style(context, args)signatures for backward compatibilityContext(fromget_current_model_context()) throughPromptManager.get_prompttoPromptHandler.get_messagesCallable[[dict[str, str]], list[PromptMessage]]toCallable[..., list[PromptMessage]]across prompt manager, server, and MCPAppNew prompt handler pattern
Test plan
Generated with Claude Code
Note
Low Risk
Additive API with signature-based dispatch; existing single-argument handlers are unchanged, and context is only injected on the prompts/get path.
Overview
Adds optional per-request
Contextto MCP prompt handlers so Python SDK behavior aligns with tools and the TypeScript SDK.PromptHandlerusesinspect.signatureat registration time: handlers with two required positional parameters (afterself) are invoked as(context, args); single-parameter handlers still receive onlyargs.PromptManager.get_promptandMCPServer._handle_get_promptpasscontextfromget_current_model_context()into that path. Handler type hints widen toCallable[..., list[PromptMessage]]on the manager, server, andMCPAppprompts API.Tests cover context-aware async/sync handlers, backward compatibility when context is omitted or ignored, default handlers, and the introspection helper.
Reviewed by Cursor Bugbot for commit 6599bc2. Bugbot is set up for automated code reviews on this repo. Configure here.