@@ -2463,6 +2463,59 @@ TEST(server_handle_unknown_method) {
24632463 PASS();
24642464}
24652465
2466+ /* Issue #2433: a modern client probes server/discover before initialize.
2467+ * The -32601 stays so it falls back; only that probe is logged as info. */
2468+ TEST(server_handle_discover_probe_logs_info) {
2469+ mcp_log_buf[0] = '\0';
2470+ CBMLogLevel prev_level = cbm_log_get_level();
2471+ cbm_log_set_level(CBM_LOG_DEBUG);
2472+ cbm_log_set_format(CBM_LOG_FORMAT_TEXT);
2473+ cbm_log_set_sink_ex(mcp_capture_log, CBM_LOG_SINK_REPLACE);
2474+
2475+ cbm_mcp_server_t *srv = cbm_mcp_server_new(NULL);
2476+
2477+ char *resp =
2478+ cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"server/discover\"}");
2479+ ASSERT_NOT_NULL(resp);
2480+ ASSERT_NOT_NULL(strstr(resp, "\"code\":-32601"));
2481+ ASSERT_NOT_NULL(strstr(resp, "Method not found"));
2482+ ASSERT_NOT_NULL(strstr(mcp_log_buf, "method=server/discover"));
2483+ ASSERT_NOT_NULL(strstr(mcp_log_buf, "level=info"));
2484+ ASSERT_NOT_NULL(strstr(mcp_log_buf, "status=ok"));
2485+ ASSERT_NULL(strstr(mcp_log_buf, "level=warn"));
2486+ ASSERT_NULL(strstr(mcp_log_buf, "status=error"));
2487+ free(resp);
2488+
2489+ mcp_log_buf[0] = '\0';
2490+ resp =
2491+ cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"unknown/method\"}");
2492+ ASSERT_NOT_NULL(resp);
2493+ ASSERT_NOT_NULL(strstr(resp, "-32601"));
2494+ ASSERT_NOT_NULL(strstr(mcp_log_buf, "method=unknown/method"));
2495+ ASSERT_NOT_NULL(strstr(mcp_log_buf, "level=warn"));
2496+ ASSERT_NOT_NULL(strstr(mcp_log_buf, "status=error"));
2497+ free(resp);
2498+
2499+ resp = cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"initialize\","
2500+ "\"params\":{\"protocolVersion\":\"2026-07-28\"}}");
2501+ ASSERT_NOT_NULL(resp);
2502+ ASSERT_NOT_NULL(strstr(resp, "2025-11-25"));
2503+ ASSERT_NULL(strstr(resp, "2026-07-28"));
2504+ free(resp);
2505+
2506+ resp =
2507+ cbm_mcp_server_handle(srv, "{\"jsonrpc\":\"2.0\",\"id\":5,\"method\":\"resources/list\"}");
2508+ ASSERT_NOT_NULL(resp);
2509+ ASSERT_NOT_NULL(strstr(resp, "\"resources\":[]"));
2510+ ASSERT_NULL(strstr(resp, "-32601"));
2511+ free(resp);
2512+
2513+ cbm_mcp_server_free(srv);
2514+ cbm_log_set_sink(NULL);
2515+ cbm_log_set_level(prev_level);
2516+ PASS();
2517+ }
2518+
24662519/* ══════════════════════════════════════════════════════════════════
24672520 * TOOL HANDLERS (via server_handle)
24682521 * ══════════════════════════════════════════════════════════════════ */
@@ -25013,6 +25066,7 @@ SUITE(mcp) {
2501325066 RUN_TEST(server_handle_prompts_get_validates_arguments);
2501425067 RUN_TEST(server_handle_logs_request_without_params);
2501525068 RUN_TEST(server_handle_unknown_method);
25069+ RUN_TEST(server_handle_discover_probe_logs_info);
2501625070
2501725071 /* Server handle — edge cases */
2501825072 RUN_TEST(server_handle_invalid_json);
0 commit comments