Make MCP client initialization timeout configurable via ToolOptions - #256
Closed
Grant Harris (gwharris7) wants to merge 7 commits into
Closed
Grant Harris (gwharris7) wants to merge 7 commits into
Grant Harris (gwharris7) wants to merge 7 commits into
Conversation
Add nullable McpClientInitializationTimeoutSeconds property to ToolOptions so consumers can override the MCP client initialization timeout. When null (default), the MCP SDK default is used. When set, both McpClientOptions and HttpClient.Timeout are configured to match. Co-Authored-By: Claude Code <noreply@anthropic.com>
- Add input validation (1-600s range) with ArgumentOutOfRangeException - Document valid range in ToolOptions XML docs - Preserve original SDK behavior when timeout is null: call McpClientFactory.CreateAsync without McpClientOptions instead of passing a default instance - Add 13 unit tests covering: null default, valid/invalid values, ArgumentOutOfRangeException for out-of-bounds inputs Co-Authored-By: Claude Code <noreply@anthropic.com>
- Extract GetValidatedInitializationTimeout internal static helper so the timeout TimeSpan is computed once and reused for both HttpClient.Timeout and McpClientOptions.InitializationTimeout. - Use nameof(ToolOptions.McpClientInitializationTimeoutSeconds) as the ArgumentOutOfRangeException ParamName so the offending property is obvious to consumers. - Loosen the GetMcpClientToolsAsync exception assertion to accept either a direct ArgumentOutOfRangeException or one wrapped by InvalidOperationException so the test is decoupled from the outer catch behavior. - Remove the unused IConfiguration mock field from the timeout test class. - Add direct unit coverage for GetValidatedInitializationTimeout (null, valid, and invalid inputs) so the behavioral change is verifiable without a McpClientFactory seam. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Grant Harris (gwharris7)
requested review from
ajmfehr and
Sellakumaran Kanagarathnam (sellakumaran)
June 8, 2026 18:05
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
Author
|
No longer needed — PR #212 was merged successfully. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in configuration surface on ToolOptions that allows consumers to override the MCP client initialization timeout, and wires that value through to MCP client creation so slow downstream dependencies don’t cause premature initialization cancellations.
Changes:
- Added
ToolOptions.McpClientInitializationTimeoutSeconds(int?) to allow overriding the MCP SDK’s initialization timeout while preserving default behavior when unset. - Applied the configured timeout (when set) to both
McpClientOptions.InitializationTimeoutand theHttpClient.Timeoutused by the SSE transport. - Added unit tests covering default/null behavior, validation bounds, and timeout conversion logic.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Tooling/Core/Services/McpToolServerConfigurationService.cs | Validates and applies an optional initialization timeout during MCP client creation; adds helper to validate/convert seconds to TimeSpan?. |
| src/Tooling/Core/Models/ToolOptions.cs | Introduces a nullable McpClientInitializationTimeoutSeconds option with XML documentation. |
| src/Tests/Microsoft.Agents.A365.Tooling.Tests/Services/McpClientInitializationTimeoutTests.cs | Adds unit tests for the new option and validation helper. |
| /// and the underlying HTTP connection. Increase this value if the MCP server performs | ||
| /// slow operations during initialization (e.g., token exchanges in test environments). | ||
| /// When null, the MCP SDK default timeout is used. | ||
| /// Valid range: 1 to 600 seconds. Values outside this range will throw <see cref="ArgumentOutOfRangeException"/>. |
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.
Summary
McpClientInitializationTimeoutSecondsproperty toToolOptionsso consumers can override the MCP client initialization timeoutnull), the MCP SDK default (60s) is used — no behavioral change for existing consumersMcpClientOptions.InitializationTimeoutandHttpClient.Timeoutare configured to matchMotivation
Consumers connecting to the MCP platform may experience
OperationCanceledExceptionwhen downstream dependencies are slow. The MCP SDK's default 60-second initialization timeout is not configurable throughToolOptions, leaving no way for consumers to adjust it for their agents.Usage
Changes
src/Tooling/Core/Models/ToolOptions.cs— Addint? McpClientInitializationTimeoutSecondspropertysrc/Tooling/Core/Services/McpToolServerConfigurationService.cs— Apply timeout only when explicitly setTest plan
null) uses MCP SDK default timeoutMcpClientOptions.InitializationTimeoutandHttpClient.TimeoutReplaces #212 (fork PR could not trigger CodeQL default setup)
Original approvals: Sellakumaran Kanagarathnam (@sellakumaran) ajmfehr