Skip to content

fix: Mock tooling server MCP protocol compliance for Python/Node.js agents#263

Merged
sellakumaran merged 2 commits intomicrosoft:mainfrom
pratapladhani:fix/mock-tooling-server-mcp-compliance
Feb 17, 2026
Merged

fix: Mock tooling server MCP protocol compliance for Python/Node.js agents#263
sellakumaran merged 2 commits intomicrosoft:mainfrom
pratapladhani:fix/mock-tooling-server-mcp-compliance

Conversation

@pratapladhani
Copy link
Contributor

Summary

Fixes #262

The mock tooling server's JSON-RPC handler at /agents/servers/{mcpServerName} only handled initialize, logging/setLevel, tools/list, and tools/call methods. Python and Node.js MCP clients send additional standard MCP methods during connection setup (ping, notifications/initialized, prompts/list, resources/list), causing unhandled exceptions and HTTP 500 errors that prevent these agents from connecting.

Changes

6 fixes in Server.cs (50 insertions, 10 deletions):

  1. notifications/* - Return 202 Accepted per MCP Streamable HTTP spec (was returning JSON-RPC error)
  2. ping - Return empty result {} for connection health checks (was method-not-found)
  3. prompts/list - Return { prompts: [] } (was error)
  4. resources/list - Return { resources: [] } (was error)
  5. Unknown MCP server names - Catch ArgumentException in tools/list and tools/call; return empty tools list / JSON-RPC error instead of unhandled crash
  6. idValue scope fix - Moved declaration before try block so the catch handler preserves the original request id (was null)

Testing

  • Build: Compiles with 0 warnings, 0 errors
  • End-to-end validation: Python Agent Framework sample (microsoft/Agent365-Samples) successfully connects to mock tooling server, discovers tools, and executes tool calls after these fixes
  • No new tests added: There is no existing endpoint/integration test infrastructure for Server.cs (existing tests cover CLI command parsing only). Integration tests could be added as a follow-up.

Risk Assessment

  • Low risk: All changes are additive handlers for previously-unhandled MCP methods
  • No breaking changes: Existing .NET agent behavior is unchanged (these methods were never sent by the .NET client)
  • Backward compatible: Unknown methods still return JSON-RPC method-not-found error

The mock tooling server's JSON-RPC handler at /agents/servers/{mcpServerName}
only handled initialize, logging/setLevel, tools/list, and tools/call methods.
Python and Node.js MCP clients send additional standard MCP methods during
connection setup, causing unhandled exceptions and 500 errors.

Changes:
- Handle notifications/* with 202 Accepted (MCP Streamable HTTP spec)
- Handle ping with empty result (connection health check)
- Handle prompts/list with empty prompts array
- Handle resources/list with empty resources array
- Catch ArgumentException for unknown MCP server names in tools/list
  and tools/call (return empty tools / JSON-RPC error instead of crash)
- Move idValue declaration before try block so catch handler preserves
  the request id (was null)

Fixes microsoft#262
@pratapladhani pratapladhani requested review from a team as code owners February 16, 2026 00:59
Copilot AI review requested due to automatic review settings February 16, 2026 00:59
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 fixes MCP protocol compliance issues in the mock tooling server that prevented Python and Node.js Agent Framework samples from connecting. The .NET samples worked because they didn't send certain standard MCP methods, but Python/Node.js MCP client libraries follow the full MCP Streamable HTTP specification and were encountering HTTP 500 errors on unhandled methods.

Changes:

  • Added handlers for standard MCP methods (ping, prompts/list, resources/list) that Python/Node.js clients send during connection setup
  • Implemented proper MCP notification handling (returning 202 Accepted for notifications/* methods)
  • Added graceful error handling for unknown MCP server names in tools/list and tools/call
  • Fixed JSON-RPC response id field preservation in error responses by moving idValue declaration before try block

Fixes CR-263-001 through CR-263-007 from code review.

Changes:
1. Extract JSON-RPC error codes to constants (CR-263-003)
   - Created JsonRpcConstants.cs with error codes and HTTP status codes
   - Replaced all magic numbers (-32601, -32602, -32603, 202) with named constants
   - Added XML documentation explaining each constant's purpose

2. Fix inconsistent error handling in tools/list (CR-263-002)
   - Changed tools/list to return JSON-RPC error instead of empty tools list for unknown MCP servers
   - Now consistent with tools/call behavior
   - Prevents misleading clients about server existence

3. Include exception in log.LogWarning calls (CR-263-007)
   - Added exception parameter to both tools/list and tools/call catch blocks
   - Follows .NET logging best practices for better debugging

4. Document null handling contract (CR-263-005)
   - Added comment explaining that 'method' field validation ensures non-null in subsequent code
   - Clarifies the null safety contract for maintainers

5. Add comment explaining idValue scope decision (CR-263-006)
   - Documents why idValue is declared outside try block
   - Ensures error responses include correct request ID

6. Add unit tests for constants (CR-263-001)
   - Created JsonRpcConstantsTests.cs with 7 tests
   - Validates error codes match JSON-RPC 2.0 specification
   - Documents intended use of each error code
   - Note: Full integration tests require server infrastructure setup (follow-up)

All changes maintain backward compatibility and follow repository coding standards.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@sellakumaran sellakumaran merged commit 4593f93 into microsoft:main Feb 17, 2026
4 checks passed
@pratapladhani pratapladhani deleted the fix/mock-tooling-server-mcp-compliance branch February 18, 2026 05:43
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.

Mock Tooling Server crashes on standard MCP protocol methods sent by Python/Node.js agents

3 participants

Comments