a2a: discover the endpoint from an agent card

SPLINTER_A2A_CARD names the card; the first send picks the JSONRPC entry
from supportedInterfaces, falls back to the older single url field, and
keeps the discovered URL for the session. SPLINTER_A2A_URL still wins
when both are set. The card fetch uses the same secret handling as a
send: the bearer token goes through curl's stdin.

The fake agent serves both card shapes, and test_a2a.sh covers discovery
with and without supportedInterfaces.
This commit is contained in:
lotherk committed 2026-11-09 23:34:59 +00:00
1 parent 93e955a4c7
commit d95ac721be
10 files changed
+211 -20

No files matched your search

+5 -3
View File
@@ -119,9 +119,11 @@ The client half of Agent2Agent: one `SendMessage` over JSON-RPC 2.0 with a text
part, blocking, and a direct `Message` or a completed `Task` as the answer. In
the UI the turn streams: `SendStreamingMessage`, artifact text appearing as it
arrives. The task and context ids are kept for the session, so the next turn
continues the same A2A context. One-shot mode streams by default; `--no-stream`
asks for the blocking send. Text only; files, push notifications,
`GetTask`/`CancelTask` and agent-card discovery are not built yet.
continues the same A2A context. `SPLINTER_A2A_CARD` discovers the JSON-RPC
endpoint from an agent card; `SPLINTER_A2A_URL` sets it directly. One-shot mode
streams by default; `--no-stream` asks for the blocking send. Text only; files,
push notifications, `GetTask`/`CancelTask` and the server side are not built
yet.
## Configuration
+8 -5
View File
@@ -47,10 +47,12 @@ Context-Id bleiben fuer die Sitzung; ein terminaler Task verliert seine Id, der
Context bleibt.
Offen: Datei- und strukturierte Teile, Push-Notifications,
`GetTask`/`CancelTask`, Agent-Card-Discovery und die Server-Richtung (andere
Agents rufen splinter).
`GetTask`/`CancelTask` und die Server-Richtung (andere Agents rufen splinter).
Die Agent-Card-Discovery ist gebaut: `SPLINTER_A2A_CARD` nennt die Karte, der
erste Aufruf waehlt den `JSONRPC`-Eintrag aus `supportedInterfaces` (oder das
aeltere einzelne `url`-Feld).
Naechster Schritt: Discovery, danach der Server.
Naechster Schritt: der Server.
### 4. `~/.local/lib` enthaelt Fremdlast
@@ -88,8 +90,9 @@ Naechster Schritt: entscheiden, ob die npm-Reste weg duerfen. Kein Code.
(submit/jobs/result, force-Retry, faelliger Job im Scheduler-Tick,
Scheduler-Widget).
- **A2A-Client**: `plugins/a2a/a2a.c` sendet `SendMessage` (JSON-RPC 2.0, Text,
blockierend) und in der UI `SendStreamingMessage` (SSE, Artefakt-Text live);
`tests/test_a2a.sh` prueft Task, direkte Message, Token und JSON-RPC-Fehler,
blockierend), in der UI `SendStreamingMessage` (SSE, Artefakt-Text live) und
findet den Endpunkt ueber `SPLINTER_A2A_CARD` (Agent Card); `tests/test_a2a.sh`
prueft Task, direkte Message, Token, JSON-RPC-Fehler, Streaming und Discovery,
`tests/test_a2a_ui.sh` den Streaming-Pfad.
- **Fehler dabei gefunden und behoben**: `delegate_retry` las `id` und `force`
in denselben Puffer; `json_str` haengt an, also wurde aus `job-1` mit
+9 -4
View File
@@ -292,8 +292,13 @@ completed status message is the answer only when no artifact or direct message
text came. One-shot mode streams too unless `--no-stream` asks for the blocking
`SendMessage` path.
The endpoint can be configured directly (`SPLINTER_A2A_URL`) or discovered:
`SPLINTER_A2A_CARD` names the agent card, and the first call picks the
`JSONRPC` entry from `supportedInterfaces` (or the older single `url` field).
The discovered URL is kept for the session.
Not implemented yet, and named so nobody assumes otherwise: file/structured-data
parts, push notifications, `GetTask`/`CancelTask`, and agent-card discovery. The
endpoint is configured directly. `tests/fake_a2a.py` and `tests/test_a2a.sh` pin
the blocking wire shape, both result forms, the bearer token and a JSON-RPC
error; `tests/test_a2a_ui.sh` drives the streaming path through tmux.
parts, push notifications, `GetTask`/`CancelTask`, and the server direction.
`tests/fake_a2a.py` and `tests/test_a2a.sh` pin the blocking wire shape, both
result forms, the bearer token, a JSON-RPC error, streaming and discovery;
`tests/test_a2a_ui.sh` drives the streaming path through tmux.
+3 -3
View File
@@ -3,9 +3,9 @@
Stand: 2026-11-09. Die geprüfte, ausführliche Liste mit Belegen steht in
`TODO.md`; hier bleibt die Reihenfolge, was als Nächstes gebaut wird.
1. **A2A: Discovery und Server** — der Client (`plugins/a2a/a2a.c`) kann
`SendMessage` und, in der UI, `SendStreamingMessage` mit Text. Offen sind
Datei- und strukturierte Teile, Push-Notifications, Discovery,
1. **A2A: Server** — der Client (`plugins/a2a/a2a.c`) kann `SendMessage`,
`SendStreamingMessage` (in der UI) und Agent-Card-Discovery, alles mit Text.
Offen sind Datei- und strukturierte Teile, Push-Notifications,
`GetTask`/`CancelTask` und die Server-Seite, damit die Flotte splinter rufen
kann. `swarm` ist nur lokale IPC im selben Verzeichnis, kein A2A.
+152 -2
View File
@@ -37,6 +37,7 @@
#include <time.h>
#include <unistd.h>
#include <strings.h>
#include "splinter.h"
#include "splinter_plugin.h"
#include "curl.h"
@@ -44,6 +45,7 @@
struct a2a_cfg {
char url[512];
char card[512];
char token[512];
char task_id[128];
char context_id[128];
@@ -368,6 +370,145 @@ start_post(struct a2a_cfg *c, const char *body, int stream, pid_t *pid,
return fd;
}
/*
* GET a document (the agent card) with the same secret handling as a send:
* the bearer token travels on curl's stdin, never in argv.
*/
static int
fetch(struct a2a_cfg *c, const char *url, struct sp_buf *body, long *http,
struct sp_buf *err)
{
char tmo[32], auth[sizeof(c->token) + 32];
const char *args[10];
const char *hdrs[2] = { NULL, NULL };
pid_t pid = -1;
FILE *f;
char chunk[4096];
size_t got;
int fd, status = 0;
char *nl;
snprintf(tmo, sizeof(tmo), "%ld", c->timeout);
args[0] = "-sS";
args[1] = "-m";
args[2] = tmo;
args[3] = "-H";
args[4] = "Accept: application/json";
args[5] = "-w";
args[6] = "\n%{http_code}";
args[7] = NULL;
if (c->token[0] != '\0') {
snprintf(auth, sizeof(auth), "Authorization: Bearer %s",
c->token);
hdrs[0] = auth;
}
fd = sp_curl_start(args, url, hdrs, 0, &pid, err);
memset(auth, 0, sizeof(auth));
if (fd < 0)
return -1;
f = fdopen(fd, "r");
if (f == NULL) {
close(fd);
(void)kill(pid, SIGKILL);
(void)waitpid(pid, NULL, 0);
sp_buf_printf(err, "a2a: fdopen: %s", strerror(errno));
return -1;
}
while ((got = fread(chunk, 1, sizeof(chunk), f)) > 0)
if (sp_buf_add(body, chunk, got) != 0) {
fclose(f);
(void)kill(pid, SIGKILL);
(void)waitpid(pid, NULL, 0);
sp_buf_puts(err, "a2a: out of memory");
return -1;
}
fclose(f);
if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) ||
WEXITSTATUS(status) != 0) {
sp_buf_printf(err, "a2a: card transfer failed for %s", url);
return -1;
}
*http = 0;
if (body->len < 2 || (nl = strrchr(body->p, '\n')) == NULL) {
sp_buf_puts(err, "a2a: card response has no HTTP status");
return -1;
}
*http = strtol(nl + 1, NULL, 10);
*nl = '\0';
return 0;
}
/*
* Discovery: the card names the interfaces. Prefer a JSONRPC one, else fall
* back to the older single "url" field. SPLINTER_A2A_URL wins over the card.
*/
static int
discover(struct a2a_cfg *c, struct sp_buf *err)
{
struct sp_buf body;
mcp_json *v = NULL;
const mcp_json *ifaces;
const char *found = NULL;
char url[512];
long http = 0;
size_t i, n;
int rc = -1;
if (c->url[0] != '\0' || c->card[0] == '\0')
return 0;
memset(&body, 0, sizeof(body));
if (sp_buf_init(&body) != 0)
return -1;
if (fetch(c, c->card, &body, &http, err) != 0)
goto out;
if (http < 200 || http > 299) {
sp_buf_printf(err, "a2a: agent card HTTP %ld", http);
goto out;
}
v = mcp_parse(body.p);
if (v == NULL) {
sp_buf_puts(err, "a2a: agent card is not JSON");
goto out;
}
ifaces = mcp_arg(v, "supportedInterfaces");
if (ifaces != NULL && ifaces->t == MCP_ARR) {
n = mcp_array_len(ifaces);
for (i = 0; i < n; i++) {
const mcp_json *it = mcp_array_at(ifaces, i);
const char *b = mcp_arg_string(it, "protocolBinding");
const char *u = mcp_arg_string(it, "url");
if (u == NULL || *u == '\0')
continue;
if (b == NULL || strcasecmp(b, "JSONRPC") == 0) {
snprintf(url, sizeof(url), "%s", u);
found = url;
break;
}
}
}
if (found == NULL) {
const char *u = mcp_arg_string(v, "url");
if (u != NULL && *u != '\0') {
snprintf(url, sizeof(url), "%s", u);
found = url;
}
}
if (found == NULL) {
sp_buf_puts(err, "a2a: agent card names no JSON-RPC interface");
goto out;
}
snprintf(c->url, sizeof(c->url), "%s", found);
rc = 0;
out:
if (v != NULL)
mcp_json_free(v);
sp_buf_free(&body);
return rc;
}
static int
post(struct a2a_cfg *c, const char *body, struct sp_buf *raw,
struct sp_buf *err)
@@ -637,8 +778,11 @@ a2a_stream(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
if (c == NULL || conv == NULL || out == NULL)
return -1;
if (discover(c, err) != 0)
return -1;
if (c->url[0] == '\0') {
sp_buf_puts(err, "a2a: SPLINTER_A2A_URL is not set");
sp_buf_puts(err, "a2a: neither SPLINTER_A2A_URL nor "
"SPLINTER_A2A_CARD is set");
return -1;
}
memset(out, 0, sizeof(*out));
@@ -759,8 +903,11 @@ a2a_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
if (c == NULL || conv == NULL || out == NULL)
return -1;
if (discover(c, err) != 0)
return -1;
if (c->url[0] == '\0') {
sp_buf_puts(err, "a2a: SPLINTER_A2A_URL is not set");
sp_buf_puts(err, "a2a: neither SPLINTER_A2A_URL nor "
"SPLINTER_A2A_CARD is set");
return -1;
}
memset(out, 0, sizeof(*out));
@@ -819,6 +966,7 @@ a2a_init(struct sp_host *h)
static struct a2a_cfg cfg;
static struct sp_transport tr;
const char *url = getenv("SPLINTER_A2A_URL");
const char *card = getenv("SPLINTER_A2A_CARD");
const char *tok = getenv("SPLINTER_A2A_TOKEN");
const char *to = getenv("SPLINTER_A2A_TIMEOUT");
const char *full = getenv("SPLINTER_A2A_FULL");
@@ -826,6 +974,8 @@ a2a_init(struct sp_host *h)
memset(&cfg, 0, sizeof(cfg));
if (url != NULL)
snprintf(cfg.url, sizeof(cfg.url), "%s", url);
if (card != NULL)
snprintf(cfg.card, sizeof(cfg.card), "%s", card);
if (tok != NULL)
snprintf(cfg.token, sizeof(cfg.token), "%s", tok);
cfg.timeout = 300;
+1 -1
View File
@@ -53,7 +53,7 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
<h1>splinter<span>_</span></h1>
<p class="lead">An agent harness you own: chat in the terminal, tools with authorization classes, plugins, any model that speaks OpenAI — built by us so we can change it, instead of getting used to how somebody else's client behaves.</p>
<p class="meta"><b>22635</b> lines of C99/POSIX &middot;
<p class="meta"><b>22785</b> lines of C99/POSIX &middot;
<b>23</b> tools &middot; <b>31</b> test programs &middot;
<b>16</b> plugins &middot; <b>42</b> palettes &middot; BSD-3-Clause</p>
+1 -1
View File
@@ -53,7 +53,7 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
<h1>splinter<span>_</span></h1>
<p class="lead">Ein Agent-Harness, das dir gehoert: Chat im Terminal, Werkzeuge mit Autorisierungsklassen, Plugins, jedes Modell das OpenAI spricht — von uns gebaut, damit wir es umbauen koennen, statt uns an das Verhalten eines fremden Clients zu gewoehnen.</p>
<p class="meta"><b>22635</b> Zeilen C99/POSIX &middot;
<p class="meta"><b>22785</b> Zeilen C99/POSIX &middot;
<b>23</b> Werkzeuge &middot; <b>31</b> Test-Programme &middot;
<b>16</b> Plugins &middot; <b>42</b> Farbschemata &middot; BSD-3-Clause</p>
+1 -1
View File
@@ -53,7 +53,7 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
<h1>splinter<span>_</span></h1>
<p class="lead">Um harness de agente que e seu: chat no terminal, ferramentas com classes de autorizacao, plugins, qualquer modelo que fale OpenAI - escrito por nos para poder mudar-lo, em vez de nos acostumar com o comportamento de um cliente alheio.</p>
<p class="meta"><b>22635</b> linhas C99/POSIX &middot;
<p class="meta"><b>22785</b> linhas C99/POSIX &middot;
<b>23</b> ferramentas &middot; <b>31</b> programas de teste &middot;
<b>16</b> plugins &middot; <b>42</b> paletas &middot; BSD-3-Clause</p>
+18
View File
@@ -32,6 +32,24 @@ class H(http.server.BaseHTTPRequestHandler):
def log_message(self, *a):
pass
def do_GET(self):
port = self.server.server_address[1]
if self.path.endswith("old-card.json"):
body = {"name": "fake", "version": "1.0.0",
"url": "http://127.0.0.1:%d/rpc" % port}
else:
body = {"name": "fake", "version": "1.0.0",
"supportedInterfaces": [{
"url": "http://127.0.0.1:%d/rpc" % port,
"protocolBinding": "JSONRPC",
"protocolVersion": "1.0"}]}
b = json.dumps(body).encode()
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(b)))
self.end_headers()
self.wfile.write(b)
def do_POST(self):
n = int(self.headers.get("Content-Length", 0))
raw = self.rfile.read(n)
+13
View File
@@ -31,6 +31,11 @@ streaming() { # the one-shot default: stream when the transport can
./splinter --no-config --plugin plugins/a2a/a2a.so \
--transport a2a -p "$1"
}
discovered() { # <card-path> <text>: no URL, only the agent card
SPLINTER_A2A_CARD="http://127.0.0.1:$P/$1" SPLINTER_A2A_TIMEOUT=20 \
./splinter --no-config --plugin plugins/a2a/a2a.so \
--transport a2a --no-stream -p "$2"
}
# ---- blocking: a Task, status message and artifact text ----
out=$(blocking "hallo" 2>&1)
@@ -89,5 +94,13 @@ check test $? -eq 0
grep -q '"method":"SendStreamingMessage"' "$D/req.log"
check test $? -eq 0
# ---- discovery: the card names the JSON-RPC endpoint ----
out=$(discovered ".well-known/agent-card.json" "hallo" 2>&1)
echo "$out" | grep -q 'a2a sagt hallo'
check test $? -eq 0
out=$(discovered "old-card.json" "hallo" 2>&1)
echo "$out" | grep -q 'a2a sagt hallo'
check test $? -eq 0
if [ "$fails" -eq 0 ]; then echo "test_a2a: ok"; exit 0; fi
exit 1