Skip to content

[MCP] Respond to stdio initialize before metadata inference - #3804

Closed
Souvik Ghosh (Souvik04) wants to merge 1 commit into
Azure:mainfrom
Souvik04:Usr/sogh/mcp-stdio-initialize-latency
Closed

[MCP] Respond to stdio initialize before metadata inference#3804
Souvik Ghosh (Souvik04) wants to merge 1 commit into
Azure:mainfrom
Souvik04:Usr/sogh/mcp-stdio-initialize-latency

Conversation

@Souvik04

Copy link
Copy Markdown
Contributor

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 initialize response 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?

  • Enter the MCP stdio protocol loop before database metadata inference and tool registration.
  • Defer that work until the first tools/list or valid tools/call request.
  • Cache the initialization task so repeated requests cannot run inference more than once.
  • Await initialization before reading or executing tools, including metadata-enriched custom tool schemas.
  • Add a deterministic test that blocks metadata inference and verifies initialize responds while tools/list remains pending.

How was this tested?

  • Integration Tests
  • Unit Tests

Focused MCP stdio and registry suite: 49 passed, 0 failed.

dotnet format --verify-no-changes and git diff --check also pass.

Sample Request(s)

Send initialize, notifications/initialized, then tools/list over stdin. The initialize response is emitted immediately; tools/list waits 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":{}}

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 Azure#3430
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@souvikghosh04

Copy link
Copy Markdown
Contributor

Superseded by #3805, opened from the Azure repository branch under the CODEOWNER account Souvik Ghosh (@souvikghosh04).

@github-project-automation github-project-automation Bot moved this from In Progress to Done in Data API builder Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

--mcp-stdio blocks initialize response until all schema introspection completes, causing MCP reconnect timeouts

2 participants