Skip to content

Commit 1bf8189

Browse files
committed
Adding health checks on the npm resource
1 parent dbaf877 commit 1bf8189

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ public class McpInspectorResource(string name) : ExecutableResource(name, "npx",
1010
{
1111
internal readonly string ConfigPath = Path.GetTempFileName();
1212

13+
/// <summary>
14+
/// The name of the client endpoint.
15+
/// </summary>
16+
public const string ClientEndpointName = "client";
17+
18+
/// <summary>
19+
/// The name of the server proxy endpoint.
20+
/// </summary>
21+
public const string ServerProxyEndpointName = "server-proxy";
22+
1323
/// <summary>
1424
/// Gets the version of the MCP Inspector.
1525
/// </summary>

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ public static IResourceBuilder<McpInspectorResource> AddMcpInspector(this IDistr
1717
var resource = builder.AddResource(new McpInspectorResource(name))
1818
.WithArgs(["-y", $"@modelcontextprotocol/inspector@{McpInspectorResource.InspectorVersion}"])
1919
.ExcludeFromManifest()
20-
.WithHttpEndpoint(isProxied: false, port: Random.Shared.Next(3000, 4000), env: "CLIENT_PORT", name: "client")
21-
.WithHttpEndpoint(isProxied: false, port: Random.Shared.Next(4000, 5000), env: "SERVER_PORT", name: "server-proxy")
22-
.WithEnvironment("DANGEROUSLY_OMIT_AUTH", "true");
20+
.WithHttpEndpoint(isProxied: false, port: Random.Shared.Next(3000, 4000), env: "CLIENT_PORT", name: McpInspectorResource.ClientEndpointName)
21+
.WithHttpEndpoint(isProxied: false, port: Random.Shared.Next(4000, 5000), env: "SERVER_PORT", name: McpInspectorResource.ServerProxyEndpointName)
22+
.WithEnvironment("DANGEROUSLY_OMIT_AUTH", "true")
23+
.WithHttpHealthCheck("/", endpointName: McpInspectorResource.ClientEndpointName)
24+
.WithHttpHealthCheck("/config", endpointName: McpInspectorResource.ServerProxyEndpointName);
2325

2426
builder.Eventing.Subscribe<BeforeResourceStartedEvent>(resource.Resource, async (@event, ct) =>
2527
{
@@ -52,8 +54,8 @@ public static IResourceBuilder<McpInspectorResource> AddMcpInspector(this IDistr
5254
return resource
5355
.WithEnvironment(ctx =>
5456
{
55-
var clientEndpoint = resource.GetEndpoint("client");
56-
var serverProxyEndpoint = resource.GetEndpoint("server-proxy");
57+
var clientEndpoint = resource.GetEndpoint(McpInspectorResource.ClientEndpointName);
58+
var serverProxyEndpoint = resource.GetEndpoint(McpInspectorResource.ServerProxyEndpointName);
5759

5860
if (clientEndpoint is null || serverProxyEndpoint is null)
5961
{

tests/CommunityToolkit.Aspire.Hosting.McpInspector.Tests/AppHostTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace CommunityToolkit.Aspire.Hosting.McpInspector.Tests;
55
public class AppHostTests(AspireIntegrationTestFixture<Projects.CommunityToolkit_Aspire_Hosting_McpInspector_AppHost> fixture) : IClassFixture<AspireIntegrationTestFixture<Projects.CommunityToolkit_Aspire_Hosting_McpInspector_AppHost>>
66
{
77
[Theory]
8-
[InlineData("client", "/")]
9-
[InlineData("server-proxy", "/config")]
8+
[InlineData(McpInspectorResource.ClientEndpointName, "/")]
9+
[InlineData(McpInspectorResource.ServerProxyEndpointName, "/config")]
1010
public async Task ResourceStartsAndRespondsOk(string endpointName, string route)
1111
{
1212
var resourceName = "mcp-inspector";

0 commit comments

Comments
 (0)