Skip to content

Commit 073f110

Browse files
committed
Minor cleanup
1 parent 5ac3f93 commit 073f110

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
lines changed

samples/EverythingServer/Tools/SampleLlmTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static async Task<string> SampleLLM(
1515
CancellationToken cancellationToken)
1616
{
1717
var samplingParams = CreateRequestSamplingParams(prompt ?? string.Empty, "sampleLLM", maxTokens);
18-
var sampleResult = await server.SampleAsync(samplingParams, options: null, cancellationToken);
18+
var sampleResult = await server.SampleAsync(samplingParams, cancellationToken: cancellationToken);
1919

2020
return $"LLM sampling result: {(sampleResult.Content as TextContentBlock)?.Text}";
2121
}

samples/TestServerWithHosting/Tools/SampleLlmTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static async Task<string> SampleLLM(
1818
CancellationToken cancellationToken)
1919
{
2020
var samplingParams = CreateRequestSamplingParams(prompt ?? string.Empty, "sampleLLM", maxTokens);
21-
var sampleResult = await thisServer.SampleAsync(samplingParams, options: null, cancellationToken);
21+
var sampleResult = await thisServer.SampleAsync(samplingParams, cancellationToken: cancellationToken);
2222

2323
return $"LLM sampling result: {(sampleResult.Content as TextContentBlock)?.Text}";
2424
}

src/ModelContextProtocol.Core/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ foreach (var tool in await client.ListToolsAsync())
5050
var result = await client.CallToolAsync(
5151
"echo",
5252
new Dictionary<string, object?>() { ["message"] = "Hello MCP!" },
53-
cancellationToken:CancellationToken.None);
53+
cancellationToken: CancellationToken.None);
5454

5555
// echo always returns one and only one text content object
5656
Console.WriteLine(result.Content.First(c => c.Type == "text").Text);
@@ -83,13 +83,13 @@ using System.ComponentModel;
8383
var serverOptions = new McpServerOptions();
8484

8585
// Add tools directly
86-
serverOptions.Capabilities.Tools = new()
86+
serverOptions.Capabilities.Tools = new()
8787
{
8888
ListChanged = true,
8989
ToolCollection = [
9090
McpServerTool.Create((string message) => $"hello {message}", new()
9191
{
92-
Name = "echo",
92+
Name = "echo",
9393
Description = "Echoes the message back to the client."
9494
})
9595
]

src/ModelContextProtocol.Core/Server/McpServer.Methods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ private sealed class SamplingChatClient(McpServer server) : IChatClient
467467

468468
/// <inheritdoc/>
469469
public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) =>
470-
_server.SampleAsync(messages, options, requestOptions: null, cancellationToken);
470+
_server.SampleAsync(messages, options: options, cancellationToken: cancellationToken);
471471

472472
/// <inheritdoc/>
473473
async IAsyncEnumerable<ChatResponseUpdate> IChatClient.GetStreamingResponseAsync(

src/ModelContextProtocol.Core/Server/McpServerExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static class McpServerExtensions
3131
[EditorBrowsable(EditorBrowsableState.Never)]
3232
public static ValueTask<CreateMessageResult> SampleAsync(
3333
this IMcpServer server, CreateMessageRequestParams request, CancellationToken cancellationToken = default)
34-
=> AsServerOrThrow(server).SampleAsync(request, options: null, cancellationToken);
34+
=> AsServerOrThrow(server).SampleAsync(request, cancellationToken: cancellationToken);
3535

3636
/// <summary>
3737
/// Requests to sample an LLM via the client using the provided chat messages and options.
@@ -53,7 +53,7 @@ public static ValueTask<CreateMessageResult> SampleAsync(
5353
public static Task<ChatResponse> SampleAsync(
5454
this IMcpServer server,
5555
IEnumerable<ChatMessage> messages, ChatOptions? options = default, CancellationToken cancellationToken = default)
56-
=> AsServerOrThrow(server).SampleAsync(messages, options, requestOptions: null, cancellationToken);
56+
=> AsServerOrThrow(server).SampleAsync(messages, options, cancellationToken: cancellationToken);
5757

5858
/// <summary>
5959
/// Creates an <see cref="IChatClient"/> wrapper that can be used to send sampling requests to the client.
@@ -94,7 +94,7 @@ public static ILoggerProvider AsClientLoggerProvider(this IMcpServer server)
9494
[EditorBrowsable(EditorBrowsableState.Never)]
9595
public static ValueTask<ListRootsResult> RequestRootsAsync(
9696
this IMcpServer server, ListRootsRequestParams request, CancellationToken cancellationToken = default)
97-
=> AsServerOrThrow(server).RequestRootsAsync(request, options: null, cancellationToken);
97+
=> AsServerOrThrow(server).RequestRootsAsync(request, cancellationToken: cancellationToken);
9898

9999
/// <summary>
100100
/// Requests additional information from the user via the client, allowing the server to elicit structured data.

src/ModelContextProtocol.Core/TokenProgress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ internal sealed class TokenProgress(McpSession session, ProgressToken progressTo
1111
/// <inheritdoc />
1212
public void Report(ProgressNotificationValue value)
1313
{
14-
_ = session.NotifyProgressAsync(progressToken, value, options: null, CancellationToken.None);
14+
_ = session.NotifyProgressAsync(progressToken, value, cancellationToken: CancellationToken.None);
1515
}
1616
}

tests/ModelContextProtocol.TestServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private static void ConfigureTools(McpServerOptions options, string? cliArg)
193193
throw new McpProtocolException("Missing required arguments 'prompt' and 'maxTokens'", McpErrorCode.InvalidParams);
194194
}
195195
var sampleResult = await request.Server.SampleAsync(CreateRequestSamplingParams(prompt.ToString(), "sampleLLM", Convert.ToInt32(maxTokens.GetRawText())),
196-
options: null, cancellationToken);
196+
cancellationToken: cancellationToken);
197197

198198
return new CallToolResult
199199
{

tests/ModelContextProtocol.TestSseServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static CreateMessageRequestParams CreateRequestSamplingParams(string context, st
187187
throw new McpProtocolException("Missing required arguments 'prompt' and 'maxTokens'", McpErrorCode.InvalidParams);
188188
}
189189
var sampleResult = await request.Server.SampleAsync(CreateRequestSamplingParams(prompt.ToString(), "sampleLLM", Convert.ToInt32(maxTokens.ToString())),
190-
options: null, cancellationToken);
190+
cancellationToken: cancellationToken);
191191

192192
return new CallToolResult
193193
{

tests/ModelContextProtocol.Tests/Server/EmptyCollectionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ public async Task ListFails()
158158

159159
var client = await CreateMcpClientForServer();
160160

161-
await Assert.ThrowsAsync<McpProtocolException>(async () => await client.ListToolsAsync(options: null, cancellationToken: TestContext.Current.CancellationToken));
162-
await Assert.ThrowsAsync<McpProtocolException>(async () => await client.ListPromptsAsync(options: null, TestContext.Current.CancellationToken));
163-
await Assert.ThrowsAsync<McpProtocolException>(async () => await client.ListResourcesAsync(options: null, TestContext.Current.CancellationToken));
161+
await Assert.ThrowsAsync<McpProtocolException>(async () => await client.ListToolsAsync(cancellationToken: TestContext.Current.CancellationToken));
162+
await Assert.ThrowsAsync<McpProtocolException>(async () => await client.ListPromptsAsync(cancellationToken: TestContext.Current.CancellationToken));
163+
await Assert.ThrowsAsync<McpProtocolException>(async () => await client.ListResourcesAsync(cancellationToken: TestContext.Current.CancellationToken));
164164
}
165165
}

0 commit comments

Comments
 (0)