Skip to content

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: 6b84f4f

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

This PR includes changesets to release 4 packages
Name Type
agents Major
@cloudflare/ai-chat Major
@cloudflare/codemode Major
hono-agents Major

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: 4d75bb3

Copy link
Contributor

@mattzcarey mattzcarey Jan 16, 2026

Choose a reason for hiding this comment

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

I'm not sure we should be typing these here. These are already defined in the output of wrangler types if I am not mistaken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the quick reply! I want to make sure I understand the concern. Are you saying wrangler types already generates ExportedHandler with a Props parameter? I added Props support to enable typed ctx.props which I don't believe exists in the current wrangler types output. Should these types live elsewhere, or should I be extending the wrangler generated types differently?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe what @mattzcarey meant was that the changes to add the Props parameter was better fit for workerd repo which is where these types come from, instead of duplicating them here.

I've created a PR already there with the changes cloudflare/workerd#5989 so the new types are not needed

}

export function createMcpHandler(
export function createMcpHandler<
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems like a good improvement independently of the types below.

@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

export function createMcpHandler(
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.

Suggested change
Props = unknown
Props extends Record<string, unknown> = Record<string, unknown>


export function createMcpHandler(
export function createMcpHandler<
Env = unknown,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Env = unknown,
Env extends Cloudflare.Env = Cloudflare.Env

*/
export function experimental_createMcpHandler(
export function experimental_createMcpHandler<
Env = 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

* 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

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe what @mattzcarey meant was that the changes to add the Props parameter was better fit for workerd repo which is where these types come from, instead of duplicating them here.

I've created a PR already there with the changes cloudflare/workerd#5989 so the new types are not needed

@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

- 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
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>

4 participants