Skip to content

bug: SendNotificationToClient not work #334

Open
@beckwy

Description

@beckwy

Description

I used the SendNotificationClient method in the example to send a notification to the client. The SendNotification method did not report an error, but the client OnNotification method did not receive the notification.

Code Sample

this is server code

server := server.ServerFromContext(ctx)
	logger.ZapLogger.Info("SendNotificationToClient start")
	err := server.SendNotificationToClient(
		ctx,
		"notifications/progress",
		map[string]any{
			"progress":      10,
			"total":         10,
			"progressToken": 0,
		},
	)
	logger.ZapLogger.Info("SendNotificationToClient end", zap.Any("err", err))
	if err != nil {
		logger.ZapLogger.Info("handleDescribeInstancesTool failed to send notification", zap.Any("err", err))
		return nil, err
	}

this is server log print

{"level":"info","ts":"2025-05-26T15:56:23.100+0800","caller":"tools/describeInstances.go:37","msg":"SendNotificationToClient start"}
{"level":"info","ts":"2025-05-26T15:56:23.100+0800","caller":"tools/describeInstances.go:46","msg":"SendNotificationToClient end","err":null}

this is client code

c = client.NewClient(sseTransport)
	// Set up notification handler
	c.OnNotification(func(notification mcp.JSONRPCNotification) {
		log.Debugf("connectMcpServerWithSSE OnNotification Received notification: %s\n, AITraceId: %v", notification.Method, yReq.AITraceId)
	})
	// Initialize the client
	initRequest := mcp.InitializeRequest{}
	initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
	initRequest.Params.ClientInfo = mcp.Implementation{
		Name:    "MCP-Go Simple Client Example",
		Version: "1.0.0",
	}
	initRequest.Params.Capabilities = mcp.ClientCapabilities{}

client not received notification!

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions