Skip to content

[BUG] #17

Description

@qdrddr

Bug Description

hedl_mcp incorrectly handles the MCP post‑initialization notification.
The MCP protocol specifies the method name as notifications/initialized, but hedl_mcp registers a handler for initialized instead. As a result, the server treats the valid MCP notification as an unknown method and emits an invalid JSON‑RPC error response (missing id).
This response violates both the MCP protocol and JSON‑RPC 2.0, causing downstream MCP clients (Python SDK) to fail parsing the message.

Steps to Reproduce

  • Start a hedl_mcp server (v2.0.0).
  • Connect using any MCP client that follows the MCP spec (e.g., Python mcp SDK or fastmcp).
  • Allow the standard MCP initialization handshake to run:
  • Client sends initialization
  • Server responds
  • Client sends notifications/initialized
  • Observe server logs and client stderr.

Expected Behavior

  • The server should correctly recognize the MCP notifications/initialization.
  • The server should not send any JSON‑RPC response to a notification (per JSON‑RPC 2.0 spec).
  • No JSON‑RPC error should be emitted.
  • MCP clients should complete initialization without parse errors.

Actual Behavior

  • hedl_mcp matches only "initialized" instead of "notifications/initialized".
  • The server treats the valid notification as an unknown method and emits a JSON‑RPC error response.
  • Because notifications have no ID, the server serializes the error without an ID field.
  • The Python MCP SDK fails to parse this message because JSONRPCError.id is required.
  • The client logs a noisy but non‑fatal validation error.

Environment

OS: macOS (reproduced on 14.x)
hedl_mcp Version: 2.0.0 (from crates.io)
Rust Version: stable (toolchain used to build hedl_mcp)
Client: Python MCP SDK (mcp), used via fastmcp

Logs and Error Messages

WARN hedl_mcp::server: Unknown method: notifications/initialized
ERROR: Failed to parse JSONRPC message from server                                                                                                 
  Traceback (most recent call last):                                                                                                                 
    File                                                                                                                                             
  "/.venv/lib/python3.13/site-packages/mcp/client/stdio/__init__.py",   
  line 155, in stdout_reader                                                                                                                         
      message = types.JSONRPCMessage.model_validate_json(line)                                                                                       
    File "/.venv/lib/python3.13/site-packages/pydantic/main.py", line   
  766, in model_validate_json                                                                                                                        
      return cls.__pydantic_validator__.validate_json(                                                                                               
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^                                                                                               
          json_data, strict=strict, extra=extra, context=context, by_alias=by_alias, by_name=by_name                                                 
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                 
      )                                                                                                                                              
      ^                                                                                                                                              
  pydantic_core._pydantic_core.ValidationError: 6 validation errors for JSONRPCMessage                                                               
  JSONRPCRequest.method                                                                                                                              
    Field required [type=missing, input_value={'jsonrpc': '2.0', 'error...fications/initialized'}}, input_type=dict]                                 
      For further information visit https://errors.pydantic.dev/2.12/v/missing                                                                       
  JSONRPCRequest.id                                                                                                                                  
    Field required [type=missing, input_value={'jsonrpc': '2.0', 'error...fications/initialized'}}, input_type=dict]                                 
      For further information visit https://errors.pydantic.dev/2.12/v/missing                                                                       
  JSONRPCNotification.method                                                                                                                         
    Field required [type=missing, input_value={'jsonrpc': '2.0', 'error...fications/initialized'}}, input_type=dict]                                 
      For further information visit https://errors.pydantic.dev/2.12/v/missing                                                                       
  JSONRPCResponse.id                                                                                                                                 
    Field required [type=missing, input_value={'jsonrpc': '2.0', 'error...fications/initialized'}}, input_type=dict]                                 
      For further information visit https://errors.pydantic.dev/2.12/v/missing                                                                       
  JSONRPCResponse.result                                                                                                                             
    Field required [type=missing, input_value={'jsonrpc': '2.0', 'error...fications/initialized'}}, input_type=dict]                                 
      For further information visit https://errors.pydantic.dev/2.12/v/missing                                                                       
  JSONRPCError.id                                                                                                                                    
    Field required [type=missing, input_value={'jsonrpc': '2.0', 'error...fications/initialized'}}, input_type=dict]                                 
      For further information visit https://errors.pydantic.dev/2.12/v/missing                                                                       
  INFO:   Discovered 11 tools on hedl 

Additional Context

Root Cause Summary

Incorrect method name in hedl_mcp in server.rs:
"initialized" => self.handle_initialized(id),
Should be:
"notifications/initialized" => self.handle_initialized(id),

Protocol violation
The server responds to a notification, which JSON‑RPC 2.0 explicitly forbids.

Invalid JSON‑RPC error
Because notifications have no ID, the server emits an error without an ID field, which is invalid for a JSON‑RPC error object.

Client-side fallout
The Python MCP SDK requires JSONRPCError.id to be present, so parsing fails with multiple validation errors.
The SDK swallows the exception and continues, which is why tool discovery still works.

Recommended Fix

  • Change "initialized" → "notifications/initialized" in server.rs.
  • Do not emit error responses for notifications.

Checklist

  • I have searched existing issues to ensure this is not a duplicate
  • I have read the documentation and FAQ
  • I can reproduce this issue consistently
  • I have included all relevant information above

By submitting this issue, I confirm that I am using Dweve technology in accordance with the Terms of Service and not for any prohibited uses (military, surveillance, or harmful applications).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions