Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/concepts/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ Execution flow: `filter1 -> filter2 -> filter3 -> baseHandler -> filter3 -> filt
{
var logger = context.Services?.GetService<ILogger<Program>>();

logger?.LogInformation($"Processing request from {context.Meta.ProgressToken}");
logger?.LogInformation($"Processing request from {context.Params?.ProgressToken}");
var result = await next(context, cancellationToken);
logger?.LogInformation($"Returning {result.Tools?.Count ?? 0} tools");
return result;
Expand All @@ -339,11 +339,11 @@ Execution flow: `filter1 -> filter2 -> filter3 -> baseHandler -> filter3 -> filt
catch (Exception ex)
{
var logger = context.Services?.GetService<ILogger<Program>>();
logger?.LogError(ex, "Error while processing CallTool request for {ProgressToken}", context.Meta.ProgressToken);
logger?.LogError(ex, "Error while processing CallTool request for {ProgressToken}", context.Params?.ProgressToken);

return new CallToolResult
{
Content = new[] { new TextContent { Type = "text", Text = "An unexpected error occurred while processing the tool call." } },
Content = [new TextContentBlock { Text = "An unexpected error occurred while processing the tool call." }],
IsError = true
};
}
Expand Down Expand Up @@ -576,7 +576,7 @@ You can also create custom authorization filters using the filter methods:
{
return new CallToolResult
{
Content = [new TextContent { Text = "Custom: Authentication required" }],
Content = [new TextContentBlock { Text = "Custom: Authentication required" }],
IsError = true
};
}
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/logging/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ server to perform any special logic it wants to perform when a client sets the l
SDK already takes care of setting the <xref:ModelContextProtocol.Server.McpServer.LoggingLevel> in the <xref:ModelContextProtocol.Server.McpServer>, so most servers will not need to
implement this.

MCP Servers using the MCP C# SDK can obtain an [ILoggerProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.iloggerprovider) from the IMcpServer <xref:ModelContextProtocol.Server.McpServer.AsClientLoggerProvider> extension method,
MCP Servers using the MCP C# SDK can obtain an [ILoggerProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.iloggerprovider) from the <xref:ModelContextProtocol.Server.McpServer.AsClientLoggerProvider> method on <xref:ModelContextProtocol.Server.McpServer>,
and from that can create an [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger) instance for logging messages that should be sent to the MCP client.

[!code-csharp[](samples/server/Tools/LoggingTools.cs?name=snippet_LoggingConfiguration)]
Expand Down
4 changes: 2 additions & 2 deletions docs/concepts/progress/progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The client should also provide a notification handler to process "notifications/
There are two ways to do this. The first is to register a notification handler using the <xref:ModelContextProtocol.McpSession.RegisterNotificationHandler*> method on the <xref:ModelContextProtocol.Client.McpClient> instance. A handler registered this way will receive all progress notifications sent by the server.

```csharp
mcpClient.RegisterNotificationHandler(NotificationMethods.ProgressNotification,
await using var handler = mcpClient.RegisterNotificationHandler(NotificationMethods.ProgressNotification,
(notification, cancellationToken) =>
{
if (JsonSerializer.Deserialize<ProgressNotificationParams>(notification.Params) is { } pn &&
Expand All @@ -47,7 +47,7 @@ mcpClient.RegisterNotificationHandler(NotificationMethods.ProgressNotification,
Console.WriteLine($"Tool progress: {pn.Progress.Progress} of {pn.Progress.Total} - {pn.Progress.Message}");
}
return ValueTask.CompletedTask;
}).ConfigureAwait(false);
});
```

The second way is to pass a [`Progress<T>`](https://learn.microsoft.com/dotnet/api/system.progress-1) instance to the tool method. `Progress<T>` is a standard .NET type that provides a way to receive progress updates.
Expand Down
12 changes: 7 additions & 5 deletions docs/concepts/tasks/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ The `InMemoryMcpTaskStore` constructor accepts several optional parameters:

```csharp
var taskStore = new InMemoryMcpTaskStore(
defaultTtl: TimeSpan.FromHours(1), // Default task retention time
maxTtl: TimeSpan.FromHours(24), // Maximum allowed TTL
pollInterval: TimeSpan.FromSeconds(1), // Suggested client poll interval
defaultTtl: TimeSpan.FromHours(1), // Default task retention time
maxTtl: TimeSpan.FromHours(24), // Maximum allowed TTL
pollInterval: TimeSpan.FromSeconds(1), // Suggested client poll interval
cleanupInterval: TimeSpan.FromMinutes(5), // Background cleanup frequency
pageSize: 100 // Tasks per page for listing
pageSize: 100, // Tasks per page for listing
maxTasks: 1000, // Maximum total tasks allowed
maxTasksPerSession: 100 // Maximum tasks per session
);
```

Expand Down Expand Up @@ -435,7 +437,7 @@ try
{
var task = await client.GetTaskAsync(taskId, cancellationToken: ct);
}
catch (McpException ex) when (ex.ErrorCode == McpErrorCode.InvalidParams)
catch (McpProtocolException ex) when (ex.ErrorCode == McpErrorCode.InvalidParams)
{
Console.WriteLine($"Task not found: {taskId}");
}
Expand Down
Loading