Skip to content

Added changes to set McpServerOptions.Instructions in HTTPS/SSE mode.#3423

Open
anushakolan wants to merge 3 commits intomainfrom
dev/anushakolan/server-instruction-not-set
Open

Added changes to set McpServerOptions.Instructions in HTTPS/SSE mode.#3423
anushakolan wants to merge 3 commits intomainfrom
dev/anushakolan/server-instruction-not-set

Conversation

@anushakolan
Copy link
Copy Markdown
Contributor

Why make this change?

Closes #3283

runtime.mcp.description was configured, but MCP HTTP/SSE initialize did not return it as instructions. This made the engine behavior inconsistent with expected MCP initialization output.

Related discussion: #3282

What is this change?

  • Wired runtime MCP description into MCP server options for HTTP/SSE initialization:

    • runtime.mcp.description -> ServerInstructions
    • Files updated:
      • src/Azure.DataApiBuilder.Mcp/Core/McpServiceCollectionExtensions.cs
      • src/Azure.DataApiBuilder.Mcp/Core/McpServerConfiguration.cs
  • Added/updated regression coverage for initialize response instructions:

    • src/Service.Tests/Configuration/ConfigurationTests.cs
    • Test: TestMcpInitializeIncludesInstructionsFromRuntimeDescription

How the bug was simulated:

  • Reverted the MCP wiring changes and called MCP initialize; result.instructions was missing.

How it was verified after fix:

  • Re-applied the wiring, called MCP initialize again, and confirmed result.instructions is present.

How was this tested?

  • Integration Tests
  • Unit Tests

Ran:

  • dotnet test src/Service.Tests/Azure.DataApiBuilder.Service.Tests.csproj --filter "FullyQualifiedName~ConfigurationTests.TestMcpInitializeIncludesInstructionsFromRuntimeDescription" -v minimal

Sample Request(s)

MCP initialize request (HTTP):

curl -i -X POST http://localhost:5000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{
    "jsonrpc":"2.0",
    "id":1,
    "method":"initialize",
    "params":{
      "protocolVersion":"2025-03-26",
      "capabilities":{},
      "clientInfo":{"name":"manual-test","version":"1.0.0"}
    }
  }'

Expected response snippet after fix:

{
  "result": {
    "instructions": "Use SQL tools to query the database."
  }
}

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 aligns MCP HTTP/SSE initialization behavior with the stdio transport by propagating runtime.mcp.description into the MCP initialize response’s instructions field, and adds a regression test to prevent regressions.

Changes:

  • Pass runtime.mcp.description into MCP server configuration during DI setup.
  • Set MCP server options (ServerInstructions) so HTTP/SSE initialize includes instructions.
  • Add an MSSQL integration test that calls MCP initialize and asserts result.instructions is present (with helper logic to parse JSON vs SSE responses).

Reviewed changes

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

File Description
src/Azure.DataApiBuilder.Mcp/Core/McpServiceCollectionExtensions.cs Passes runtime MCP description into MCP server configuration during service registration.
src/Azure.DataApiBuilder.Mcp/Core/McpServerConfiguration.cs Adds an instructions parameter and wires it to MCP server options used by HTTP/SSE initialize.
src/Service.Tests/Configuration/ConfigurationTests.cs Adds a regression test + helper to invoke MCP initialize and validate returned instructions.

Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

minimize test duplication.

Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Server instruction not set properly in the engine.

4 participants