Title: TypeVar-bound ADCPHandler for typed ToolContext subclasses · Issue #223 · adcontextprotocol/adcp-client-python · GitHub
Open Graph Title: TypeVar-bound ADCPHandler for typed ToolContext subclasses · Issue #223 · adcontextprotocol/adcp-client-python
X Title: TypeVar-bound ADCPHandler for typed ToolContext subclasses · Issue #223 · adcontextprotocol/adcp-client-python
Description: Summary ToolContext supports subclassing (the docstring in adcp.server.base explicitly invites it for multi-tenant agents carrying typed adapter handles, testing hooks, etc.). The context_factory hook lets downstream return their subclas...
Open Graph Description: Summary ToolContext supports subclassing (the docstring in adcp.server.base explicitly invites it for multi-tenant agents carrying typed adapter handles, testing hooks, etc.). The context_factory h...
X Description: Summary ToolContext supports subclassing (the docstring in adcp.server.base explicitly invites it for multi-tenant agents carrying typed adapter handles, testing hooks, etc.). The context_factory h...
Opengraph URL: https://github.com/adcontextprotocol/adcp-client-python/issues/223
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeVar-bound ADCPHandler for typed ToolContext subclasses","articleBody":"## Summary\n\n`ToolContext` supports subclassing (the docstring in `adcp.server.base` explicitly invites it for multi-tenant agents carrying typed adapter handles, testing hooks, etc.). The `context_factory` hook lets downstream return their subclass at runtime. But the static-type story stops there: every `ADCPHandler` method signature declares `context: ToolContext | None`, so handlers that take a subclass-specific field have to `cast()` or `isinstance()` at every call site.\n\nArchitect on PR #219 review:\n> The docstring encourages subclassing, but nothing rewards it — the factory return type is `ToolContext`, not `TContext = TypeVar(bound=ToolContext)`. Handlers that subclass still get `ToolContext` in their type hints. Add the TypeVar; it's a one-line change that turns the encouragement into a contract.\n\nThe architect undersold the change size (it's more than one line because `ADCPHandler` has 57+ method signatures), but the intent holds.\n\n## Proposed fix\n\n```python\nTContext = TypeVar(\\\"TContext\\\", bound=ToolContext)\n\nclass ADCPHandler(ABC, Generic[TContext]):\n async def get_products(\n self, params: GetProductsRequest | dict[str, Any], context: TContext | None = None\n ) -> Any: ...\n```\n\nSubclasses parameterize: `class SalesAgentHandler(ADCPHandler[SalesAgentContext])`. Factories that return `SalesAgentContext` narrow the handler's inbound type. No runtime behavior change.\n\n## Tradeoffs\n\n- Every existing subclass gains the option to parameterize but must keep working without it (default `TContext = ToolContext`). mypy may need a few `# type: ignore` touches during migration.\n- 57+ method signatures across `ADCPHandler`, `GovernanceHandler`, `ContentStandardsHandler`, `SponsoredIntelligenceHandler`, `BrandHandler`, `TmpHandler`, `ComplianceHandler` each need the TypeVar threaded through. Invasive but mechanical.\n- Downstream that does `isinstance(context, MyContext)` today still works; the TypeVar just adds compile-time checks.\n\n## Context\n\nTracked from PR #219 expert architecture review. Deferred because the surgery touches every handler method signature — better to ship as its own PR than bundled with the tenant-scoping fix. Landing after #220 (advertised-tools gate) reduces the set of method signatures that need touching.","author":{"url":"https://github.com/bokelley","@type":"Person","name":"bokelley"},"datePublished":"2026-04-20T06:04:38Z","url":"https://github.com/adcontextprotocol/adcp-client-python/issues/223"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:04f67a45-9347-43c5-c521-d1fed8f83239 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1AE:63875:BC166F:FA7BF5:6B00F26F |
| html-safe-nonce | 51ffd2cb252e92eff7ec900f405483208cf4298f933183d620cbc7098337a4af |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUFFOjYzODc1OkJDMTY2RjpGQTdCRjU6NkIwMEYyNkYiLCJ2aXNpdG9yX2lkIjoiNzkzNjUxNjA2MzQzMTI5MTUwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7ae0288912b797699c7c7c3016c10a9e65263a89a729c0f9497b10284be50aef |
| hovercard-subject-tag | issue:4293463665 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/adcontextprotocol/adcp-client-python/223/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9a57eca2d68362351a32d2e051491a0f4bb7a6007825beea9eba534502ee23f2/adcontextprotocol/adcp-client-python/issues/223 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9a57eca2d68362351a32d2e051491a0f4bb7a6007825beea9eba534502ee23f2/adcontextprotocol/adcp-client-python/issues/223 |
| og:image:alt | Summary ToolContext supports subclassing (the docstring in adcp.server.base explicitly invites it for multi-tenant agents carrying typed adapter handles, testing hooks, etc.). The context_factory h... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bokelley |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/adcontextprotocol/adcp-client-python git https://github.com/adcontextprotocol/adcp-client-python.git |
| octolytics-dimension-user_id | 221690821 |
| octolytics-dimension-user_login | adcontextprotocol |
| octolytics-dimension-repository_id | 1090305973 |
| octolytics-dimension-repository_nwo | adcontextprotocol/adcp-client-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1090305973 |
| octolytics-dimension-repository_network_root_nwo | adcontextprotocol/adcp-client-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width