-
Notifications
You must be signed in to change notification settings - Fork 299
[MCP] Centralize JSON‑RPC error handling, standardize MCP response envelope, and add default anonymous role for stdio mode. #3035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
mcp-stdio mode code changes.
There was a problem hiding this 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
JsonRpcErrorCodesclass - Standardized response handling through shared
WriteResultandWriteErrorhelper methods - Added implicit default role of "anonymous" when
--mcp-stdiois 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.
Aniruddh25
left a comment
There was a problem hiding this 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
mcp-stdio mode code changes.|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
souvikghosh04
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments for appropriate way of naming and versioning of MCP server and some naming/structuring conventions.
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
souvikghosh04
left a comment
There was a problem hiding this 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. Approved.
…velope, and add default anonymous role for stdio mode. (#3035) ## 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. 5. When calling tools without any role parameter, all tools except `describe-entities` fail with permission denied error. (cherry picked from commit de8f074)
…velope, and add default anonymous role for stdio mode. (#3035) ## 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. 5. When calling tools without any role parameter, all tools except `describe-entities` fail with permission denied error. (cherry picked from commit de8f074)
Why make this change?
This is a follow up PR for, #2983 to address some of the newer comments.
What is this change?
anonymouswhen no role is provided inmcp-stdiomode.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" } }Authenticatedall tools pass.Anonymous, all tools exceptdescribe-entitiesfail with permission denied error.describe-entitiesfail with permission denied error.