Refuse a tool policy on plugin providers without permission.tool_policy as tool_policy_unsupported (#10889)

A plugin provider's connection negotiates permission.tool_policy, so the
registry lets a toolPolicy through. When the connection does not offer it,
ProviderRuntime.openSession threw a plain Error, which Hub reported as
create_failed instead of tool_policy_unsupported. It now throws
ToolPolicyUnsupportedError before sending session.open.
This commit is contained in:
Mohamed Boudra authored and GitHub committed 2026-11-26 12:01:05 +07:00
1 parent 5238bfb641
commit c0903be174
2 files changed
+77 -1

No files matched your search

@@ -25,6 +25,7 @@ import { AgentManager } from "./agent-manager.js";
import { buildProviderRegistry } from "./provider-registry.js";
import { ProviderOverrideSchema } from "@getpaseo/protocol/provider-config";
import { PluginAgentClientRegistry } from "./plugin-provider.js";
import { ToolPolicyUnsupportedError } from "./provider-options.js";
import { runProviderRefreshWithDeadline } from "./provider-refresh-deadline.js";
import {
isStaleProviderSessionError,
@@ -3869,3 +3870,70 @@ test("a plugin session reopen sends the wrap the session opened with", async ()
await session.close();
await registry.shutdown();
});
describe("plugin provider tool policy", () => {
const hubMcpServers = { hub: { type: "http" as const, url: "https://hub.test/mcp" } };
const grants = { preapproved: [{ kind: "mcp" as const, server: "hub", tool: "reply" }] };
async function createWithToolPolicy(
capabilities: ProviderConnection["capabilities"],
toolPolicy: { preapproved: (typeof grants)["preapproved"] },
) {
const logger = createTestLogger();
const harness = createProviderHarness({ capabilities });
const plugins = new PluginAgentClientRegistry(logger);
plugins.replace([harness.registration]);
const registry = buildProviderRegistry(logger, { pluginProviders: plugins.definitions() });
const manager = new AgentManager({
logger,
clients: { "plugin-direct": registry["plugin-direct"].createClient(logger) },
providerDefinitions: { "plugin-direct": registry["plugin-direct"] },
});
const created = manager
.createAgent(
{ provider: "plugin-direct", cwd: tmpdir(), mcpServers: hubMcpServers, toolPolicy },
undefined,
{ workspaceId: undefined },
)
.then(
(agent) => ({ agent, error: null }),
(error: unknown) => ({ agent: null, error }),
);
const result = await created;
const opened = harness.inputs.filter((input) => input.type === "session.open");
await Promise.all(manager.listAgents().map((item) => manager.closeAgent(item.id)));
await plugins.shutdown();
return { ...result, opened };
}
test.each([
["exact grants", grants],
["an empty grant list", { preapproved: [] }],
])(
"a plugin without permission.tool_policy refuses %s with ToolPolicyUnsupportedError",
async (_label, toolPolicy) => {
const result = await createWithToolPolicy(CAPABILITIES, toolPolicy);
expect(result.error).toBeInstanceOf(ToolPolicyUnsupportedError);
expect(result.error).toMatchObject({
code: "tool_policy_unsupported",
provider: "plugin-direct",
});
expect(result.opened).toEqual([]);
},
);
test.each([
["exact grants", grants],
["an empty grant list", { preapproved: [] }],
])("a plugin with permission.tool_policy opens with %s", async (_label, toolPolicy) => {
const result = await createWithToolPolicy(
[...CAPABILITIES, "permission.tool_policy"],
toolPolicy,
);
expect(result.error).toBeNull();
expect(result.opened).toHaveLength(1);
expect(result.opened[0]).toMatchObject({ config: { toolPolicy } });
});
});
@@ -81,7 +81,7 @@ import {
formatProviderDiagnostic,
type DiagnosticEntry,
} from "./providers/diagnostic-utils.js";
import { LaunchWrapUnsupportedError } from "./provider-options.js";
import { LaunchWrapUnsupportedError, ToolPolicyUnsupportedError } from "./provider-options.js";
import type { RegisteredProviderDefinition } from "./provider-registry.js";
import { runProviderTurn } from "./providers/provider-runner.js";
import { StaleProviderSessionError } from "./stale-provider-session-error.js";
@@ -349,6 +349,12 @@ class ProviderRuntime {
throw new Error(`Provider session already exists: ${input.sessionId}`);
}
const connection = await this.getConnection();
if (input.config.toolPolicy && !connection.capabilities.includes("permission.tool_policy")) {
throw new ToolPolicyUnsupportedError(
this.registration.id,
`Provider '${this.registration.id}' cannot preapprove exact MCP tools: its connection does not offer permission.tool_policy`,
);
}
requireProviderCapabilities(connection.capabilities, {
type: "session.open",
requestId: "capability-check",
@@ -1063,6 +1069,8 @@ function createPluginProviderDefinition(
requiresConfiguration: registration.requiresConfiguration,
defaultModeId: null,
modes: [],
// Each connection negotiates permission.tool_policy, so the registry lets a policy through and
// ProviderRuntime.openSession refuses it with ToolPolicyUnsupportedError when it is not offered.
supportsExactMcpPreapproval: true,
supportsLaunchWrap: registration.launchWrap === true,
createClient,