@@ -705,6 +705,26 @@ char *cbm_mcp_get_string_arg(const char *args_json, const char *key) {
705705 return result ;
706706}
707707
708+ /* Resolve the project argument, accepting the canonical "project" key plus the
709+ * aliases a caller naturally reaches for (#640): list_projects surfaces the
710+ * field as "name" and the not-found hint says "pass the project name", so
711+ * "project_name" is the usual guess; "project_id" / "projectName" are accepted
712+ * too. NOT bare "name" — index_repository uses "name" for an explicit
713+ * project-name override. Caller must free() the result. */
714+ static char * get_project_arg (const char * args_json ) {
715+ char * p = cbm_mcp_get_string_arg (args_json , "project" );
716+ if (!p ) {
717+ p = cbm_mcp_get_string_arg (args_json , "project_name" );
718+ }
719+ if (!p ) {
720+ p = cbm_mcp_get_string_arg (args_json , "project_id" );
721+ }
722+ if (!p ) {
723+ p = cbm_mcp_get_string_arg (args_json , "projectName" );
724+ }
725+ return p ;
726+ }
727+
708728int cbm_mcp_get_int_arg (const char * args_json , const char * key , int default_val ) {
709729 yyjson_doc * doc = yyjson_read (args_json , strlen (args_json ), 0 );
710730 if (!doc ) {
@@ -1039,7 +1059,8 @@ static char *build_project_list_error(const char *reason) {
10391059 if (count > 0 ) {
10401060 snprintf (buf , sizeof (buf ),
10411061 "{\"error\":\"%s\",\"hint\":\"Use list_projects to see all indexed projects, "
1042- "then pass the project name.\",\"available_projects\":[%s],\"count\":%d}" ,
1062+ "then pass it as the \\\"project\\\" "
1063+ "argument.\",\"available_projects\":[%s],\"count\":%d}" ,
10431064 reason , projects , count );
10441065 } else {
10451066 snprintf (buf , sizeof (buf ),
@@ -1050,16 +1071,34 @@ static char *build_project_list_error(const char *reason) {
10501071 return heap_strdup (buf );
10511072}
10521073
1053- /* Bail with project list when no store is available. */
1054- #define REQUIRE_STORE (store , project ) \
1055- do { \
1056- if (!(store)) { \
1057- char *_err = build_project_list_error("project not found or not indexed"); \
1058- char *_res = cbm_mcp_text_result(_err, true); \
1059- free(_err); \
1060- free(project); \
1061- return _res; \
1062- } \
1074+ /* Distinct from "unknown project": the caller omitted the project argument
1075+ * entirely (no recognized key). Name the literal "project" key so the fix is
1076+ * obvious (#640). Caller must free() result. */
1077+ static char * build_missing_project_error (void ) {
1078+ return heap_strdup ("{\"error\":\"missing required argument: project\",\"hint\":\"Pass "
1079+ "the project as the \\\"project\\\" argument, e.g. "
1080+ "{\\\"project\\\":\\\"<name from list_projects>\\\"}. Run "
1081+ "list_projects to see indexed projects.\"}" );
1082+ }
1083+
1084+ /* Pick the right no-store error: a NULL project means the argument was missing
1085+ * (clearer message); a non-NULL project that didn't resolve means it's
1086+ * unknown/unindexed (list the available ones). */
1087+ static char * build_no_store_error (const char * project ) {
1088+ return project ? build_project_list_error ("project not found or not indexed" )
1089+ : build_missing_project_error ();
1090+ }
1091+
1092+ /* Bail with the right error when no store is available. */
1093+ #define REQUIRE_STORE (store , project ) \
1094+ do { \
1095+ if (!(store)) { \
1096+ char *_err = build_no_store_error(project); \
1097+ char *_res = cbm_mcp_text_result(_err, true); \
1098+ free(_err); \
1099+ free(project); \
1100+ return _res; \
1101+ } \
10631102 } while (0)
10641103
10651104/* ── Tool handler implementations ─────────────────────────────── */
@@ -1200,7 +1239,7 @@ static char *verify_project_indexed(cbm_store_t *store, const char *project) {
12001239}
12011240
12021241static char * handle_get_graph_schema (cbm_mcp_server_t * srv , const char * args ) {
1203- char * project = cbm_mcp_get_string_arg (args , "project" );
1242+ char * project = get_project_arg (args );
12041243 cbm_store_t * store = resolve_store (srv , project );
12051244 REQUIRE_STORE (store , project );
12061245
@@ -1668,7 +1707,7 @@ static bool run_semantic_query(yyjson_mut_doc *doc, yyjson_mut_val *root, const
16681707}
16691708
16701709static char * handle_search_graph (cbm_mcp_server_t * srv , const char * args ) {
1671- char * project = cbm_mcp_get_string_arg (args , "project" );
1710+ char * project = get_project_arg (args );
16721711 cbm_store_t * store = resolve_store (srv , project );
16731712 REQUIRE_STORE (store , project );
16741713
@@ -1813,7 +1852,7 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) {
18131852
18141853static char * handle_query_graph (cbm_mcp_server_t * srv , const char * args ) {
18151854 char * query = cbm_mcp_get_string_arg (args , "query" );
1816- char * project = cbm_mcp_get_string_arg (args , "project" );
1855+ char * project = get_project_arg (args );
18171856 cbm_store_t * store = resolve_store (srv , project );
18181857 int max_rows = cbm_mcp_get_int_arg (args , "max_rows" , 0 );
18191858
@@ -1891,7 +1930,7 @@ static char *handle_query_graph(cbm_mcp_server_t *srv, const char *args) {
18911930}
18921931
18931932static char * handle_index_status (cbm_mcp_server_t * srv , const char * args ) {
1894- char * project = cbm_mcp_get_string_arg (args , "project" );
1933+ char * project = get_project_arg (args );
18951934 cbm_store_t * store = resolve_store (srv , project );
18961935 REQUIRE_STORE (store , project );
18971936
@@ -1935,7 +1974,7 @@ static char *handle_index_status(cbm_mcp_server_t *srv, const char *args) {
19351974
19361975/* delete_project: just erase the .db file (and WAL/SHM). */
19371976static char * handle_delete_project (cbm_mcp_server_t * srv , const char * args ) {
1938- char * name = cbm_mcp_get_string_arg (args , "project" );
1977+ char * name = get_project_arg (args );
19391978 if (!name ) {
19401979 return cbm_mcp_text_result ("project is required" , true);
19411980 }
@@ -2046,7 +2085,7 @@ static void append_cross_repo_summary(yyjson_mut_doc *doc, yyjson_mut_val *root,
20462085}
20472086
20482087static char * handle_get_architecture (cbm_mcp_server_t * srv , const char * args ) {
2049- char * project = cbm_mcp_get_string_arg (args , "project" );
2088+ char * project = get_project_arg (args );
20502089 char * scope_path = cbm_mcp_get_string_arg (args , "path" );
20512090 cbm_store_t * store = resolve_store (srv , project );
20522091 REQUIRE_STORE (store , project );
@@ -2598,7 +2637,7 @@ static void bfs_union_same_name(cbm_store_t *store, const cbm_node_t *nodes, int
25982637
25992638static char * handle_trace_call_path (cbm_mcp_server_t * srv , const char * args ) {
26002639 char * func_name = cbm_mcp_get_string_arg (args , "function_name" );
2601- char * project = cbm_mcp_get_string_arg (args , "project" );
2640+ char * project = get_project_arg (args );
26022641 cbm_store_t * store = resolve_store (srv , project );
26032642 char * direction = cbm_mcp_get_string_arg (args , "direction" );
26042643 char * mode = cbm_mcp_get_string_arg (args , "mode" );
@@ -3460,7 +3499,7 @@ static char *build_snippet_response(cbm_mcp_server_t *srv, cbm_node_t *node,
34603499
34613500static char * handle_get_code_snippet (cbm_mcp_server_t * srv , const char * args ) {
34623501 char * qn = cbm_mcp_get_string_arg (args , "qualified_name" );
3463- char * project = cbm_mcp_get_string_arg (args , "project" );
3502+ char * project = get_project_arg (args );
34643503 bool include_neighbors = cbm_mcp_get_bool_arg (args , "include_neighbors" );
34653504
34663505 if (!qn ) {
@@ -4176,7 +4215,7 @@ static bool compile_path_filter(const char *filter, cbm_regex_t *re) {
41764215
41774216static char * handle_search_code (cbm_mcp_server_t * srv , const char * args ) {
41784217 char * pattern = cbm_mcp_get_string_arg (args , "pattern" );
4179- char * project = cbm_mcp_get_string_arg (args , "project" );
4218+ char * project = get_project_arg (args );
41804219 char * file_pattern = cbm_mcp_get_string_arg (args , "file_pattern" );
41814220 char * path_filter = cbm_mcp_get_string_arg (args , "path_filter" );
41824221 char * mode_str = cbm_mcp_get_string_arg (args , "mode" );
@@ -4434,7 +4473,7 @@ static void detect_add_impacted_symbols(cbm_store_t *store, const char *project,
44344473}
44354474
44364475static char * handle_detect_changes (cbm_mcp_server_t * srv , const char * args ) {
4437- char * project = cbm_mcp_get_string_arg (args , "project" );
4476+ char * project = get_project_arg (args );
44384477 char * base_branch = cbm_mcp_get_string_arg (args , "base_branch" );
44394478 char * since = cbm_mcp_get_string_arg (args , "since" );
44404479 char * scope = cbm_mcp_get_string_arg (args , "scope" );
@@ -4674,7 +4713,7 @@ static char *adr_read_legacy_file(const char *root_path) {
46744713 "PATTERNS, TRADEOFFS, PHILOSOPHY."
46754714
46764715static char * handle_manage_adr (cbm_mcp_server_t * srv , const char * args ) {
4677- char * project = cbm_mcp_get_string_arg (args , "project" );
4716+ char * project = get_project_arg (args );
46784717 char * mode_str = cbm_mcp_get_string_arg (args , "mode" );
46794718 char * content = cbm_mcp_get_string_arg (args , "content" );
46804719
0 commit comments