Skip to content

Conversation

fabio-sassi-spotview
Copy link

Motivation and Context

Using the example code from README:

// Legacy message endpoint for older clients
app.post('/messages', async (req, res) => {
  const sessionId = req.query.sessionId as string;
  const transport = transports.sse[sessionId];
  if (transport) {
    await transport.handlePostMessage(req, res, req.body);
  } else {
    res.status(400).send('No transport found for sessionId');
  }
});

I notice that "await" is not respected

    await transport.handlePostMessage(req, res, req.body);

The reason is a missing await in handlePostMessage 

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

  • [ x] I have read the MCP Documentation
  • [ x] 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

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.

onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;

onmessage is not an Awaitable, so adding await does nothing here.

@fabio-sassi-spotview
Copy link
Author

onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;

onmessage is not an Awaitable, so adding await does nothing here.

Hello @felixweinberger,

Based on my understanding of the code, it seems to me that (async) handlePostMessage calls (async) handleMessage, which then calls without await onmessage.

So if I use await handlePostMessage in the code, the hook is not actually called with await.

@felixweinberger
Copy link
Contributor

onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;

onmessage is not an Awaitable, so adding await does nothing here.

Hello @felixweinberger,

Based on my understanding of the code, it seems to me that (async) handlePostMessage calls (async) handleMessage, which then calls without await onmessage.

So if I use await handlePostMessage in the code, the hook is not actually called with await.

Are you running into an actual issue with the example code? Adding await here should do nothing, given this.onmessage does not return a promise.

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.

2 participants