@@ -642,9 +642,10 @@ static const tool_def_t TOOLS[] = {
642642
643643 {"manage_adr" , "Manage ADR" , "Create or update Architecture Decision Records" ,
644644 "{\"type\":\"object\",\"properties\":{\"project\":{\"type\":\"string\"},\"mode\":{\"type\":"
645- "\"string\",\"enum\":[\"get\",\"update\",\"sections\"]},\"content\":{\"type\":\"string\"},"
646- "\"sections\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"project\"]"
647- "}" },
645+ "\"string\",\"enum\":[\"get\",\"update\",\"sections\"],\"description\":\"update replaces "
646+ "the entire ADR document; sections only lists existing headings\"},\"content\":{\"type\":\"string\","
647+ "\"description\":\"Complete replacement document required by update\"}},\"additionalProperties\":false,"
648+ "\"required\":[\"project\"]}" },
648649
649650 {"ingest_traces" , "Ingest traces" , "Ingest runtime traces to enhance the knowledge graph" ,
650651 "{\"type\":\"object\",\"properties\":{\"traces\":{\"type\":\"array\",\"items\":{\"type\":"
@@ -10158,6 +10159,28 @@ static char *handle_manage_adr(cbm_mcp_server_t *srv, const char *args) {
1015810159 mode_str = heap_strdup ("get" );
1015910160 }
1016010161
10162+ /* `sections` used to be advertised as an input argument, but it was never
10163+ * consumed: mode=update still replaced the whole document. Reject the old
10164+ * shape explicitly before opening a store so a stale client cannot mistake
10165+ * a whole-document replacement for a section-scoped update. */
10166+ bool has_sections_arg = false;
10167+ yyjson_doc * args_doc = yyjson_read (args , strlen (args ), 0 );
10168+ if (args_doc ) {
10169+ yyjson_val * args_root = yyjson_doc_get_root (args_doc );
10170+ has_sections_arg = args_root && yyjson_is_obj (args_root ) &&
10171+ yyjson_obj_get (args_root , "sections" ) != NULL ;
10172+ yyjson_doc_free (args_doc );
10173+ }
10174+ if (has_sections_arg ) {
10175+ free (project );
10176+ free (mode_str );
10177+ free (content );
10178+ return cbm_mcp_text_result (
10179+ "{\"status\":\"invalid_arguments\",\"error\":\"The sections argument is not an "
10180+ "update primitive and has been removed. No ADR write was performed.\"}" ,
10181+ true);
10182+ }
10183+
1016110184 bool mutation_held = false;
1016210185 if (project ) {
1016310186 mutation_held = mcp_project_mutation_begin (srv , project );
@@ -10265,6 +10288,7 @@ static char *handle_manage_adr(cbm_mcp_server_t *srv, const char *args) {
1026510288 if ((strcmp (mode_str , "update" ) == 0 || strcmp (mode_str , "store" ) == 0 ) && content ) {
1026610289 if (cbm_store_adr_store (store , project , content ) == CBM_STORE_OK ) {
1026710290 yyjson_mut_obj_add_str (doc , root_obj , "status" , "updated" );
10291+ yyjson_mut_obj_add_str (doc , root_obj , "semantics" , "whole_document_replaced" );
1026810292 } else {
1026910293 yyjson_mut_obj_add_str (doc , root_obj , "status" , "write_error" );
1027010294 is_error = true;
0 commit comments