googleapis/mcp-toolbox · warning

invalid notification request: %w

Error message

invalid notification request: %w

What it means

NotificationHandler parses an MCP notification body; since Toolbox does not process notifications, its only failure mode is that the body is not valid JSON or does not decode into a JSONRPCNotification. The underlying json.Unmarshal error is wrapped as "invalid notification request: %w".

Source

Thrown at internal/server/mcp/mcp.go:50

	"github.com/googleapis/mcp-toolbox/internal/util"
)

// ProtocolOptions contains configuration passed during server initialization to protocol handlers.
type ProtocolOptions struct {
	DisableExt []string
}

// InitializeProtocols performs version-specific protocol setup across all supported MCP versions.
func InitializeProtocols(opts ProtocolOptions) {
	v20260728.Initialize(opts.DisableExt)
}

// NotificationHandler process notifications request. It MUST NOT send a response.
// Currently Toolbox does not process any notifications.
func NotificationHandler(ctx context.Context, body []byte) error {
	var notification jsonrpc.JSONRPCNotification
	if err := json.Unmarshal(body, &notification); err != nil {
		return fmt.Errorf("invalid notification request: %w", err)
	}
	// Since we do not enforce notifications, we do not need to check the
	// `Mcp-Method` header here
	return nil
}

// ProcessMethod returns a response for the request.
// This is the Operation phase of the lifecycle for MCP client-server connections.
func ProcessMethod(ctx context.Context, mcpVersion string, id jsonrpc.RequestId, method string, g group.Group, primitiveMgr *primitives.PrimitiveManager, body []byte, header http.Header) (any, error) {
	enableDraft, ok := util.EnableDraftSpecsFromContext(ctx)
	if !ok {
		err := fmt.Errorf("unable to retrieve enableDraftSpecs from context")
		return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
	}
	switch mcpVersion {
	case mcputil.VERSION_20260728:
		return v20260728.ProcessMethod(ctx, id, method, g, primitiveMgr, body, header)
	case mcputil.VERSION_20251125:

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Log/print the exact body being sent and confirm it is complete, valid JSON shaped like {"jsonrpc":"2.0","method":"..."}.
  2. Ensure the Content-Type is application/json and the body is not truncated or double-encoded.
  3. Send the notification to the correct MCP endpoint path for the server version in use.
  4. If testing manually, use a minimal valid notification payload via curl or an MCP SDK client instead of hand-crafting.

Example fix

// before: malformed notification body
curl -X POST $URL -d 'notifications/initialized'
// after: valid JSON-RPC notification
curl -X POST $URL -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","method":"notifications/initialized"}'
Defensive patterns

Strategy: validation

Validate before calling

// Validate the notification before sending
function isValidNotification(body) {
  try {
    const n = JSON.parse(body);
    return n.jsonrpc === "2.0" && typeof n.method === "string";
  } catch { return false; }
}

Type guard

function isJSONRPCNotification(n) {
  return typeof n === "object" && n !== null &&
    n.jsonrpc === "2.0" && typeof n.method === "string" && n.id === undefined;
}

Prevention

When it happens

Trigger: POSTing a notification (notifications/initialized, notifications/cancelled, etc.) with a malformed or non-JSON body, an empty body, or content-type/body mismatch (e.g. form-encoded or truncated payload).

Common situations: Hand-rolled MCP clients sending notifications with wrong JSON shape (missing jsonrpc/method fields); curl tests with quoting mistakes; intermediaries compressing or truncating the body; sending the notification to the wrong endpoint so a non-notification payload is parsed as one.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/5510386599db8a0c. Report an issue: GitHub.