Add MCP probe to comprehensive health endpoint#3685
Open
Copilot wants to merge 2 commits into
Open
Conversation
Copilot
AI
changed the title
[WIP] Add MCP checks to health endpoint
Add MCP probe to comprehensive health endpoint
Jun 26, 2026
Contributor
There was a problem hiding this comment.
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
initializepayload builder for MCP health probing. - Implemented
HttpUtilities.ExecuteMcpQueryAsyncand wired an MCP check intoHealthCheckHelper.UpdateHealthCheckDetailsAsync. - Extended health endpoint tests and introduced the
mcphealth-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>()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why make this change?
/healthreport advertised whether MCP was enabled in itsconfigurationblock but never actually probed the MCP endpoint, so MCP outages were invisible to health monitoring.What is this change?
HealthCheckHelper— NewUpdateMcpHealthCheckResultsAsync, wired intoUpdateHealthCheckDetailsAsyncalongside the data-source/entity/embeddings checks. Runs only whenIsMcpEnabled; emits aHealthCheckResultEntrynamedmcp, tagged["mcp"], comparing response time against the default 1000 ms threshold.HttpUtilities.ExecuteMcpQueryAsync— POSTs a JSON-RPCinitializerequest toruntimeConfig.McpPathwithAccept: application/json, text/event-stream, reusing the existingCheckSanityOfUrlSSRF guard and role-header propagation.initializeis used becausetools/listrequires an active session under the Streamable HTTP transport.Utilities.CreateHttpMcpQuery— Builds the minimal initialize payload.HealthCheckConstants— Adds themcptag.Single
mcptag (mirroring the data-source check's singledata-sourcetag) rather than reusingendpoint, which is reserved for per-entity REST/GraphQL checks. The check is gated solely onIsMcpEnabledwith a default threshold — no new config surface.How was this tested?
ComprehensiveHealthEndpoint_ValidateContentsto assert themcptag appears iff MCP is enabled.TestHealthCheckMcpResponseAsync/TestFailureHealthCheckMcpResponseAsynccover success and non-2xx responses.Sample Request(s)
Resulting check entry when MCP is enabled:
{ "name": "mcp", "status": "Healthy", "tags": ["mcp"], "data": { "duration-ms": 12, "threshold-ms": 1000 } }