From bdff031d9304a24fd0c1e0879bd4b917e624f0a4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 20 Oct 2025 11:33:29 -0700 Subject: [PATCH] Call Regex.IsMatch when Match is not needed --- .../Server/AIFunctionMcpServerResource.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ModelContextProtocol.Core/Server/AIFunctionMcpServerResource.cs b/src/ModelContextProtocol.Core/Server/AIFunctionMcpServerResource.cs index 288a864fc..510806898 100644 --- a/src/ModelContextProtocol.Core/Server/AIFunctionMcpServerResource.cs +++ b/src/ModelContextProtocol.Core/Server/AIFunctionMcpServerResource.cs @@ -317,15 +317,21 @@ private AIFunctionMcpServerResource(AIFunction function, ResourceTemplate resour public override bool IsMatch(string uri) { Throw.IfNull(uri); - return TryMatch(uri, out _); + + // For templates, use the Regex to parse. For static resources, we can just compare the URIs. + if (_uriParser is null) + { + // This resource is not templated. + return UriTemplate.UriTemplateComparer.Instance.Equals(uri, ProtocolResourceTemplate.UriTemplate); + } + + return _uriParser.IsMatch(uri); } private bool TryMatch(string uri, out Match? match) { - // For templates, use the Regex to parse. For static resources, we can just compare the URIs. if (_uriParser is null) { - // This resource is not templated. match = null; return UriTemplate.UriTemplateComparer.Instance.Equals(uri, ProtocolResourceTemplate.UriTemplate); }