arcade-mcp icon indicating copy to clipboard operation
arcade-mcp copied to clipboard

Python: Add context parameter to prompt handlers for SDK parity

Open TheMostlyGreat opened this issue 1 year ago • 0 comments

Summary

TypeScript arcade-mcp standardized handler signatures to always include ctx. Python should consider the same for consistency across SDKs.

Current Python Patterns

# Tool - has context
@tool
async def get_user(context: Context, user_id: str) -> dict:
    return db.get(user_id)

# Prompt - no context
async def greeting(args: dict[str, str]) -> list[PromptMessage]:
    return [PromptMessage(role="user", content=f"Hello {args['name']}")]

Proposed Python Pattern

# Tool - has context (unchanged)
@tool
async def get_user(context: Context, user_id: str) -> dict:
    return db.get(user_id)

# Prompt - add context (context first, matching tools)
async def greeting(context: Context, args: dict[str, str]) -> list[PromptMessage]:
    # Now can access logging, etc.
    return [PromptMessage(role="user", content=f"Hello {args['name']}")]

Why

  1. Consistency - All handlers have context available
  2. Logging - Prompts can use context.log
  3. Future-proofing - If prompts need secrets/auth later, no breaking change

TypeScript Decision

TypeScript uses:

  • Tools: ({ input, ctx }) => ...
  • Prompts: ({ args, ctx }) => ...
  • Resources: ({ uri, params, ctx }) => ...

Breaking Change?

Yes. Current handler type in arcade_mcp_server/managers/prompt.py:

Callable[[dict[str, str]], list[PromptMessage]]

Changing to context-first would break existing prompts.

Mitigation: Use introspection to support both signatures:

sig = inspect.signature(handler)
if len(sig.parameters) == 2:
    result = handler(context, args)  # new style
else:
    result = handler(args)  # backward compatible

Action

Consider adding optional context parameter to Python prompt handlers for parity. Use signature introspection for backward compatibility.

TheMostlyGreat avatar Dec 03 '25 16:12 TheMostlyGreat