Skip to content

Python: Add context parameter to prompt handlers for SDK parity #707

@TheMostlyGreat

Description

@TheMostlyGreat

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions