Skip to content

Commit 6bc7ade

Browse files
committed
fix(mcp): log the server/discover connect probe as info, not an error
That call now passes false for the error argument when the method is server/discover and true for every other unknown method, so the probe is logged as level=info with status=ok while other misses stay level=warn and status=error. The JSON-RPC response is still -32601 Method not found. The new test server_handle_discover_probe_logs_info checks those log fields, checks that unknown/method still logs a warning, checks that an initialize request for 2026-07-28 still negotiates 2025-11-25, and checks that resources/list still returns an empty resource list. Fixes #2433 Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
1 parent 268a9d8 commit 6bc7ade

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎src/mcp/mcp.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18681,7 +18681,9 @@ char *cbm_mcp_server_handle(cbm_mcp_server_t *srv, const char *line) {
1868118681
cbm_clock_gettime(CLOCK_MONOTONIC, &t1);
1868218682
long long dur_us = ((long long)(t1.tv_sec - req_t0.tv_sec) * MCP_S_TO_US) +
1868318683
((long long)(t1.tv_nsec - req_t0.tv_nsec) / MCP_MS_TO_US);
18684-
cbm_log_mcp_request(req.method, NULL, true, dur_us);
18684+
/* server/discover is the modern connect probe. -32601 stays so the
18685+
* client falls back to initialize; that miss is not an error (#2433). */
18686+
cbm_log_mcp_request(req.method, NULL, strcmp(req.method, "server/discover") != 0, dur_us);
1868518687
cbm_mcp_server_request_scope_end(srv);
1868618688
cbm_jsonrpc_request_free(&req);
1868718689
return err;

‎tests/test_mcp.c‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,59 @@ TEST(server_handle_unknown_method) {
23552355
PASS();
23562356
}
23572357

2358+
/* Issue #2433: a modern client probes server/discover before initialize.
2359+
* The -32601 stays so it falls back; only that probe is logged as info. */
2360+
TEST(server_handle_discover_probe_logs_info) {
2361+
mcp_log_buf[0] = '\0';
2362+
CBMLogLevel prev_level = cbm_log_get_level();
2363+
cbm_log_set_level(CBM_LOG_DEBUG);
2364+
cbm_log_set_format(CBM_LOG_FORMAT_TEXT);
2365+
cbm_log_set_sink_ex(mcp_capture_log, CBM_LOG_SINK_REPLACE);
2366+
2367+
cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
2368+
2369+
char *resp =
2370+
cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"server/discover\"}");
2371+
ASSERT_NOT_NULL(resp);
2372+
ASSERT_NOT_NULL(strstr(resp, "\"code\":-32601"));
2373+
ASSERT_NOT_NULL(strstr(resp, "Method not found"));
2374+
ASSERT_NOT_NULL(strstr(mcp_log_buf, "method=server/discover"));
2375+
ASSERT_NOT_NULL(strstr(mcp_log_buf, "level=info"));
2376+
ASSERT_NOT_NULL(strstr(mcp_log_buf, "status=ok"));
2377+
ASSERT_NULL(strstr(mcp_log_buf, "level=warn"));
2378+
ASSERT_NULL(strstr(mcp_log_buf, "status=error"));
2379+
free(resp);
2380+
2381+
mcp_log_buf[0] = '\0';
2382+
resp =
2383+
cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"unknown/method\"}");
2384+
ASSERT_NOT_NULL(resp);
2385+
ASSERT_NOT_NULL(strstr(resp, "-32601"));
2386+
ASSERT_NOT_NULL(strstr(mcp_log_buf, "method=unknown/method"));
2387+
ASSERT_NOT_NULL(strstr(mcp_log_buf, "level=warn"));
2388+
ASSERT_NOT_NULL(strstr(mcp_log_buf, "status=error"));
2389+
free(resp);
2390+
2391+
resp = cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"initialize\","
2392+
"\"params\":{\"protocolVersion\":\"2026-07-28\"}}");
2393+
ASSERT_NOT_NULL(resp);
2394+
ASSERT_NOT_NULL(strstr(resp, "2025-11-25"));
2395+
ASSERT_NULL(strstr(resp, "2026-07-28"));
2396+
free(resp);
2397+
2398+
resp =
2399+
cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":5,\"method\":\"resources/list\"}");
2400+
ASSERT_NOT_NULL(resp);
2401+
ASSERT_NOT_NULL(strstr(resp, "\"resources\":[]"));
2402+
ASSERT_NULL(strstr(resp, "-32601"));
2403+
free(resp);
2404+
2405+
cbm_mcp_server_free(srv);
2406+
cbm_log_set_sink(NULL);
2407+
cbm_log_set_level(prev_level);
2408+
PASS();
2409+
}
2410+
23582411
/* ══════════════════════════════════════════════════════════════════
23592412
* TOOL HANDLERS (via server_handle)
23602413
* ══════════════════════════════════════════════════════════════════ */
@@ -22351,6 +22404,7 @@ SUITE(mcp) {
2235122404
RUN_TEST(server_handle_prompts_get_validates_arguments);
2235222405
RUN_TEST(server_handle_logs_request_without_params);
2235322406
RUN_TEST(server_handle_unknown_method);
22407+
RUN_TEST(server_handle_discover_probe_logs_info);
2235422408

2235522409
/* Server handle — edge cases */
2235622410
RUN_TEST(server_handle_invalid_json);

0 commit comments

Comments
 (0)