Skip to content

Commit 1fec659

Browse files
committed
返回 202
1 parent 6e117c3 commit 1fec659

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/DotNetCampus.ModelContextProtocol/Servers/HttpServerTransport.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff 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
{

0 commit comments

Comments
 (0)