feat(slack-relay): gated agents see every agent on the relay (mcp__relay_agents)

Merged
KH
5d ago
+629-31

Problem

Behind relaygate (gate-only installs), a Slack thread agent asked to message another agent answered that its relay connection had "no workspace key set up" and it couldn't see any agents outside its thread.

Cause: the agent's relay tools are @relaycast/mcp (12.8.0) with RELAY_BASE_URL=<relaygate> and the agent's rg_ token. Its agent.list calls requireWorkspaceKey() and throws Workspace key not configured before any request. A gated agent never has a workspace key: relaygate holds it. relaygate itself already proxies GET /v1/agents and /v1/agents/:name for an rg_ token (answered with its workspace key, filtered by policy), so the gate was never asked. The MCP also has no agent-card tool.

A second gap: relaygate showed only agents whose inbox the caller may read or write, so desktop/editor agents whose names match no inbox prefix stayed invisible to the pit. That is fixed in AgentWorkforce/relaygate#41 (a visibility-only r on relaycast:agent/<name>).

Change

  • src/agents-mcp.ts (new): stdio MCP relay_agents with list_agents (status, include_stale) and get_agent (status, persona, card). Each is a GET to relaygate with the agent's own rg_ token. No write tools; credential-looking fields dropped; errors are plain ("not found or not visible to you"), never "workspace key".
  • main.ts: behind relaygate (host.relayAgentsMcp / RELAY_AGENTS_MCP, default true) each agent gets mcp__relay_agents, and mcp__relaycast__agent_list plus mcp__relaycast__workspace_* are disallowed (they can only fail without a key).
  • host.ts: behind relaygate the system prompt says the agent can see every agent on the relay, can message agents in its own group, can't message agents outside it (local/desktop/editor agents; relaygate refuses with relaygate_denied), and must never cite a workspace key.
  • relaygate chart default policy: { prefix: "relaycast:agent/", gid: 22, mode: "040" }: the pit sees every agent; local agents' view is unchanged. Visibility only: messaging outside the pit is still denied (no w on outside inboxes). Older relaygate images ignore it.
  • Versions: slack-relay 0.3.10, relaygate 0.1.9, agent-relay 0.7.48 (0.3.9/0.7.47 left for #439; expect a rebase). Requirements registry and generated doc updated.
  • Docs: "What the agents see on the relay" in docs/self-hosted-slack-relay.md (with the exact policy line), directory row in docs/self-hosted-relaygate.md.

What a deployer grants

For the pit to see every agent: r on relaycast:agent/ for gid 22, i.e. keep (or add, if you override policy.streamDefaults):

- { prefix: "relaycast:agent/", gid: 22, mode: "040" }

Needs a relaygate image with #41. Without it, the pit sees agents whose inbox it may read or write (default policy: its own group and local-*).

Tests

  • test/agents-mcp.test.ts (fake gate): list/get as the agent (GET only, Bearer rg_), filters, scrubbed fields, 404/401/down errors without workspace-key talk, invalid input never sent, stdio round trip, system prompt text, and a regression test that spawns the real @relaycast/mcp and shows agent.list refusing with Workspace key not configured without asking the gate.
  • npm test 94 pass / 0 fail (9 skipped e2e), tsc --noEmit clean; scripts/ci/charts.sh static, ci/agent-relay/render.sh, scripts/ci/deps.sh, registry check all pass locally.

Not merged or deployed; no image built.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Behind relaygate, Slack thread agents could not see the other agents on the relay: @relaycast/mcp's agent.list throws "workspace key not configured" before making any request, and a gated agent never holds a workspace key (relaygate does). Gated agents now get a read-only mcp__relay_agents MCP that lists agents and reads their status, persona and card through relaygate with each agent's own rg_ token, and relaygate's default policy now shows the pit every agent (visibility only). CI e2e policy checks carry the same default as the chart.

  • Behind relaygate each agent gets mcp__relay_agents (default on, host.relayAgentsMcp, independent of relaycastMcp); list_agents pages and filters so every visible agent is reachable. The Relaycast agent.list and workspace tools, which can only fail without a key, are disallowed.
  • An OAuth MCP server named relay_agents can no longer replace the built-in one.
  • The system prompt now says agents see every agent on the relay, can message only their own group, and must never cite a missing workspace key.

Migration

  • Deployers who override policy.streamDefaults must keep the new - { prefix: "relaycast:agent/", gid: 22, mode: "040" } line and use a relaygate image with the agent directory (relaygate#41); older images ignore it and the pit only sees agents whose inbox it may read or write.