Skip to content

Commit 0b8790e

Browse files
committed
Rename CanReadUri to IsMatch
- Improve comments
1 parent 8323451 commit 0b8790e

8 files changed

Lines changed: 21 additions & 18 deletions

File tree

src/ModelContextProtocol.AspNetCore/HttpServerTransportOptions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ public class HttpServerTransportOptions
2323
public Func<HttpContext, McpServer, CancellationToken, Task>? RunSessionHandler { get; set; }
2424

2525
/// <summary>
26-
/// Gets or sets whether the server should run in a stateless mode which allows for load balancing without session affinity.
26+
/// Gets or sets whether the server should run in a stateless mode which does not track state between requests
27+
/// allowing for load balancing without session affinity.
2728
/// </summary>
2829
/// <remarks>
29-
/// If <see langword="true"/>, <see cref="RunSessionHandler"/> is called once for every request for each request,
30-
/// the "/sse" endpoint will be disabled, and the "MCP-Session-Id" header will not be used.
30+
/// If <see langword="true"/>, <see cref="McpSession.SessionId"/> will be null, and the "MCP-Session-Id" header will not be used,
31+
/// the <see cref="RunSessionHandler"/> will be called once for for each request, and the "/sse" endpoint will be disabled.
3132
/// Unsolicited server-to-client messages and all server-to-client requests are also unsupported, because any responses
3233
/// may arrive at another ASP.NET Core application process.
3334
/// Client sampling and roots capabilities are also disabled in stateless mode, because the server cannot make requests.

src/ModelContextProtocol.Core/McpException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace ModelContextProtocol;
1212
///
1313
/// This exception type can be thrown by MCP tools or tool call filters to propagate detailed error messages
1414
/// from <see cref="Exception.Message"/> when a tool execution fails via a <see cref="CallToolResult"/>.
15-
/// For non-tool calls, this exception controls the message propogated via a <see cref="JsonRpcError"/>.
16-
///
15+
/// For non-tool calls, this exception controls the message propagated via a <see cref="JsonRpcError"/>.
16+
///
1717
/// <see cref="McpProtocolException"/> is a derived type that can be used to also specify the
1818
/// <see cref="McpErrorCode"/> that should be used for the resulting <see cref="JsonRpcError"/>.
1919
/// </remarks>

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private AIFunctionMcpServerResource(AIFunction function, ResourceTemplate resour
314314
public override IReadOnlyList<object> Metadata => _metadata;
315315

316316
/// <inheritdoc />
317-
public override bool CanReadUri(string uri)
317+
public override bool IsMatch(string uri)
318318
{
319319
Throw.IfNull(uri);
320320
return TryMatch(uri, out _);

src/ModelContextProtocol.Core/Server/DelegatingMcpServerResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected DelegatingMcpServerResource(McpServerResource innerResource)
2626
public override ResourceTemplate ProtocolResourceTemplate => _innerResource.ProtocolResourceTemplate;
2727

2828
/// <inheritdoc />
29-
public override bool CanReadUri(string uri) => _innerResource.CanReadUri(uri);
29+
public override bool IsMatch(string uri) => _innerResource.IsMatch(uri);
3030

3131
/// <inheritdoc />
3232
public override ValueTask<ReadResourceResult> ReadAsync(RequestContext<ReadResourceRequestParams> request, CancellationToken cancellationToken = default) =>

src/ModelContextProtocol.Core/Server/McpServerImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ await originalListResourceTemplatesHandler(request, cancellationToken).Configure
372372
// Fall back to an O(N) lookup, trying to match against each URI template.
373373
foreach (var resourceTemplate in resources)
374374
{
375-
if (resourceTemplate.CanReadUri(uri))
375+
if (resourceTemplate.IsMatch(uri))
376376
{
377377
request.MatchedPrimitive = resourceTemplate;
378378
break;

src/ModelContextProtocol.Core/Server/McpServerResource.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ protected McpServerResource()
167167
/// and can be used as the <see cref="ReadResourceRequestParams.Uri"/> passed to <see cref="ReadAsync"/>.
168168
/// </summary>
169169
/// <param name="uri">The URI being evaluated for this resource.</param>
170-
/// <returns><see langword="true"/> if the <paramref name="uri"/> matches the <see cref="ProtocolResourceTemplate"/>; otherwise, <see langword="false"/>.</returns>
171-
public abstract bool CanReadUri(string uri);
170+
/// <returns>
171+
/// <see langword="true"/> if the <paramref name="uri"/> matches the <see cref="ProtocolResourceTemplate"/>; otherwise, <see langword="false"/>.
172+
/// </returns>
173+
public abstract bool IsMatch(string uri);
172174

173175
/// <summary>
174176
/// Gets the resource, rendering it with the provided request parameters and returning the resource result.

tests/ModelContextProtocol.Tests/Server/McpServerResourceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public async Task UriTemplate_NonMatchingUri_DoesNotMatch(string uri)
286286
{
287287
McpServerResource t = McpServerResource.Create((string arg1) => arg1, new() { Name = "Hello" });
288288
Assert.Equal("resource://mcp/Hello{?arg1}", t.ProtocolResourceTemplate.UriTemplate);
289-
Assert.False(t.CanReadUri(uri));
289+
Assert.False(t.IsMatch(uri));
290290
await Assert.ThrowsAsync<InvalidOperationException>(async () => await t.ReadAsync(
291291
new RequestContext<ReadResourceRequestParams>(new Mock<McpServer>().Object, CreateTestJsonRpcRequest()) { Params = new() { Uri = uri } },
292292
TestContext.Current.CancellationToken));

tests/ModelContextProtocol.Tests/Server/McpServerTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ await Can_Handle_Requests(
369369
new ServerCapabilities
370370
{
371371
Resources = new()
372-
},
372+
},
373373
method: RequestMethods.ResourcesRead,
374374
configureOptions: options =>
375375
{
@@ -438,7 +438,7 @@ public async Task Can_Handle_List_Prompts_Requests_Throws_Exception_If_No_Handle
438438
public async Task Can_Handle_Get_Prompts_Requests()
439439
{
440440
await Can_Handle_Requests(
441-
new ServerCapabilities
441+
new ServerCapabilities
442442
{
443443
Prompts = new()
444444
},
@@ -466,7 +466,7 @@ public async Task Can_Handle_Get_Prompts_Requests_Throws_Exception_If_No_Handler
466466
public async Task Can_Handle_List_Tools_Requests()
467467
{
468468
await Can_Handle_Requests(
469-
new ServerCapabilities
469+
new ServerCapabilities
470470
{
471471
Tools = new()
472472
},
@@ -504,7 +504,7 @@ await Can_Handle_Requests(
504504
new ServerCapabilities
505505
{
506506
Tools = new()
507-
},
507+
},
508508
method: RequestMethods.ToolsCall,
509509
configureOptions: options =>
510510
{
@@ -626,7 +626,7 @@ await transport.SendMessageAsync(
626626
TestContext.Current.CancellationToken
627627
);
628628

629-
var error = await receivedMessage.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
629+
var error = await receivedMessage.Task.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
630630
Assert.NotNull(error);
631631
Assert.NotNull(error.Error);
632632
Assert.Equal((int)errorCode, error.Error.Code);
@@ -662,7 +662,7 @@ await transport.SendMessageAsync(
662662
}
663663
);
664664

665-
var response = await receivedMessage.Task.WaitAsync(TimeSpan.FromSeconds(5));
665+
var response = await receivedMessage.Task.WaitAsync(TimeSpan.FromSeconds(10));
666666
Assert.NotNull(response);
667667

668668
assertResult(server, response.Result);
@@ -779,7 +779,7 @@ public override Task<JsonRpcResponse> SendRequestAsync(JsonRpcRequest request, C
779779
};
780780

781781
return Task.FromResult(new JsonRpcResponse
782-
{
782+
{
783783
Id = new RequestId("0"),
784784
Result = JsonSerializer.SerializeToNode(result, McpJsonUtilities.DefaultOptions),
785785
});

0 commit comments

Comments
 (0)