@@ -3712,6 +3712,126 @@ func TestStreamableStateless_AcceptsNewProtocol(t *testing.T) {
37123712 }
37133713}
37143714
3715+ // TestStreamableStateless_NotificationMetaValidation checks that the SEP-2575
3716+ // per-request `_meta` triple is required of calls only. NotificationParams
3717+ // declares `_meta` optional with no protocolVersion, so a notification that
3718+ // omits it is well-formed and must be accepted with 202.
3719+ func TestStreamableStateless_NotificationMetaValidation (t * testing.T ) {
3720+ newProtocolMeta := map [string ]any {
3721+ MetaKeyProtocolVersion : protocolVersion20260728 ,
3722+ MetaKeyClientInfo : map [string ]any {"name" : "new-proto-client" , "version" : "9.9" },
3723+ MetaKeyClientCapabilities : map [string ]any {},
3724+ }
3725+
3726+ tests := []struct {
3727+ name string
3728+ message map [string ]any
3729+ wantStatus int
3730+ }{
3731+ {
3732+ name : "cancelled without meta" ,
3733+ message : map [string ]any {
3734+ "jsonrpc" : "2.0" ,
3735+ "method" : notificationCancelled ,
3736+ "params" : map [string ]any {"requestID" : 1 , "reason" : "context canceled" },
3737+ },
3738+ wantStatus : http .StatusAccepted ,
3739+ },
3740+ {
3741+ name : "progress without meta" ,
3742+ message : map [string ]any {
3743+ "jsonrpc" : "2.0" ,
3744+ "method" : notificationProgress ,
3745+ "params" : map [string ]any {"progressToken" : "t" , "progress" : 1 },
3746+ },
3747+ wantStatus : http .StatusAccepted ,
3748+ },
3749+ {
3750+ name : "notification with matching meta" ,
3751+ message : map [string ]any {
3752+ "jsonrpc" : "2.0" ,
3753+ "method" : notificationCancelled ,
3754+ "params" : map [string ]any {
3755+ "_meta" : newProtocolMeta ,
3756+ "requestID" : 1 ,
3757+ },
3758+ },
3759+ wantStatus : http .StatusAccepted ,
3760+ },
3761+ {
3762+ // A notification that volunteers a version is still held to the
3763+ // header-match rule, so relaxing the requirement does not open a
3764+ // hole for inconsistent messages.
3765+ name : "notification with mismatched meta" ,
3766+ message : map [string ]any {
3767+ "jsonrpc" : "2.0" ,
3768+ "method" : notificationCancelled ,
3769+ "params" : map [string ]any {
3770+ "_meta" : map [string ]any {
3771+ MetaKeyProtocolVersion : "2025-06-18" ,
3772+ MetaKeyClientCapabilities : map [string ]any {},
3773+ },
3774+ "requestID" : 1 ,
3775+ },
3776+ },
3777+ wantStatus : http .StatusBadRequest ,
3778+ },
3779+ {
3780+ // Calls remain subject to the requirement.
3781+ name : "call without meta" ,
3782+ message : map [string ]any {
3783+ "jsonrpc" : "2.0" ,
3784+ "id" : 1 ,
3785+ "method" : "tools/list" ,
3786+ "params" : map [string ]any {},
3787+ },
3788+ wantStatus : http .StatusBadRequest ,
3789+ },
3790+ }
3791+
3792+ server := NewServer (testImpl , nil )
3793+ AddTool (server , & Tool {Name : "noop" },
3794+ func (ctx context.Context , req * CallToolRequest , args struct {}) (* CallToolResult , any , error ) {
3795+ return & CallToolResult {Content : []Content {& TextContent {Text : "ok" }}}, nil , nil
3796+ })
3797+ handler := NewStreamableHTTPHandler (
3798+ func (* http.Request ) * Server { return server },
3799+ & StreamableHTTPOptions {Stateless : true },
3800+ )
3801+ httpServer := httptest .NewServer (handler )
3802+ defer httpServer .Close ()
3803+
3804+ for _ , test := range tests {
3805+ t .Run (test .name , func (t * testing.T ) {
3806+ body , err := json .Marshal (test .message )
3807+ if err != nil {
3808+ t .Fatal (err )
3809+ }
3810+ req , err := http .NewRequest (http .MethodPost , httpServer .URL , bytes .NewReader (body ))
3811+ if err != nil {
3812+ t .Fatal (err )
3813+ }
3814+ req .Header .Set ("Content-Type" , "application/json" )
3815+ req .Header .Set ("Accept" , "application/json, text/event-stream" )
3816+ req .Header .Set (protocolVersionHeader , protocolVersion20260728 )
3817+ req .Header .Set (methodHeader , test .message ["method" ].(string ))
3818+
3819+ resp , err := http .DefaultClient .Do (req )
3820+ if err != nil {
3821+ t .Fatal (err )
3822+ }
3823+ defer resp .Body .Close ()
3824+ respBody , _ := io .ReadAll (resp .Body )
3825+ if resp .StatusCode != test .wantStatus {
3826+ t .Fatalf ("status = %d, want %d; body = %s" , resp .StatusCode , test .wantStatus , respBody )
3827+ }
3828+ if test .wantStatus == http .StatusAccepted && len (respBody ) > 0 {
3829+ t .Errorf ("accepted notification returned body %q, want empty" , respBody )
3830+ }
3831+ })
3832+ }
3833+ }
3834+
37153835// TestStreamableClientUnsupportedVersionFallback exercises the full
37163836// SEP-2575 fallback. The client requests protocolVersion20260728, which the
37173837// server is configured to NOT advertise in supportedProtocolVersions for the
0 commit comments