Skip to content

Commit d13e0f3

Browse files
halter73Copilot
andcommitted
Fix ScopeRequests guidance for pre-scoped providers
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 26e3bb5 commit d13e0f3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/concepts/sessions/sessions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,12 @@ This means:
333333

334334
The stdio transport creates a single server for the lifetime of the process. The server's <xref:ModelContextProtocol.McpServer.Services> is the application-level `IServiceProvider`. By default, <xref:ModelContextProtocol.Server.McpServerOptions.ScopeRequests> is `true`, so each handler invocation gets its own scope — the same behavior as stateful HTTP.
335335

336-
You can set <xref:ModelContextProtocol.Server.McpServerOptions.ScopeRequests> to `false` if you want handlers to resolve services directly from the root container. This is a rare, advanced option — similar to how ASP.NET Core itself supports opting out of per-request scopes — and is generally not recommended because scoped services will then behave like singletons for the lifetime of the process, which most scoped registrations don't expect.
336+
You can set <xref:ModelContextProtocol.Server.McpServerOptions.ScopeRequests> to `false` if the `IServiceProvider` passed to the server is already scoped to the desired lifetime. For example, when using <xref:ModelContextProtocol.McpServer.Create*> with a pre-scoped service provider, disabling `ScopeRequests` avoids creating redundant nested scopes. However, be cautious setting this globally via `AddMcpServer` for stdio servers — with the default hosting, the server receives the root application `IServiceProvider`, so scoped services would behave like singletons for the lifetime of the process.
337337

338338
```csharp
339339
builder.Services.AddMcpServer(options =>
340340
{
341-
// Disable per-handler scoping. Scoped services will resolve from the root container.
341+
// Disable per-handler scoping — only appropriate when the server's IServiceProvider is already scoped.
342342
options.ScopeRequests = false;
343343
})
344344
.WithStdioServerTransport()

0 commit comments

Comments
 (0)