Skip to content

Commit b575f6e

Browse files
authored
Call Regex.IsMatch when Match is not needed (#903)
1 parent 1343dd3 commit b575f6e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerResource.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,21 @@ private AIFunctionMcpServerResource(AIFunction function, ResourceTemplate resour
317317
public override bool IsMatch(string uri)
318318
{
319319
Throw.IfNull(uri);
320-
return TryMatch(uri, out _);
320+
321+
// For templates, use the Regex to parse. For static resources, we can just compare the URIs.
322+
if (_uriParser is null)
323+
{
324+
// This resource is not templated.
325+
return UriTemplate.UriTemplateComparer.Instance.Equals(uri, ProtocolResourceTemplate.UriTemplate);
326+
}
327+
328+
return _uriParser.IsMatch(uri);
321329
}
322330

323331
private bool TryMatch(string uri, out Match? match)
324332
{
325-
// For templates, use the Regex to parse. For static resources, we can just compare the URIs.
326333
if (_uriParser is null)
327334
{
328-
// This resource is not templated.
329335
match = null;
330336
return UriTemplate.UriTemplateComparer.Instance.Equals(uri, ProtocolResourceTemplate.UriTemplate);
331337
}

0 commit comments

Comments
 (0)