Files
splinter/tests/test_mcpsession.sh
lotherk 74df75d438 no approval gate: splinter runs what the operator's registry offers
Konrad, 24.11.: "v1 geht durch ohne irgendwas. ich will auch keine approvals
generell. ich will nur das der user mit ask nach sachen gefragt werden kann."

Removed the whole approval apparatus, not just the prompt:

- agent.c: the decision point (sp_host_gate/approve callbacks), the
  pause/resume path (has_pending, pending_from, sp_agent_resume), ack_approval,
  ask_operator and the ack stdin thread are gone. A tool runs; its exit status
  is the observation. sp_tool_policy (allow/deny per profile) stays - that is
  the operator's own configuration, not a question to the operator.
- engine.c: SP_EV_APPROVAL, sp_engine_approve, the approve_pending condition
  variable and the `approval`/`approve` protocol commands are gone.
- openai_server.c: the v1 endpoint runs gw_* tools without a gate; the
  autonomous flag is no longer part of sp_gateway_opts.
- a2aserver.c: INPUT_REQUIRED and the resume-by-taskId path are gone; CancelTask
  stays. An A2A caller has no operator sitting in front of a prompt.
- mcpserver.c: --autonomous no longer gates mutating tools; the flag and the
  config key are accepted for compatibility and documented as changing
  nothing.
- telegram.c: tg_approve and the approval callback are gone; ask is the only
  dialog, and /cancel inside it still ends the turn.
- front ends: protocol.c, curses.c, ui_local.c, ui_remote.c, client.c lose the
  approval event and the waiting flag.
- ack.c stays: it is a plugin API (plugins/kids asks its parent through it),
  not splinter's own gate. --ack is documented as such.

Tests: test_pause.c guarded the pause and now guards the opposite (a mutate and
a destructive tool run, nothing is asked). test_a2a_input.sh, test_protocol.sh,
test_ui.sh, test_agents_ui.sh, test_gateway.sh, test_gateway_openai.sh,
test_agent.c and test_mcpsession.sh were rewritten the same way;
splinter_approve must now be absent from the MCP tool list. Every rewritten
test was run red against the old behaviour where that was possible.

make check: all tests passed (428 s)
make check-asan: all 47 test binaries clean
make check-tsan: all 47 test binaries free of data races
2026-11-24 11:46:10 +00:00

84 lines
2.8 KiB
Bash
Executable File

#!/bin/sh
# The MCP server's session tools, over a real socket.
#
# A script transport stands in for the model ("answer hello"), so no network is
# touched: tools/list must offer the session tools, and say/history/sessions/
# models must round-trip through the engine.
set -e
cd "$(dirname "$0")/.."
. "$(dirname "$0")/sh/port.sh"
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-mcps-XXXXXX") || exit 1
port=$(free_port)
pid=
cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null; rm -rf "$D"; }
trap cleanup EXIT INT TERM
mkdir -p "$D/home"
echo "answer hello" > "$D/replies"
HOME=$D/home ./splinter --no-config --autonomous --model m \
--script "$D/replies" --mcp-server-listen 127.0.0.1 \
--mcp-listen-port "$port" > "$D/srv.out" 2>&1 &
pid=$!
# the helper proves our own server owns the socket, so a port another program
# holds cannot make the checks below talk to a stranger
if ! wait_tcp "$port" "$pid"; then
echo "test_mcpsession: the MCP server did not start on $port"
cat "$D/srv.out"
exit 1
fi
python3 - "$port" <<'PY'
import json, socket, sys
s = socket.create_connection(("127.0.0.1", int(sys.argv[1])), 5)
# a turn is a turn: the script transport is fast, but the machine may be busy
s.settimeout(120)
f = s.makefile("rw", encoding="utf-8")
def req(i, method, params=None):
o = {"jsonrpc": "2.0", "id": i, "method": method}
if params is not None:
o["params"] = params
f.write(json.dumps(o) + "\n"); f.flush()
return json.loads(f.readline())
def call(i, name, args):
r = req(i, "tools/call", {"name": name, "arguments": args})
if "error" in r:
print("error:", r["error"], file=sys.stderr); sys.exit(1)
return r["result"]["content"][0]["text"]
init = req(1, "initialize", {})
assert init["result"]["serverInfo"]["name"] == "splinter", init
tools = [t["name"] for t in req(2, "tools/list")["result"]["tools"]]
for want in ("splinter_sessions", "splinter_state", "splinter_models",
"splinter_history", "splinter_say", "splinter_steer",
"splinter_cancel", "splinter_answer"):
assert want in tools, (want, tools)
# there is no approval to answer: splinter does not gate its own tools
assert "splinter_approve" not in tools, tools
state = call(3, "splinter_state", {})
assert "model: m" in state, state
assert "session: sess-" in state, state
say = call(4, "splinter_say", {"text": "hi"})
assert "hello" in say, say
hist = call(5, "splinter_history", {"limit": 10})
assert "[user] hi" in hist and "[assistant] hello" in hist, hist
sessions = call(6, "splinter_sessions", {})
assert "sess-" in sessions and "*" in sessions, sessions
models = call(7, "splinter_models", {})
assert "local/m" in models, models
cancel = call(8, "splinter_cancel", {})
assert "no turn is running" in cancel, cancel
print("test_mcpsession: ok")
PY