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
@anushakolan anushakolan added this to the Nov 2025 milestone Nov 19, 2025
Copy link
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 adds Model Context Protocol (MCP) stdio support to Data API Builder, enabling DAB to function as an MCP server with role-based authorization. The implementation ensures MCP sessions can run under a specific DAB authorization role (from dab-config.json) by detecting --mcp-stdio early, configuring I/O streams appropriately, and forcing the Simulator authentication provider for requested roles.

Key changes:

  • Service entrypoint detects --mcp-stdio flag, configures stdin/stdout encodings, redirects non-MCP output to stderr, parses optional role:<name> argument, and runs MCP stdio loop instead of HTTP server.
  • CLI integration adds --mcp-stdio option and optional positional role argument to dab start command.
  • New McpStdioServer implementation handles JSON-RPC requests (initialize, listTools, callTool) over stdio with role-based authentication context.

Reviewed Changes

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

Show a summary per file
File Description
src/Service/Startup.cs Adds MCP stdio mode detection and forces Simulator authentication when running in MCP stdio mode
src/Service/Program.cs Implements MCP stdio mode detection, I/O configuration, role parsing, and server loop instead of HTTP host
src/Cli/Exporter.cs Updates StartOptions constructor calls to include new MCP parameters
src/Cli/ConfigGenerator.cs Adds logic to append MCP stdio switches and role argument when starting engine
src/Cli/Commands/StartOptions.cs Adds McpStdio and McpRole properties with corresponding CLI options
src/Azure.DataApiBuilder.Mcp/IMcpStdioServer.cs Defines interface for MCP stdio server
src/Azure.DataApiBuilder.Mcp/Core/McpStdioServer.cs Implements MCP stdio server with JSON-RPC message handling and role-based authorization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@anushakolan anushakolan linked an issue Nov 19, 2025 that may be closed by this pull request
@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).

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

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

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

4 participants