⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

feat: add Props type parameter to ExportedHandler for typed ctx.props#784

Open
HueCodes wants to merge 7 commits intocloudflare:mainfrom
HueCodes:fix/501-exported-handler-props
Open

feat: add Props type parameter to ExportedHandler for typed ctx.props#784
HueCodes wants to merge 7 commits intocloudflare:mainfrom
HueCodes:fix/501-exported-handler-props

Conversation

@HueCodes
Copy link
Contributor

Add a Props type parameter to ExportedHandler so that ctx.props can be properly typed when using satisfies ExportedHandler<Env, Props>.

  • Add enhanced ExportedHandler<Env, Props, QueueHandlerMessage, CfHostMetadata>
  • Add Props-aware handler types (ExportedHandlerFetchHandler, etc.)
  • Export types from main entry point and agents/types
  • Add generic params to createMcpHandler and McpAgent.serve()

Fixes #501

Add a Props type parameter to ExportedHandler so that ctx.props can be
properly typed when using `satisfies ExportedHandler<Env, Props>`.

- Add enhanced ExportedHandler<Env, Props, QueueHandlerMessage, CfHostMetadata>
- Add Props-aware handler types (ExportedHandlerFetchHandler, etc.)
- Export types from main entry point and agents/types
- Add generic params to createMcpHandler and McpAgent.serve()

Fixes cloudflare#501
@changeset-bot
Copy link

changeset-bot bot commented Jan 16, 2026

🦋 Changeset detected

Latest commit: 88de792

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@784

commit: 88de792

@threepointone
Copy link
Contributor

I'll need to review this

Copy link
Contributor

@deathbyknowledge deathbyknowledge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the changes in in /mcp but remove the rest

* Defaults to Streamable HTTP transport.
*/
static serve(
static serve<Env = unknown, Props = unknown>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here please

@HueCodes
Copy link
Contributor Author

Thanks for the review! I understand now that I was unnecessarily re inventing types that already exist. Will fix this later today. Really appreciate the feedback

HueCodes and others added 2 commits January 29, 2026 19:38
- Update MCP handler type constraints per reviewer suggestion:
  - Env extends Cloudflare.Env = Cloudflare.Env
  - Props extends Record<string, unknown> = Record<string, unknown>
- Remove ExportedHandler types (will be added to workerd repo instead)
- Update tests to work with new type constraints
- Update changeset description
Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs fixes to pass CI

Remove overly strict type constraints that required Env to extend
Cloudflare.Env and Props to extend Record<string, unknown>. This
allows users to pass ExecutionContext without explicit type parameters.

Fixes TypeScript errors in examples that use `env: unknown` or
`ExecutionContext` without type parameters.
@HueCodes
Copy link
Contributor Author

HueCodes commented Feb 2, 2026

CI failures are unrelated infrastructure issues (missing
id-token: write permission and app-id config). Actual code checks passed. If I am mistaken let me know and I will change whatever is needed! Thanks

Env extends Cloudflare.Env = Cloudflare.Env,
Props extends Record<string, unknown> = Record<string, unknown>
>(
export function createMcpHandler<Env = unknown, Props = unknown>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I preferred this to default to Cloudflare.Env, why was it necessary to change it back to unknown? trouble with typescript?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with unknown thinking it would be better for type safety and was trying to make it more flexible. So you didn’t need to use Cloudflare.Env and was thinking they’d be unknown until the user specifies. What is your preference? Looking back now I can see why you’d specify in a cloudflare repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make ExportedHandler support setting ExecutionContext<Props>

5 participants