Skip to content

Conversation

@anushakolan
Copy link
Contributor

@anushakolan anushakolan commented Dec 30, 2025

Why make this change?

This is a follow up PR for, #2983 to address some of the newer comments.

What is this change?

  1. Centralized JSON‑RPC error handling: all standard JSON‑RPC error codes are now defined in one place and used consistently throughout the MCP server (for things like parse errors, invalid requests, unknown methods, invalid parameters, and internal errors).
  2. Standardized how responses are written: both successful results and errors now go through shared helpers, so every MCP response has a consistent JSON‑RPC envelope and is easy to change or audit.
  3. Added an implicit default role to be anonymous when no role is provided in mcp-stdio mode.

How was this tested?

Tested manually by calling all the CRUD tools and execute tool.

Added an MCP server in VS Code in C:\DAB\data-api-builder\.vscode\mcp.json

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

  1. When calling tools with Authenticated all tools pass.
  2. When calling tools with Anonymous, all tools except describe-entities fail with permission denied error.
  3. When calling tools without any role parameter, all tools except describe-entities fail with permission denied error.

@anushakolan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@anushakolan anushakolan marked this pull request as ready for review December 30, 2025 01:43
Copilot AI review requested due to automatic review settings December 30, 2025 01:43
@anushakolan anushakolan changed the title Addressed comments Follow up PR for mcp-stdio mode code changes. Dec 30, 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 is a follow-up to #2983 that improves the MCP stdio server implementation by centralizing JSON-RPC error handling, standardizing response writing, and adding an implicit default role when none is provided.

  • Centralized all JSON-RPC error codes into a single JsonRpcErrorCodes class
  • Standardized response handling through shared WriteResult and WriteError helper methods
  • Added implicit default role of "anonymous" when --mcp-stdio is used without a role parameter

Reviewed changes

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

File Description
src/Service/Utilities/McpStdioHelper.cs Added [NotNullWhen(true)] attribute to enforce non-null role guarantee, implemented implicit default role of "anonymous", and removed unnecessary service scope creation since services are singletons
src/Service/Program.cs Added copyright header (formatting artifact in diff)
src/Azure.DataApiBuilder.Mcp/Core/JsonRpcErrorCodes.cs New file defining centralized JSON-RPC 2.0 error codes for consistent error handling across the MCP server
src/Azure.DataApiBuilder.Mcp/Core/McpStdioServer.cs Replaced hardcoded error codes with constants from JsonRpcErrorCodes, refactored initialize handler to use standardized WriteResult, and updated server name in initialization response

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

Copy link
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.

Approved, but please fix the title to mention "what" the code changes are. Follow up PR doesnt convey much information unless you look into the changes. The PR titles are seen directly in the Release notes, so they should be more meaningful. For example, in this case, it is refactor to use common JsonRpcErrorCodes

@anushakolan anushakolan changed the title Follow up PR for mcp-stdio mode code changes. Centralize JSON‑RPC error handling, standardize MCP response envelope, and add default anonymous role for stdio mode. Dec 30, 2025
@anushakolan anushakolan changed the title Centralize JSON‑RPC error handling, standardize MCP response envelope, and add default anonymous role for stdio mode. [MCP] Centralize JSON‑RPC error handling, standardize MCP response envelope, and add default anonymous role for stdio mode. Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants