[MCP] Respond to stdio initialize before metadata inference - #3805
Draft
Souvik Ghosh (souvikghosh04) wants to merge 2 commits into
Draft
[MCP] Respond to stdio initialize before metadata inference#3805Souvik Ghosh (souvikghosh04) wants to merge 2 commits into
Souvik Ghosh (souvikghosh04) wants to merge 2 commits into
Conversation
Defer metadata provider initialization and tool registration until the first tools/list or tools/call request so the MCP handshake is not blocked by schema introspection. Fixes #3430
2 tasks
Register a no-op metadata provider factory in the shared protocol test service provider so lazy tool initialization can complete for pre-populated test registries.
Copilot started reviewing on behalf of
Souvik Ghosh (souvikghosh04)
September 8, 2026 13:43
View session
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Approval assessments are split, and the lazy DI tool-registration path lacks direct coverage.
Pull request overview
Defers MCP stdio metadata inference and tool registration so initialize can respond immediately.
Changes:
- Lazily caches metadata and tool initialization.
- Awaits initialization for tool listing and execution.
- Adds deterministic initialization-order tests.
File summaries
| File | Description |
|---|---|
src/Service/Utilities/McpStdioHelper.cs |
Removes eager tool registration. |
src/Service.Tests/UnitTests/McpStdioServerRunAsyncTests.cs |
Tests response timing and cached initialization. |
src/Service.Tests/UnitTests/McpStdioServerProtocolTests.cs |
Provides no-op metadata initialization for protocol tests. |
src/Azure.DataApiBuilder.Mcp/Core/McpStdioServer.cs |
Adds lazy metadata and tool initialization; direct coverage of DI-based tool registration remains requested as a nit. |
Review details
Suppressed comments (1)
src/Azure.DataApiBuilder.Mcp/Core/McpStdioServer.cs:331
- Please add coverage for the new lazy registration path. The blocking test registers no
IMcpTool, while the protocol tests pre-populateMcpToolRegistry, so all tests still pass if these registration lines are removed. Register a tool through DI and assert that it appears intools/list(ideally also verifying a custom tool's metadata is enriched only after inference completes).
IEnumerable<IMcpTool> tools = _serviceProvider.GetServices<IMcpTool>();
McpToolRegistry.InitializeAndRegisterTools(tools, _toolRegistry, _serviceProvider);
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 6 pipeline(s). |
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?
Fixes #3430.
MCP stdio currently performs database schema introspection before entering the JSON-RPC read loop. For remote databases with many entities, clients can time out waiting for the
initializeresponse even though the process and database are healthy.Related: #3783 and #3784. This change also ensures stdio initializes metadata providers without starting the HTTP host.
What is this change?
tools/listor validtools/callrequest.initializeresponds whiletools/listremains pending.How was this tested?
Focused MCP stdio, protocol, and registry suite: 76 passed, 0 failed.
dotnet format --verify-no-changesandgit diff --checkalso pass.Sample Request(s)
Send
initialize,notifications/initialized, thentools/listover stdin. Theinitializeresponse is emitted immediately;tools/listwaits until schema inference and tool registration complete.{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"probe","version":"1"}}} {"jsonrpc":"2.0","method":"notifications/initialized","params":{}} {"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}