File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
src/DotNetCampus.ModelContextProtocol/Servers Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -261,8 +261,9 @@ private async Task HandleJsonRpcRequestAsync(HttpListenerContext ctx)
261261
262262 if ( response . IsNoResponse )
263263 {
264- // Notification,不返回内容
265- RespondWithSuccess ( ctx , HttpStatusCode . OK ) ;
264+ // Notification:根据 MCP 协议,必须返回 202 Accepted
265+ // https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#sending-messages-to-the-server
266+ RespondWithSuccess ( ctx , HttpStatusCode . Accepted ) ;
266267 }
267268 else
268269 {
@@ -414,9 +415,13 @@ private async Task HandleLegacyMessageRequestAsync(HttpListenerContext ctx)
414415 await session . Writer . WriteAsync ( "event:message\n " ) ;
415416 var responseText = JsonSerializer . Serialize ( response , McpServerResponseJsonContext . Default . JsonRpcResponse ) ;
416417 await session . Writer . WriteAsync ( $ "data:{ responseText } \n \n ") ;
418+ RespondWithSuccess ( ctx , HttpStatusCode . OK ) ;
419+ }
420+ else
421+ {
422+ // Notification:根据 MCP 协议,必须返回 202 Accepted
423+ RespondWithSuccess ( ctx , HttpStatusCode . Accepted ) ;
417424 }
418-
419- RespondWithSuccess ( ctx , HttpStatusCode . OK ) ;
420425 }
421426 catch ( JsonException ex )
422427 {
You can’t perform that action at this time.
0 commit comments