fix(server/stdio): notifications should not return a response (#638)

Currently the `stdio` transport protocol will throw a `ZodError` during
initialization. This is due to Toolbox writing `null` to stdout when it
received a notification. This is not expected hence the `ZodError`
occurs. Per the MCP protocol, notifications do not expect any response.

This fix added a condition to check if the responses is `nil` before
writing to stdout.
This commit is contained in:
Yuan
2025-06-02 16:59:39 -07:00
committed by GitHub
parent 4700dd363c
commit 69d047af46

View File

@@ -106,8 +106,12 @@ func (s *stdioSession) readInputStream(ctx context.Context) error {
// server can continue to run.
s.server.logger.ErrorContext(ctx, err.Error())
}
if err = s.write(ctx, res); err != nil {
return err
// no responses for notifications
if res != nil {
if err = s.write(ctx, res); err != nil {
return err
}
}
}
}