Skip to content

feat: support async callbacks for onsessioninitialized and onsessionclosed #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jerome3o-anthropic
Copy link
Member

Summary

  • Updated StreamableHTTPServerTransport to accept both sync and async callbacks for onsessioninitialized and onsessionclosed
  • Changed callback type signatures from (sessionId: string) => void to (sessionId: string) => void | Promise<void>
  • Used await Promise.resolve() to handle both callback types transparently

Test plan

  • Added comprehensive tests for async callback functionality
  • Verified backwards compatibility with sync callbacks
  • Tested error propagation from async callbacks
  • All existing tests continue to pass
  • Lint checks pass

🤖 Generated with Claude Code

…losed

Updated StreamableHTTPServerTransport to support both sync and async callbacks:
- Changed callback types to return void | Promise<void>
- Used await Promise.resolve() to handle both sync and async callbacks
- Added comprehensive tests for async callback functionality
- Errors in callbacks now properly propagate to HTTP responses

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

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

LGTM

Please can you add cases where you'd use async - might be useful for the historic decision making

Copy link
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

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

Seems reasonable, curious if this came from a feature request or if there are any concrete examples of when we'd want to use this?

@jerome3o-anthropic
Copy link
Member Author

Seems reasonable, curious if this was a feature request? Any concrete examples of when we'd want to use an async callback?

Please can you add cases where you'd use async - might be useful for the historic decision making

Yup - sorry I should have added examples / documented in the PR. The motivating use case here is when spinning up / shutting down a session might be happening on a different machine, or require setting up redis channels etc. This is in the example server I'm working on (Will open up the repo v soon for anyone clicking through from here)

@jerome3o-anthropic jerome3o-anthropic merged commit 11e84f0 into main Jul 9, 2025
5 checks passed
@jerome3o-anthropic jerome3o-anthropic deleted the jerome/fix/allow-async-onsession-callbacks branch July 9, 2025 20:04
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.

3 participants