feat(soul): MCP connectors — /api/connectors proxy + per-connector auto-approve
Adds the soul side of the connectors feature (spec: docs/research/
mcp-connectors-adoption-spec.md). The soul thin-proxies the neuron-connectd
bridge on 127.0.0.1:7771 so the UI talks to one origin and never reaches the
bridge directly.
routes.el:
- handle_connectors + connectd_get/connectd_post helpers (POST bodies go via
a temp file + curl -d @file, so model/UI input can't reach the shell).
- GET /api/connectors and POST /api/connectors/{add,toggle,auto-approve,
remove,secret,oauth/start} registered in both GET and POST routers.
chat.el:
- tool_auto_approved(): an mcp__* tool skips the approval card only when its
server is explicitly opted in (off by default; built-in tools unaffected;
bridge down -> false). Wired into the agentic approval gate so an
auto-approved connector tool flows straight to execution.
Regenerated dist/chat.c and dist/routes.c. Verified live on :7770: real chat,
recall, and /api/connectors all work after promotion.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vendored
+90
-6
@@ -40,8 +40,18 @@ el_val_t handle_see(el_val_t body);
|
||||
el_val_t studio_tools_json(void);
|
||||
el_val_t agentic_api_key(void);
|
||||
el_val_t agentic_tools_literal(void);
|
||||
el_val_t agentic_tools_with_web(void);
|
||||
el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input);
|
||||
el_val_t json_array_append(el_val_t arr, el_val_t item);
|
||||
el_val_t append_tool_log(el_val_t log, el_val_t name);
|
||||
el_val_t exec_tool_block(el_val_t block);
|
||||
el_val_t agentic_blob(el_val_t model, el_val_t system, el_val_t tools_json, el_val_t messages, el_val_t origin, el_val_t approval, el_val_t iteration, el_val_t tools_log, el_val_t content, el_val_t queue, el_val_t results, el_val_t next);
|
||||
el_val_t extract_all_text(el_val_t s);
|
||||
el_val_t strip_citations(el_val_t s);
|
||||
el_val_t agentic_api_turn(el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages);
|
||||
el_val_t agentic_engine(el_val_t session_id, el_val_t blob);
|
||||
el_val_t handle_chat_agentic(el_val_t body);
|
||||
el_val_t handle_session_approve(el_val_t session_id, el_val_t body);
|
||||
el_val_t handle_chat_as_soul(el_val_t body);
|
||||
el_val_t handle_dharma_room_turn(el_val_t body);
|
||||
el_val_t handle_dharma_room_turn_agentic(el_val_t body);
|
||||
@@ -89,6 +99,7 @@ el_val_t handle_api_link_entities(el_val_t body);
|
||||
el_val_t handle_api_list_typed(el_val_t node_type, el_val_t path, el_val_t body);
|
||||
el_val_t handle_api_consolidate(el_val_t body);
|
||||
el_val_t strip_query(el_val_t path);
|
||||
el_val_t flag_true(el_val_t body, el_val_t key);
|
||||
el_val_t err_404(el_val_t path);
|
||||
el_val_t err_405(el_val_t method, el_val_t path);
|
||||
el_val_t route_health(void);
|
||||
@@ -98,6 +109,9 @@ el_val_t route_imprint_user(el_val_t body);
|
||||
el_val_t route_synthesize(el_val_t body);
|
||||
el_val_t handle_dharma_recv(el_val_t body);
|
||||
el_val_t route_sessions(void);
|
||||
el_val_t connectd_get(el_val_t suffix);
|
||||
el_val_t connectd_post(el_val_t suffix, el_val_t body);
|
||||
el_val_t handle_connectors(el_val_t method, el_val_t clean, el_val_t body);
|
||||
el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body);
|
||||
|
||||
el_val_t strip_query(el_val_t path) {
|
||||
@@ -109,6 +123,11 @@ el_val_t strip_query(el_val_t path) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t flag_true(el_val_t body, el_val_t key) {
|
||||
return (json_get_bool(body, key) || (json_get_int(body, key) > 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t err_404(el_val_t path) {
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"error\":\"not found\",\"path\":\""), path), EL_STR("\"}"));
|
||||
return 0;
|
||||
@@ -201,9 +220,12 @@ el_val_t handle_dharma_recv(el_val_t body) {
|
||||
if (str_eq(eff_event, EL_STR("chat"))) {
|
||||
el_val_t msg = json_get(eff_payload, EL_STR("message"));
|
||||
el_val_t chat_body = ({ el_val_t _if_result_5 = 0; if (str_eq(msg, EL_STR(""))) { _if_result_5 = (el_str_concat(el_str_concat(EL_STR("{\"message\":\""), str_replace(str_replace(eff_payload, EL_STR("\\"), EL_STR("\\\\")), EL_STR("\""), EL_STR("\\\""))), EL_STR("\"}"))); } else { _if_result_5 = (eff_payload); } _if_result_5; });
|
||||
el_val_t agentic_flag = json_get_bool(eff_payload, EL_STR("agentic"));
|
||||
el_val_t agentic_flag = flag_true(eff_payload, EL_STR("agentic"));
|
||||
el_val_t reply = ({ el_val_t _if_result_6 = 0; if (agentic_flag) { _if_result_6 = (handle_chat_agentic(chat_body)); } else { _if_result_6 = (handle_chat(chat_body)); } _if_result_6; });
|
||||
auto_persist(chat_body, reply);
|
||||
el_val_t is_pending = str_contains(reply, EL_STR("\"status\":\"tool_pending\""));
|
||||
if (!is_pending) {
|
||||
auto_persist(chat_body, reply);
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
if (str_eq(eff_event, EL_STR("memory"))) {
|
||||
@@ -254,6 +276,53 @@ el_val_t route_sessions(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t connectd_get(el_val_t suffix) {
|
||||
el_val_t out = exec_capture(el_str_concat(EL_STR("curl -s --max-time 5 http://127.0.0.1:7771"), suffix));
|
||||
if (str_eq(out, EL_STR(""))) {
|
||||
return EL_STR("{\"ok\":false,\"error\":\"connector bridge unreachable (neuron-connectd on :7771)\"}");
|
||||
}
|
||||
return out;
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t connectd_post(el_val_t suffix, el_val_t body) {
|
||||
el_val_t eff = ({ el_val_t _if_result_10 = 0; if (str_eq(body, EL_STR(""))) { _if_result_10 = (EL_STR("{}")); } else { _if_result_10 = (body); } _if_result_10; });
|
||||
el_val_t tmp = EL_STR("/tmp/neuron-connectors-req.json");
|
||||
fs_write(tmp, eff);
|
||||
el_val_t out = exec_capture(el_str_concat(el_str_concat(el_str_concat(EL_STR("curl -s --max-time 20 -X POST http://127.0.0.1:7771"), suffix), EL_STR(" -H 'Content-Type: application/json' -d @")), tmp));
|
||||
if (str_eq(out, EL_STR(""))) {
|
||||
return EL_STR("{\"ok\":false,\"error\":\"connector bridge unreachable (neuron-connectd on :7771)\"}");
|
||||
}
|
||||
return out;
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t handle_connectors(el_val_t method, el_val_t clean, el_val_t body) {
|
||||
if (str_eq(method, EL_STR("GET"))) {
|
||||
return connectd_get(EL_STR("/mcp/servers"));
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/connectors/add"))) {
|
||||
return connectd_post(EL_STR("/mcp/servers/add"), body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/connectors/toggle"))) {
|
||||
return connectd_post(EL_STR("/mcp/servers/toggle"), body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/connectors/auto-approve"))) {
|
||||
return connectd_post(EL_STR("/mcp/servers/auto-approve"), body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/connectors/remove"))) {
|
||||
return connectd_post(EL_STR("/mcp/servers/remove"), body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/connectors/secret"))) {
|
||||
return connectd_post(EL_STR("/mcp/servers/secret"), body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/connectors/oauth/start"))) {
|
||||
return connectd_post(EL_STR("/mcp/oauth/start"), body);
|
||||
}
|
||||
return EL_STR("{\"ok\":false,\"error\":\"unknown connectors route\"}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
el_val_t clean = strip_query(path);
|
||||
if (str_eq(method, EL_STR("POST")) && str_eq(clean, EL_STR("/dharma/recv"))) {
|
||||
@@ -277,7 +346,7 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
engram_save(snap_path);
|
||||
el_val_t snap = fs_read(snap_path);
|
||||
el_val_t edges_raw = json_get_raw(snap, EL_STR("edges"));
|
||||
return ({ el_val_t _if_result_10 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_10 = (EL_STR("[]")); } else { _if_result_10 = (edges_raw); } _if_result_10; });
|
||||
return ({ el_val_t _if_result_11 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_11 = (EL_STR("[]")); } else { _if_result_11 = (edges_raw); } _if_result_11; });
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/chat"))) {
|
||||
return handle_chat(body);
|
||||
@@ -349,6 +418,9 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/neuron/recall"))) {
|
||||
return handle_api_recall(method, path, body);
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/connectors"))) {
|
||||
return handle_connectors(method, clean, body);
|
||||
}
|
||||
return err_404(clean);
|
||||
}
|
||||
if (str_eq(method, EL_STR("POST"))) {
|
||||
@@ -365,11 +437,20 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return handle_elp_chat(body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/chat"))) {
|
||||
el_val_t agentic_flag = json_get_bool(body, EL_STR("agentic"));
|
||||
el_val_t reply = ({ el_val_t _if_result_11 = 0; if (agentic_flag) { _if_result_11 = (handle_chat_agentic(body)); } else { _if_result_11 = (handle_chat(body)); } _if_result_11; });
|
||||
auto_persist(body, reply);
|
||||
el_val_t agentic_flag = flag_true(body, EL_STR("agentic"));
|
||||
el_val_t reply = ({ el_val_t _if_result_12 = 0; if (agentic_flag) { _if_result_12 = (handle_chat_agentic(body)); } else { _if_result_12 = (handle_chat(body)); } _if_result_12; });
|
||||
el_val_t is_pending = str_contains(reply, EL_STR("\"status\":\"tool_pending\""));
|
||||
if (!is_pending) {
|
||||
auto_persist(body, reply);
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/")) && str_ends_with(clean, EL_STR("/approve"))) {
|
||||
el_val_t sid_start = str_len(EL_STR("/api/sessions/"));
|
||||
el_val_t sid_end = (str_len(clean) - str_len(EL_STR("/approve")));
|
||||
el_val_t sid = str_slice(clean, sid_start, sid_end);
|
||||
return handle_session_approve(sid, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/see"))) {
|
||||
return handle_see(body);
|
||||
}
|
||||
@@ -406,6 +487,9 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/imprints"))) {
|
||||
return axon_post(clean, body);
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/connectors"))) {
|
||||
return handle_connectors(method, clean, body);
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/neuron/session/begin"))) {
|
||||
return handle_api_begin_session(body);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user