initial: @a2a/mcp gateway for a2acloud agents

Local MCP server that exposes any number of deployed A2A agents to
Claude Code, Cursor, Windsurf, and other MCP clients. Reuses the
~/.a2a/credentials.json token written by the Python a2a CLI. Adding
or removing agents is a single ~/.a2a/mcp.json edit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-11 20:33:54 -03:00
commit 9c5d8172dc
13 changed files with 2738 additions and 0 deletions

46
tests/config.test.ts Normal file
View File

@@ -0,0 +1,46 @@
import { test, beforeEach, afterEach } from "node:test";
import assert from "node:assert/strict";
import os from "node:os";
import path from "node:path";
import { promises as fs } from "node:fs";
import { addAgent, loadConfig, removeAgent } from "../src/config.js";
let originalHome: string | undefined;
let tmpHome: string;
beforeEach(async () => {
originalHome = process.env.HOME;
tmpHome = await fs.mkdtemp(path.join(os.tmpdir(), "a2a-mcp-"));
process.env.HOME = tmpHome;
});
afterEach(async () => {
if (originalHome !== undefined) process.env.HOME = originalHome;
else delete process.env.HOME;
await fs.rm(tmpHome, { recursive: true, force: true });
});
test("loadConfig returns empty when file is missing", async () => {
const cfg = await loadConfig();
assert.deepEqual(cfg, { version: 1, agents: [] });
});
test("addAgent persists and replaces by name", async () => {
await addAgent({ name: "a", url: "https://x", addedAt: "t1" });
await addAgent({ name: "b", url: "https://y", addedAt: "t1" });
await addAgent({ name: "a", url: "https://z", addedAt: "t2" });
const cfg = await loadConfig();
assert.deepEqual(
cfg.agents.map((a) => `${a.name}:${a.url}`),
["a:https://z", "b:https://y"],
);
});
test("removeAgent reports hit/miss", async () => {
await addAgent({ name: "a", url: "https://x", addedAt: "t" });
assert.equal(await removeAgent("missing"), false);
assert.equal(await removeAgent("a"), true);
const cfg = await loadConfig();
assert.equal(cfg.agents.length, 0);
});