Pass context from request endpoint to message handler
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 32/100
Rechercherichtung
Beginne bei McpEndpointRouteBuilderExtensions und McpServer und verfolge OnMessageReceivedAsync sowie den im Issue gezeigten Aufruf RequestHandlers.Set. Ermittle, wie ein opaker Aufruferkontext zusammen mit der IJsonRpcMessage in den Tool-Handler oder den MCP-Anforderungskontext gelangen kann. Als abgeschlossen gilt die Aufgabe, wenn der vom Endpunkt bereitgestellte Kontext während lang laufender Tool-Aufrufe verfügbar ist, ohne den abgeschlossenen HttpContext zu speichern oder weiterzugeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Is your feature request related to a problem? Please describe.
When the server is started, it runs in a scope that has the current HttpContext. In that context there might be useful headers that are relevant for that session. But when you need to call a tool the message endpoint might have a different HttpContext and different headers.
For example you might want to use the bearer token from the message endpoint to call a tool or to get the list of tools. In the case of SSE transport, you will need to transfer this token to the tool handler.
Describe the solution you'd like
Be able to build an object (could be opaque) on the message endpoint (can contain anything you want, you can include headers or other info) and pass that object alongside with the IJsonRpcMessage to the tool hander. Maybe make it available on the mcp request context.
Example call:
McpEndpointRouteBuilderExtensions:
await transport.OnMessageReceivedAsync(message, callerContext, context.RequestAborted);
McpServer:
RequestHandlers.Set(
RequestMethods.ToolsCall,
(request, callerContext, cancellationToken) => callToolHandler(new(this, request, callerContext), cancellationToken),
McpJsonUtilities.JsonContext.Default.CallToolRequestParams,
McpJsonUtilities.JsonContext.Default.CallToolResponse);
This could be extended to other requests as well.
Describe alternatives you've considered
Storing the context in memory introduces additional overhead since it has to be cleaned up and introduces unneeded complexity.
Storing the context in a cache is not ok because we might want to pass sensitive information.
Passing the http context directly is not ok because the post /message request could be finished by the time the tool call is actually processed.
Additional context
In this case we have tool calls with long timeout, they might take a long time to complete, in the order of minutes at least.
- Vorherrschende Sprache
- C#
- Sterne
- 4.5k
- Forks
- 814
- Ø Merge
- 9 T. 19 Std.
- Gemergte PRs (30 T.)
- 4
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/csharp-sdk
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
modelcontextprotocol/csharp-sdk#1867 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
modelcontextprotocol/csharp-sdk#1840 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
modelcontextprotocol/csharp-sdk#1836 ·
-
enhancement needs confirmation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
modelcontextprotocol/csharp-sdk#678 · 1 Kommentar ·
-
enhancement needs confirmation P3 ready for work
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
modelcontextprotocol/csharp-sdk#515 · 6 Kommentare · 3 Reaktionen ·
Alle Issues in modelcontextprotocol/csharp-sdk
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
SubtitleEdit/subtitleedit#15108 · 1 Kommentar ·
-
area/docs-content Bug pulumi/docs
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 94/100
-
agentic-workflows untriaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100