@@ -650,9 +650,11 @@ static const tool_def_t TOOLS[] = {
650650
651651 {"manage_adr" , "Manage ADR" , "Create or update Architecture Decision Records" ,
652652 "{\"type\":\"object\",\"properties\":{\"project\":{\"type\":\"string\"},\"mode\":{\"type\":"
653- "\"string\",\"enum\":[\"get\",\"update\",\"sections\"]},\"content\":{\"type\":\"string\"},"
654- "\"sections\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"project\"]"
655- "}" },
653+ "\"string\",\"enum\":[\"get\",\"update\",\"sections\"],\"description\":\"update replaces "
654+ "the entire ADR document; sections only lists existing "
655+ "headings\"},\"content\":{\"type\":\"string\",\"description\":\"Complete replacement document "
656+ "required by update\"}},\"additionalProperties\":false,"
657+ "\"required\":[\"project\"]}" },
656658
657659 {"ingest_traces" , "Ingest traces" , "Ingest runtime traces to enhance the knowledge graph" ,
658660 "{\"type\":\"object\",\"properties\":{\"traces\":{\"type\":\"array\",\"items\":{\"type\":"
@@ -10372,6 +10374,28 @@ static char *handle_manage_adr(cbm_mcp_server_t *srv, const char *args) {
1037210374 mode_str = heap_strdup ("get" );
1037310375 }
1037410376
10377+ /* `sections` used to be advertised as an input argument, but it was never
10378+ * consumed: mode=update still replaced the whole document. Reject the old
10379+ * shape explicitly before opening a store so a stale client cannot mistake
10380+ * a whole-document replacement for a section-scoped update. */
10381+ bool has_sections_arg = false;
10382+ yyjson_doc * args_doc = yyjson_read (args , strlen (args ), 0 );
10383+ if (args_doc ) {
10384+ yyjson_val * args_root = yyjson_doc_get_root (args_doc );
10385+ has_sections_arg =
10386+ args_root && yyjson_is_obj (args_root ) && yyjson_obj_get (args_root , "sections" ) != NULL ;
10387+ yyjson_doc_free (args_doc );
10388+ }
10389+ if (has_sections_arg ) {
10390+ free (project );
10391+ free (mode_str );
10392+ free (content );
10393+ return cbm_mcp_text_result (
10394+ "{\"status\":\"invalid_arguments\",\"error\":\"The sections argument is not an "
10395+ "update primitive and has been removed. No ADR write was performed.\"}" ,
10396+ true);
10397+ }
10398+
1037510399 bool mutation_held = false;
1037610400 if (project ) {
1037710401 mutation_held = mcp_project_mutation_begin (srv , project );
@@ -10479,6 +10503,7 @@ static char *handle_manage_adr(cbm_mcp_server_t *srv, const char *args) {
1047910503 if ((strcmp (mode_str , "update" ) == 0 || strcmp (mode_str , "store" ) == 0 ) && content ) {
1048010504 if (cbm_store_adr_store (store , project , content ) == CBM_STORE_OK ) {
1048110505 yyjson_mut_obj_add_str (doc , root_obj , "status" , "updated" );
10506+ yyjson_mut_obj_add_str (doc , root_obj , "semantics" , "whole_document_replaced" );
1048210507 } else {
1048310508 yyjson_mut_obj_add_str (doc , root_obj , "status" , "write_error" );
1048410509 is_error = true;
0 commit comments