Skip to content

Add MCP probe to comprehensive health endpoint#3685

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/add-mcp-checks-to-health-endpoint
Open

Add MCP probe to comprehensive health endpoint#3685
Copilot wants to merge 2 commits into
mainfrom
copilot/add-mcp-checks-to-health-endpoint

Conversation

Copilot AI commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Why make this change?

  • Closes [Enh]: Add MCP checks to Health Endpoint #2843
  • The comprehensive /health report advertised whether MCP was enabled in its configuration block but never actually probed the MCP endpoint, so MCP outages were invisible to health monitoring.

What is this change?

  • HealthCheckHelper — New UpdateMcpHealthCheckResultsAsync, wired into UpdateHealthCheckDetailsAsync alongside the data-source/entity/embeddings checks. Runs only when IsMcpEnabled; emits a HealthCheckResultEntry named mcp, tagged ["mcp"], comparing response time against the default 1000 ms threshold.
  • HttpUtilities.ExecuteMcpQueryAsync — POSTs a JSON-RPC initialize request to runtimeConfig.McpPath with Accept: application/json, text/event-stream, reusing the existing CheckSanityOfUrl SSRF guard and role-header propagation. initialize is used because tools/list requires an active session under the Streamable HTTP transport.
  • Utilities.CreateHttpMcpQuery — Builds the minimal initialize payload.
  • HealthCheckConstants — Adds the mcp tag.

Single mcp tag (mirroring the data-source check's single data-source tag) rather than reusing endpoint, which is reserved for per-entity REST/GraphQL checks. The check is gated solely on IsMcpEnabled with a default threshold — no new config surface.

How was this tested?

  • Integration Tests — extended ComprehensiveHealthEndpoint_ValidateContents to assert the mcp tag appears iff MCP is enabled.
  • Unit Tests — TestHealthCheckMcpResponseAsync / TestFailureHealthCheckMcpResponseAsync cover success and non-2xx responses.

Sample Request(s)

GET /health

Resulting check entry when MCP is enabled:

{
  "name": "mcp",
  "status": "Healthy",
  "tags": ["mcp"],
  "data": { "duration-ms": 12, "threshold-ms": 1000 }
}

Copilot AI changed the title [WIP] Add MCP checks to health endpoint Add MCP probe to comprehensive health endpoint Jun 26, 2026
Copilot AI requested a review from souvikghosh04 June 26, 2026 08:26
@souvikghosh04 souvikghosh04 marked this pull request as ready for review June 26, 2026 09:37
Copilot AI review requested due to automatic review settings June 26, 2026 09:37
@souvikghosh04 souvikghosh04 modified the milestones: July 2026, June 2026 Jun 26, 2026
@souvikghosh04 souvikghosh04 moved this from Todo to In Progress in Data API builder Jun 26, 2026
@souvikghosh04 souvikghosh04 moved this from In Progress to Review In Progress in Data API builder Jun 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an MCP probe to the comprehensive /health endpoint so that MCP availability and response time are reflected in health monitoring when MCP is enabled.

Changes:

  • Added a minimal JSON-RPC initialize payload builder for MCP health probing.
  • Implemented HttpUtilities.ExecuteMcpQueryAsync and wired an MCP check into HealthCheckHelper.UpdateHealthCheckDetailsAsync.
  • Extended health endpoint tests and introduced the mcp health-check tag constant.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Service/HealthCheck/Utilities.cs Adds helper to create a minimal MCP initialize JSON-RPC request payload.
src/Service/HealthCheck/HttpUtilities.cs Adds an MCP POST probe method for the health check HTTP client.
src/Service/HealthCheck/HealthCheckHelper.cs Wires MCP probing into comprehensive health checks and records duration/threshold.
src/Service.Tests/Configuration/HealthEndpointTests.cs Extends comprehensive health assertions and adds MCP request unit tests.
src/Config/HealthCheck/HealthCheckConstants.cs Adds the mcp tag constant.

Comment on lines +145 to +163
if (string.IsNullOrEmpty(mcpUriSuffix))
{
_logger.LogError("The MCP route is not available, hence HealthEndpoint is not available.");
return errorMessage;
}

if (!Program.CheckSanityOfUrl($"{_httpClient.BaseAddress}{mcpUriSuffix.TrimStart('/')}"))
{
_logger.LogError("Blocked outbound request due to invalid or unsafe URI.");
return "Blocked outbound request due to invalid or unsafe URI.";
}

string jsonPayload = Utilities.CreateHttpMcpQuery();
HttpContent content = new StringContent(jsonPayload, Encoding.UTF8, Utilities.JSON_CONTENT_TYPE);

HttpRequestMessage message = new(method: HttpMethod.Post, requestUri: mcpUriSuffix)
{
Content = content
};
Comment on lines +245 to +258
private async Task<(int, string?)> ExecuteMcpQueryAsync(string mcpUriSuffix, string roleHeader, string roleToken)
{
string? errorMessage = null;
if (!string.IsNullOrEmpty(mcpUriSuffix))
{
Stopwatch stopwatch = new();
stopwatch.Start();
errorMessage = await _httpUtility.ExecuteMcpQueryAsync(mcpUriSuffix, roleHeader, roleToken);
stopwatch.Stop();
return string.IsNullOrEmpty(errorMessage) ? ((int)stopwatch.ElapsedMilliseconds, errorMessage) : (HealthCheckConstants.ERROR_RESPONSE_TIME_MS, errorMessage);
}

return (HealthCheckConstants.ERROR_RESPONSE_TIME_MS, errorMessage);
}
Comment on lines +428 to +434
mockHandler.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(req =>
req.Method == HttpMethod.Post &&
req.RequestUri == new Uri($"{BASE_DAB_URL}{runtimeConfig.McpPath}")),
ItExpr.IsAny<CancellationToken>())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

[Enh]: Add MCP checks to Health Endpoint

5 participants