The MCP C++ server crashes (segfault) when receiving standard MCP methods like ping or any unknown method. This is a critical issue for production use and MCP conformance.
Steps to Reproduce
- Start the MCP server
- Initialize a session
- Send a
ping request:
{"jsonrpc": "2.0", "id": 99, "method": "ping"}
- Server crashes immediately
Root Cause
In src/shared/base_session.cpp, line ~102:
void BaseSession::ProcessIncomingRequest(const JSONRPCRequest& rpcRequest, RequestContext& ctx)
{
if (!rpcRequest.request_) {
MCP_LOG(MCP_LOG_LEVEL_ERROR, "rpcRequest.request_ is null");
} // <-- BUG: no return here
const Request& typedRequest = *static_cast<const Request*>(rpcRequest.request_.get());
// ^^ null pointer dereference → segfault
When a method like ping arrives, the JSON parser can't deserialize it into any known request type (no PingRequest class exists), so rpcRequest.request_ is nullptr. The code logs the error but doesn't return — it falls through and dereferences the null pointer.
Proposed Fix
Fix 1 — Add return after null check (base_session.cpp):
if (!rpcRequest.request_) {
MCP_LOG(MCP_LOG_LEVEL_ERROR, "rpcRequest.request_ is null");
return; // ADD THIS
}
Fix 2 — Add ping handler (mcp_server_implement.cpp, in ReceiveIncomingMessages):
if (method == "ping") {
auto session = serverManager_->GetSession(ctx.sessionId);
if (session) {
auto result = std::make_unique<Result>();
session->SendResponse(requestId, std::move(result), ctx);
}
return;
}
Impact
- Any MCP client sending
ping (including the official MCP Inspector) will crash the server
- Per the MCP spec,
ping is a standard method that all servers should handle
- Per JSON-RPC 2.0, unknown methods should return error code -32601, never crash
Environment
- MCP C++ SDK from
openJiuwen-ai/agent-protocol
- Tested via MCP Inspector v0.21.1 and curl

The MCP C++ server crashes (segfault) when receiving standard MCP methods like
pingor any unknown method. This is a critical issue for production use and MCP conformance.Steps to Reproduce
pingrequest:{"jsonrpc": "2.0", "id": 99, "method": "ping"}Root Cause
In
src/shared/base_session.cpp, line ~102:When a method like
pingarrives, the JSON parser can't deserialize it into any known request type (noPingRequestclass exists), sorpcRequest.request_isnullptr. The code logs the error but doesn't return — it falls through and dereferences the null pointer.Proposed Fix
Fix 1 — Add return after null check (
base_session.cpp):Fix 2 — Add ping handler (
mcp_server_implement.cpp, inReceiveIncomingMessages):Impact
ping(including the official MCP Inspector) will crash the serverpingis a standard method that all servers should handleEnvironment
openJiuwen-ai/agent-protocol