Skip to content

Fix the "HTTP with SSE" example #193

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

Conversation

cliffhall
Copy link
Contributor

In README.md

  • Fix the HTTP with SSE example.
  • Declare transport outside of the /sse handler so it can be seen inside the /messages handler

Fixes #187

Motivation and Context

The HTTP with SSE example doesn't work because the transport is declared as a const inside the handler for /sse endpoint and referenced in the handler for the /messages endpoint.

Discovered this while researching #187

Typechecking as it is currently written gives the following message:
Screenshot 2025-03-13 at 7 16 48 PM

You can build it and it will run, but when you attempt a connection, you will get

  await transport.handlePostMessage(req, res);
  ^

ReferenceError: transport is not defined

How Has This Been Tested?

Ran the example with the changes and connected successfully with the Inspector
Screenshot 2025-03-13 at 7 19 38 PM

Breaking Changes

Nope.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

…red as a const inside the handler for /sse endpoint and referenced in the handler for the /messages endpoint.

This fixes modelcontextprotocol#187
@cliffhall cliffhall mentioned this pull request Mar 13, 2025
@cliffhall cliffhall changed the title The HTTP with SSE example doesn't work because the transport is decla… Fix the "HTTP with SSE" example Mar 14, 2025
@cliffhall
Copy link
Contributor Author

This PR has been superseded by #197. Closing.

@cliffhall cliffhall closed this Mar 25, 2025
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.

SSE example is broken
1 participant