From 6c18d7ecf180570a7786a080d371e7d9fa488854 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Wed, 25 Nov 2026 15:37:17 +0100 Subject: [PATCH] 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. --- .../server/src/server/agent/agent-manager.ts | 8 +++- .../server/plugins/agent-tools.e2e.test.ts | 43 +++++++++++++++++++ public-docs/plugins/hooks.md | 5 ++- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/packages/server/src/server/agent/agent-manager.ts b/packages/server/src/server/agent/agent-manager.ts index 47bddabdc7..a422cc4977 100644 --- a/packages/server/src/server/agent/agent-manager.ts +++ b/packages/server/src/server/agent/agent-manager.ts @@ -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> { 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 { diff --git a/packages/server/src/server/plugins/agent-tools.e2e.test.ts b/packages/server/src/server/plugins/agent-tools.e2e.test.ts index 7c6d778f94..f918877edd 100644 --- a/packages/server/src/server/plugins/agent-tools.e2e.test.ts +++ b/packages/server/src/server/plugins/agent-tools.e2e.test.ts @@ -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( diff --git a/public-docs/plugins/hooks.md b/public-docs/plugins/hooks.md index 37a2de6341..d62cb9e542 100644 --- a/public-docs/plugins/hooks.md +++ b/public-docs/plugins/hooks.md @@ -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