fix(server): reserve only Paseo's own tool names when a plugin refresh checks collisions

The agent's catalog also lists its plugin tools, so a later plugin rerun by an earlier plugin's edit saw its own tool as taken and lost it. The session owner settles names between plugins from its record. The hooks reference now says an MCP server name collision fails the reopen without hiding tools.
This commit is contained in:
Mohamed Boudra
2026-11-25 15:37:17 +01:00
parent 8747a78457
commit 6c18d7ecf1
3 changed files with 52 additions and 4 deletions
@@ -1162,14 +1162,18 @@ export class AgentManager {
);
}
/** Paseo's own tool names, including the ones the agent's provider disables, and its running plugin tools. */
/**
* Paseo's own tool names for the agent, including the ones its provider disables. The catalog also lists the
* agent's plugin tools; the plugin session owner settles those names between plugins itself.
*/
private async reservedAgentToolNames(agentId: string): Promise<ReadonlySet<string>> {
if (!this.paseoToolCatalogFactory) return new Set();
const pluginToolNames = new Set(this.getPluginTools(agentId).map((tool) => tool.name));
const catalog = await this.paseoToolCatalogFactory({
callerAgentId: agentId,
paseoToolPolicy: {},
});
return new Set(catalog.tools.keys());
return new Set([...catalog.tools.keys()].filter((name) => !pluginToolNames.has(name)));
}
private detachPluginTools(agentId: string): void {
@@ -938,6 +938,49 @@ test("a plugin reruns when an earlier plugin changes what it receives, and the s
}
}, 60_000);
const hintSource = (hint: string) => `
export default function contribute(server) {
server.addHook("agent.open.before", async ({ request }) => ({ ...request, env: { ...request.env, HINT: ${JSON.stringify(hint)} } }));
return () => {};
}
`;
const hintReaderSource = `
import { z } from "zod";
import { defineAgentTool } from "@getpaseo/plugin/server";
export default function contribute(server) {
server.addHook("agent.open.before", async ({ request }) => {
const { HINT: hint, ...env } = request.env;
const tool = defineAgentTool({
name: "read_tool_hint", description: "The hint from the plugin before",
input: z.object({}),
async execute() { return { text: String(hint) }; },
});
return { ...request, env, tools: [...request.tools, tool] };
});
return () => {};
}
`;
test("a later plugin rerun by an earlier plugin's edit keeps its own tool, and the session keeps running", async () => {
const h = await setup(false, openCounterSource);
try {
await h.install("a-hint", hintSource("red"));
await h.install("b-hint-reader", hintReaderSource);
const a = await h.create();
await writePluginSource(h, "a-hint", hintSource("green"));
await h.client.reloadPlugin("a-hint");
expect(
await (await h.mcp(a.id)).callTool({ name: "read_tool_hint", arguments: {} }),
).toMatchObject({ content: [{ type: "text", text: "green" }] });
// b-hint-reader removes the hint, so the launch is unchanged.
await sendAndFinish(h, a.id, "after hint change");
expect(h.launches).toHaveLength(1);
} finally {
await h.close();
}
}, 60_000);
// Once armed, the module waits for the gate file before it loads, which holds a restart between stop and start.
const gatedStartSource = (arm: string, entered: string, gate: string) =>
openCounterSource.replace(
+3 -2
View File
@@ -524,8 +524,9 @@ the session continues as if the plugin stopped.
- If the callback throws or times out, its tools stay off, and the session reopens before its next
idle prompt. Paseo does not rerun it for the same plugin instance.
- If a returned tool collides with a Paseo tool or another plugin's tool, that plugin's tools stay
off, and the session reopens before its next idle prompt. The same happens when two plugins return
the same MCP server name. That prompt fails with the collision error.
off, and the session reopens before its next idle prompt.
- If two plugins return the same MCP server name, both plugins keep their agent tools, but the reopen
before the next idle prompt fails with the collision error.
Agents that receive Paseo tools natively (OpenCode with the bridge, OMP) keep the tool list they
launched with until the reopen. Their calls to a listed tool reach the new instance of the plugin