Skip to content

Commit adf5932

Browse files
authored
Suppressing some logs from mcp inspector. (#892)
Fixes #861
1 parent 7c4ea4c commit adf5932

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/CommunityToolkit.Aspire.Hosting.McpInspector/CommunityToolkit.Aspire.Hosting.McpInspector.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@
99
<PackageReference Include="AspNetCore.HealthChecks.Uris" />
1010
</ItemGroup>
1111

12+
<ItemGroup>
13+
<Compile Include="$(SharedDir)\LoggingUtils.cs" Link="LoggingUtils.cs" />
14+
</ItemGroup>
15+
1216
</Project>

src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResourceBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Aspire.Hosting.ApplicationModel;
2+
using CommunityToolkit.Hosting.Utils;
23
using Microsoft.Extensions.DependencyInjection;
34

45
namespace Aspire.Hosting;
@@ -138,6 +139,7 @@ public static IResourceBuilder<McpInspectorResource> AddMcpInspector(this IDistr
138139
setup.AddCustomHeader("X-MCP-Proxy-Auth", $"Bearer {token}");
139140
});
140141
}, healthCheckKey);
142+
builder.Services.SuppressHealthCheckHttpClientLogging(healthCheckKey);
141143

142144
return resource.WithHealthCheck(healthCheckKey);
143145
}

src/Shared/LoggingUtils.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace CommunityToolkit.Hosting.Utils;
5+
6+
internal static class LoggingUtils
7+
{
8+
public static void SuppressHealthCheckHttpClientLogging(this IServiceCollection services, string healthCheckName)
9+
{
10+
services.AddLogging(configure =>
11+
{
12+
// The AddUrlGroup health check makes use of http client factory.
13+
configure.AddFilter($"System.Net.Http.HttpClient.{healthCheckName}.LogicalHandler", LogLevel.None);
14+
configure.AddFilter($"System.Net.Http.HttpClient.{healthCheckName}.ClientHandler", LogLevel.None);
15+
});
16+
}
17+
}

0 commit comments

Comments
 (0)