Skip to content

Commit 0bcb168

Browse files
committed
fix: response error when tool execution failed
1 parent a999157 commit 0bcb168

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

internal/core/sse.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,11 @@ func (s *Server) handlePostMessage(c *gin.Context, conn session.Connection) {
430430
)
431431
switch protoType {
432432
case cnst.BackendProtoHttp:
433-
result = s.callHTTPTool(c, req, conn, params)
433+
result = s.callHTTPTool(c, req, conn, params, true)
434+
if result == nil {
435+
// Error already handled by callHTTPTool
436+
return
437+
}
434438
case cnst.BackendProtoStdio, cnst.BackendProtoSSE, cnst.BackendProtoStreamable:
435439
transport := s.state.GetTransport(conn.Meta().Prefix)
436440
if transport == nil {

internal/core/streamable.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ func (s *Server) handleMCPRequest(c *gin.Context, req mcp.JSONRPCRequest, conn s
292292
)
293293
switch protoType {
294294
case cnst.BackendProtoHttp:
295-
result = s.callHTTPTool(c, req, conn, params)
295+
result = s.callHTTPTool(c, req, conn, params, false)
296+
if result == nil {
297+
// Error already handled by callHTTPTool
298+
return
299+
}
296300
case cnst.BackendProtoStdio, cnst.BackendProtoSSE, cnst.BackendProtoStreamable:
297301
transport := s.state.GetTransport(conn.Meta().Prefix)
298302
if transport == nil {

internal/core/tool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func (s *Server) fetchHTTPToolList(conn session.Connection) ([]mcp.ToolSchema, e
426426
return tools, nil
427427
}
428428

429-
func (s *Server) callHTTPTool(c *gin.Context, req mcp.JSONRPCRequest, conn session.Connection, params mcp.CallToolParams) *mcp.CallToolResult {
429+
func (s *Server) callHTTPTool(c *gin.Context, req mcp.JSONRPCRequest, conn session.Connection, params mcp.CallToolParams, isSSE bool) *mcp.CallToolResult {
430430
// Log tool invocation at info level
431431
s.logger.Info("invoking HTTP tool",
432432
zap.String("tool", params.Name),
@@ -482,7 +482,7 @@ func (s *Server) callHTTPTool(c *gin.Context, req mcp.JSONRPCRequest, conn sessi
482482
zap.String("tool", params.Name),
483483
zap.String("session_id", conn.Meta().ID),
484484
zap.Error(err))
485-
s.sendToolExecutionError(c, conn, req, err, true)
485+
s.sendToolExecutionError(c, conn, req, err, isSSE)
486486
return nil
487487
}
488488

0 commit comments

Comments
 (0)