Skip to content

Conversation

@anushakolan
Copy link
Contributor

@anushakolan anushakolan commented Nov 17, 2025

Why make this change?

  • Add MCP stdio support to Data API Builder and wire it through both the engine and CLI so DAB can be used as a Model Context Protocol (MCP) server.
  • Ensures MCP sessions can run under a specific DAB authorization role, making it possible to test and use MCP tools with permissions from dab-config.json.

What is this change?

Service entrypoint

  • Detects --mcp-stdio early, configures stdin/stdout encodings, and redirects all non‑MCP output to STDERR to keep STDOUT clean for MCP JSON.
  • Parses an optional role:<name> argument (e.g. role:anonymous, role:authenticated) and injects it into configuration as MCP:Role, defaulting to anonymous when omitted.
  • In MCP stdio mode, forces Runtime:Host:Authentication:Provider = "Simulator" via in‑memory configuration so the requested role is always available during MCP sessions.
  • Starts the full ASP.NET Core host, registers all MCP tools from DI, and runs the MCP stdio loop instead of the normal HTTP host.Run().

CLI Integration

  • Adds --mcp-stdio to dab start to launch the engine in MCP stdio mode.
  • Adds an optional positional role argument (e.g. role:anonymous) captured as StartOptions.McpRole.
  • Keeps existing behavior for non‑MCP dab start unchanged.

Note

  • ExecuteEntityTool now looks for MCP tool inputs under arguments (the standard MCP field) and falls back to the legacy parameters property only if arguments is missing. This aligns our server with how current MCP clients (like VS Code) actually send tool arguments, and preserves backward compatibility for any older clients that still use parameters.

How was this tested?

Integration-like manual testing via MCP clients against:

  • Engine-based MCP server: dotnet Azure.DataApiBuilder.Service.dll --mcp-stdio role:authenticated.
  • CLI-based MCP server: dab start --mcp-stdio role:authenticated.

Manual verification of all MCP tools:

  • describe_entities shows correct entities and effective permissions for the active role.
  • read_records, create_record, update_record, delete_record, execute_entity succeed when the role has the appropriate permissions.

Sample Request(s)

  1. MCP server via CLI (dab)

{ "mcpServers": { "dab-with-exe": { "command": "C:\\DAB\\data-api-builder\\out\\publish\\Debug\\net8.0\\win-x64\\dab\\Microsoft.DataApiBuilder.exe", "args": ["start", "--mcp-stdio", "role:authenticated", "--config", "C:\\DAB\\data-api-builder\\dab-config.json"], "env": { "DAB_ENVIRONMENT": "Development" } } }
2. MCP server via engine DLL

{ "mcpServers": { "dab": { "command": "dotnet", "args": [ "C:\\DAB\\data-api-builder\\out\\publish\\Debug\\net8.0\\win-x64\\dab\\Azure.DataApiBuilder.Service.dll", "--mcp-stdio", "role:authenticated", "--config", "C:\\DAB\\data-api-builder\\dab-config.json" ], "type": "stdio" } } }

@anushakolan
Copy link
Contributor Author

anushakolan commented Nov 18, 2025

/azp run #Resolved

@azure-pipelines
Copy link

azure-pipelines bot commented Nov 18, 2025

Azure Pipelines successfully started running 6 pipeline(s).

#Resolved

@anushakolan
Copy link
Contributor Author

anushakolan commented Nov 19, 2025

/azp run #Resolved

@azure-pipelines
Copy link

azure-pipelines bot commented Nov 19, 2025

Azure Pipelines successfully started running 6 pipeline(s).

#Resolved

@anushakolan
Copy link
Contributor Author

anushakolan commented Nov 19, 2025

/azp run #Resolved

@azure-pipelines
Copy link

azure-pipelines bot commented Nov 19, 2025

Azure Pipelines successfully started running 6 pipeline(s).

#Resolved

@anushakolan anushakolan marked this pull request as ready for review November 19, 2025 10:27
Copilot AI review requested due to automatic review settings November 19, 2025 10:27
@anushakolan anushakolan changed the title Dev/anushakolan/mcp/claude integration [MCP] Added support for --mcp-stdio flag to dab start Nov 19, 2025
@anushakolan anushakolan self-assigned this Nov 19, 2025
@azure-pipelines
Copy link

azure-pipelines bot commented Nov 20, 2025

No pipelines are associated with this pull request.

#Resolved

2 similar comments
@azure-pipelines
Copy link

azure-pipelines bot commented Nov 20, 2025

No pipelines are associated with this pull request.

#Resolved

@azure-pipelines
Copy link

azure-pipelines bot commented Nov 20, 2025

No pipelines are associated with this pull request.

#Resolved

@anushakolan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link
Contributor

@aaronburtle aaronburtle left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@souvikghosh04 souvikghosh04 left a comment

Choose a reason for hiding this comment

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

Added some comments to have common role parsing and retrieval logic along with some refactoring/modularization.

@github-project-automation github-project-automation bot moved this from Todo to Review In Progress in Data API builder Nov 25, 2025
@anushakolan
Copy link
Contributor Author

Added some comments to have common role parsing and retrieval logic along with some refactoring/modularization.

Addressed all comments.

@anushakolan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@souvikghosh04 souvikghosh04 self-requested a review November 26, 2025 05:16
Copy link
Contributor

@souvikghosh04 souvikghosh04 left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

[Enh]: add --mcp-stdio flag to dab start

6 participants