Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(eve): pass MCP tool annotations to connection approval policies (#4596)

Ben Pankowf5e5183ae402
diff --git a/.changeset/connection-tool-annotations.md b/.changeset/connection-tool-annotations.md
new file mode 100644
index 000000000..fd462e7eb
--- /dev/null
+++ b/.changeset/connection-tool-annotations.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Connection approval policies now receive `toolAnnotations`, the hints an MCP server declared for the called tool (such as `readOnlyHint` and `destructiveHint`), so a policy can skip approval for read-only tools. It is `undefined` when the server declares none.
diff --git a/docs/connections/mcp.mdx b/docs/connections/mcp.mdx
index f6878088e..428849a35 100644
--- a/docs/connections/mcp.mdx
+++ b/docs/connections/mcp.mdx
@@ -115,7 +115,7 @@ Use the shared `approval` option to gate every tool served by an MCP connection.
### Gate specific tools by name or input
-A remote MCP server usually mixes read tools with destructive or publishing ones, so a blanket `always()` would prompt on every harmless call. Pass a custom policy instead — the same [`Approval`](/docs/human-in-the-loop#approvals) shape authored tools use — to gate only the calls that matter. The policy receives `{ session, toolName, toolInput, approvedTools, callId, abortSignal }` and returns an approval status, synchronously or as a promise.
+A remote MCP server usually mixes read tools with destructive or publishing ones, so a blanket `always()` would prompt on every harmless call. Pass a custom policy instead — the same [`Approval`](/docs/human-in-the-loop#approvals) shape authored tools use — to gate only the calls that matter. The policy receives `{ session, toolName, toolInput, toolAnnotations, approvedTools, callId, abortSignal }` and returns an approval status, synchronously or as a promise.
This connection always gates deletes, gates a publish only when the call actually schedules a post, and lets everything else through:
@@ -157,6 +157,27 @@ Two details are specific to connection tools:
Return `"user-approval"` (or `true`) to pause for a person and `"not-applicable"` (or `false`) to run without a prompt; return `"approved"` or `"denied"` to decide automatically without involving anyone.
+### Gate by the server's tool annotations
+
+Many MCP servers declare [tool annotations](https://modelcontextprotocol.io/specification/2025-06-18/server/tools#tool) such as `readOnlyHint` and `destructiveHint` for each tool. eve passes what the server declared for the called tool as `toolAnnotations`, typed as `ConnectionToolAnnotations` from `eve/tools/approval`. It is `undefined` when the server declares none, so keep a fallback:
+
+```ts title="agent/connections/linear.ts"
+import { connect } from "@vercel/connect/eve";
+import { defineMcpClientConnection } from "eve/connections";
+
+export default defineMcpClientConnection({
+ url: "https://mcp.linear.app/mcp",
+ description: "Linear issues and projects.",
+ auth: connect("mcp.linear.app/linear"),
+ approval: ({ toolAnnotations }) => {
+ if (toolAnnotations?.readOnlyHint === true) return "not-applicable";
+ return "user-approval";
+ },
+});
+```
+
+Annotations are hints from the server, not guarantees. Trust them only as far as you trust the server that sent them.
+
[Human-in-the-loop](/docs/human-in-the-loop#approvals) covers the full set of statuses, how `approvedTools` and `session.auth` factor in, and how a gated call pauses and resumes durably.
## Forward the caller to an eve agent
diff --git a/docs/tools/human-in-the-loop.md b/docs/tools/human-in-the-loop.md
index 7d8ec3d80..156796130 100644
--- a/docs/tools/human-in-the-loop.md
+++ b/docs/tools/human-in-the-loop.md
@@ -64,7 +64,7 @@ approval: auto({
A reusable approval grant applies only after every matching request that is already pending has been resolved. If several calls to a `once()`-gated tool have each produced an approval prompt, approving one does not authorize the others; each visible prompt remains an independent decision. After those pending requests are resolved, later calls in the session are allowed automatically.
-When the decision depends on the input, pass your own policy instead of a helper. It receives the same session context as tool execution, plus `{ toolName, toolInput, approvedTools, callId, abortSignal }`, and returns an AI SDK 7 approval status synchronously or as a promise. Use `abortSignal` for asynchronous policy work so cancellation stops it with the turn. Use `ctx.session.auth.current` to guard by the caller of the current turn and `ctx.session.auth.initiator` to guard by the caller that created the session. Return `"user-approval"` to pause for a person or `"not-applicable"` to continue without a prompt. `toolInput` can be undefined, so guard the access. This policy denies cross-tenant calls, then requires approval only when an amount crosses a threshold:
+When the decision depends on the input, pass your own policy instead of a helper. It receives the same session context as tool execution, plus `{ toolName, toolInput, approvedTools, callId, abortSignal }` (connection tools also get `toolAnnotations`), and returns an AI SDK 7 approval status synchronously or as a promise. Use `abortSignal` for asynchronous policy work so cancellation stops it with the turn. Use `ctx.session.auth.current` to guard by the caller of the current turn and `ctx.session.auth.initiator` to guard by the caller that created the session. Return `"user-approval"` to pause for a person or `"not-applicable"` to continue without a prompt. `toolInput` can be undefined, so guard the access. This policy denies cross-tenant calls, then requires approval only when an amount crosses a threshold:
```ts
approval: ({ session, toolInput }) => {
diff --git a/e2e/fixtures/agent-mcp/agent/agent.ts b/e2e/fixtures/agent-mcp/agent/agent.ts
index a456db1c0..77e85d284 100644
--- a/e2e/fixtures/agent-mcp/agent/agent.ts
+++ b/e2e/fixtures/agent-mcp/agent/agent.ts
@@ -16,6 +16,16 @@ function directiveCall(message: string): MockModelToolCall | undefined {
name: CALL_TOOL,
};
}
+ if (message.includes("MCP_CANCEL")) {
+ return {
+ id: "mcp-cancel",
+ input: {
+ input: { invocationId: "inv_front_desk" },
+ name: `${LOOPBACK_CONNECTION}__agent_cancel`,
+ },
+ name: CALL_TOOL,
+ };
+ }
const notice = PUBLISH_DIRECTIVE.exec(message)?.[1];
if (notice !== undefined) {
return {
diff --git a/e2e/fixtures/agent-mcp/agent/connections/loopback.ts b/e2e/fixtures/agent-mcp/agent/connections/loopback.ts
index 8fb59bf31..d1437bbd8 100644
--- a/e2e/fixtures/agent-mcp/agent/connections/loopback.ts
+++ b/e2e/fixtures/agent-mcp/agent/connections/loopback.ts
@@ -1,12 +1,17 @@
import { defineDynamic, defineMcpClientConnection } from "eve/connections";
-import { SERVICE_TOKEN, previewBypassHeaders, selfMcpUrl } from "../../fixture";
+import { DESTRUCTIVE_DENIAL, SERVICE_TOKEN, previewBypassHeaders, selfMcpUrl } from "../../fixture";
// Resolved per session so the URL is this deployment's, not the build host's.
export default defineDynamic({
events: {
"session.started": () =>
defineMcpClientConnection({
+ // Decides from what the MCP channel declares about each tool, not from its name.
+ approval: ({ toolAnnotations }) =>
+ toolAnnotations?.destructiveHint === true
+ ? { reason: DESTRUCTIVE_DENIAL, type: "denied" }
+ : "not-applicable",
description: "The Maple Street kennel agent's own tools, reached over its MCP channel.",
forwardPrincipal: true,
headers: { ...previewBypassHeaders(), authorization: `Bearer ${SERVICE_TOKEN}` },
diff --git a/e2e/fixtures/agent-mcp/evals/annotations.eval.ts b/e2e/fixtures/agent-mcp/evals/annotations.eval.ts
new file mode 100644
index 000000000..7732ac6e6
--- /dev/null
+++ b/e2e/fixtures/agent-mcp/evals/annotations.eval.ts
@@ -0,0 +1,25 @@
+import { defineEval } from "eve/evals";
+
+import { DESTRUCTIVE_DENIAL } from "../fixture";
+import { requireMockModel } from "./mock-model";
+
+const mentions = (text: string) => (value: unknown) => JSON.stringify(value).includes(text);
+
+export default defineEval({
+ description:
+ "A connection approval policy reads the tool annotations the MCP server declared and denies a tool marked destructive before it runs.",
+
+ async test(t) {
+ requireMockModel(t);
+ const cancelled = await t.send(
+ "Alice asks the front desk to stop yesterday's kennel report run. MCP_CANCEL",
+ );
+ cancelled.expectOk();
+ cancelled.notEvent("input.requested");
+ cancelled.calledTool("loopback__agent_cancel", {
+ count: 1,
+ output: mentions(DESTRUCTIVE_DENIAL),
+ status: "failed",
+ });
+ },
+});
diff --git a/e2e/fixtures/agent-mcp/fixture.ts b/e2e/fixtures/agent-mcp/fixture.ts
index d164e09df..4d06e657c 100644
--- a/e2e/fixtures/agent-mcp/fixture.ts
+++ b/e2e/fixtures/agent-mcp/fixture.ts
@@ -18,6 +18,9 @@ export const LOOPBACK_CONNECTION = "loopback";
export const MCP_PATH = "/eve/v1/mcp";
+/** Why the loopback connection refuses a tool its server marks destructive. */
+export const DESTRUCTIVE_DENIAL = "The front desk does not run tools the server marks destructive.";
+
/** Where the note tools keep the front-desk note in the sandbox. */
export const NOTE_PATH = "/workspace/front-desk-note.txt";
diff --git a/packages/eve/extension-contracts/compatibility/connection/v47.ts b/packages/eve/extension-contracts/compatibility/connection/v47.ts
new file mode 100644
index 000000000..68860de1e
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/connection/v47.ts
@@ -0,0 +1,12 @@
+import { defineMcpClientConnection } from "#public/connections/index.js";
+
+// Epoch 47 approval policies that decide without the server's tool annotations remain supported.
+export default defineMcpClientConnection({
+ description: "Manage issues in the tracker.",
+ url: "https://tracker.example.com/mcp",
+ approval({ toolInput, toolName }) {
+ return toolName.endsWith("__delete_issue") && toolInput !== undefined
+ ? "user-approval"
+ : "not-applicable";
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/dynamicTool/v81.ts b/packages/eve/extension-contracts/compatibility/dynamicTool/v81.ts
new file mode 100644
index 000000000..aa9df0ded
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/dynamicTool/v81.ts
@@ -0,0 +1,15 @@
+import { defineDynamic, defineTool } from "#public/tools/index.js";
+
+// Epoch 81 dynamic tool approval policies that decide without tool annotations remain supported.
+export default defineDynamic({
+ events: {
+ "session.started": () => ({
+ restart: defineTool({
+ approval: ({ toolName }) => (toolName === "restart" ? "user-approval" : "not-applicable"),
+ description: "Restart the service after approval.",
+ inputSchema: { type: "object", properties: {} },
+ execute: () => ({ restarted: true }),
+ }),
+ }),
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/tool/v86.ts b/packages/eve/extension-contracts/compatibility/tool/v86.ts
new file mode 100644
index 000000000..a65e82063
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/tool/v86.ts
@@ -0,0 +1,13 @@
+import { defineTool } from "#public/tools/index.js";
+
+// Epoch 86 approval policies that decide without tool annotations remain supported.
+export default defineTool({
+ approval: ({ toolInput }) => (toolInput?.force === true ? "user-approval" : "not-applicable"),
+ description: "Restart the service, asking first when forced.",
+ inputSchema: {
+ type: "object",
+ properties: { force: { type: "boolean" } },
+ additionalProperties: false,
+ },
+ execute: () => ({ restarted: true }),
+});
diff --git a/packages/eve/extension-contracts/reports/connection/v48.json b/packages/eve/extension-contracts/reports/connection/v48.json
new file mode 100644
index 000000000..e1c3df12e
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/connection/v48.json
@@ -0,0 +1,16 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "connection",
+ "epoch": 48,
+ "sha256": "02f761e273782cad32e4cd96d769b5a7ecd00221526df501d8f0ac7ddb47d12a",
+ "exports": [
+ "ConnectionAuthorizationFailedError",
+ "ConnectionAuthorizationRequiredError",
+ "defineDynamic",
+ "defineInteractiveAuthorization",
+ "defineMcpClientConnection",
+ "defineOpenAPIConnection",
+ "isConnectionAuthorizationFailedError",
+ "isConnectionAuthorizationRequiredError"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/dynamicTool/v82.json b/packages/eve/extension-contracts/reports/dynamicTool/v82.json
new file mode 100644
index 000000000..988bdd28a
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/dynamicTool/v82.json
@@ -0,0 +1,16 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "dynamicTool",
+ "epoch": 82,
+ "sha256": "9d081f5d0179a08b3ea4729adffb59dbe096cf87f95e6e90a330028862ea1b60",
+ "exports": [
+ "DynamicToolEntry",
+ "DynamicToolEvents",
+ "DynamicToolResult",
+ "DynamicToolSet",
+ "auto",
+ "defineDurableCallback",
+ "defineDurableSchema",
+ "defineDynamic"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/tool/v87.json b/packages/eve/extension-contracts/reports/tool/v87.json
new file mode 100644
index 000000000..c4b6eb2db
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/tool/v87.json
@@ -0,0 +1,29 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "tool",
+ "epoch": 87,
+ "sha256": "d828bd8d8395a77356c8ae36b7f6ad2d398ef160778edfa3a6e72417bad993c8",
+ "exports": [
+ "AgentRouterInput",
+ "AgentRouterTool",
+ "WorkflowStepToolContext",
+ "WorkflowTool",
+ "WorkflowToolDefinition",
+ "WorkflowToolInput",
+ "WorkflowToolOptions",
+ "agentRouter",
+ "decide",
+ "defaultWebSearch",
+ "defineTool",
+ "defineWorkflowTool",
+ "disableTool",
+ "isDisabledToolSentinel",
+ "isWebSearchToolDefinition",
+ "serializeModelInputSchema",
+ "toolOutput",
+ "toolOutputPart",
+ "toolResultFrom",
+ "webSearch",
+ "workflow"
+ ]
+}
diff --git a/packages/eve/src/approval/definition.ts b/packages/eve/src/approval/definition.ts
index 2525ff5dd..bd080b586 100644
--- a/packages/eve/src/approval/definition.ts
+++ b/packages/eve/src/approval/definition.ts
@@ -17,10 +17,35 @@ export interface ApprovalContext<TInput = Record<string, unknown>> extends Sessi
readonly abortSignal: AbortSignal;
readonly approvedTools: ReadonlySet<string>;
readonly callId: string;
+ /**
+ * Behavior hints the connection's server declared for this tool, such as
+ * MCP's `readOnlyHint` and `destructiveHint`. Absent for authored tools and
+ * for servers that declare none. Hints are only as trustworthy as the server.
+ */
+ readonly toolAnnotations?: ConnectionToolAnnotations;
readonly toolInput?: ApprovalToolInput<TInput>;
readonly toolName: string;
}
+/**
+ * Behavior hints a connection's server declares for one of its tools. The
+ * named fields follow MCP's `ToolAnnotations`; other keys pass through as the
+ * server sent them.
+ */
+export interface ConnectionToolAnnotations {
+ /** Human-readable tool title. */
+ readonly title?: string;
+ /** The tool does not modify its environment. */
+ readonly readOnlyHint?: boolean;
+ /** The tool may perform destructive updates. Meaningful only when not read-only. */
+ readonly destructiveHint?: boolean;
+ /** Repeating a call with the same arguments has no additional effect. */
+ readonly idempotentHint?: boolean;
+ /** The tool may interact with an open world of external entities. */
+ readonly openWorldHint?: boolean;
+ readonly [key: string]: unknown;
+}
+
/** Request-time approval decision returned by an {@link ApprovalPolicy}. */
export type ApprovalStatus =
| undefined
diff --git a/packages/eve/src/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.ts
index 191921dbd..977640287 100644
--- a/packages/eve/src/compiler/extension-compatibility.ts
+++ b/packages/eve/src/compiler/extension-compatibility.ts
@@ -22,10 +22,10 @@ interface ExtensionCapabilityContract {
const EXTENSION_CAPABILITY_CONTRACTS = {
extension: { current: 1, supported: [1], dropped: {} },
tool: {
- current: 86,
+ current: 87,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 29, 30, 31, 32, 34, 35, 76, 77, 78, 80, 81, 82, 84,
- 85, 86,
+ 85, 86, 87,
],
dropped: {
14: "TaskExec.delegated was removed; migrate to workflow-backed background tools",
@@ -89,10 +89,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
dynamicTool: {
- current: 81,
+ current: 82,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 31, 32, 33, 52, 54,
- 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 79, 80, 81,
+ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82,
],
dropped: {
21: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
@@ -188,10 +188,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
connection: {
- current: 47,
+ current: 48,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 32, 33, 34,
- 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47,
+ 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48,
],
dropped: {
9: "Dynamic connection resolvers no longer receive conversation or channel continuation data",
diff --git a/packages/eve/src/execution/catalog/connection-entry.test.ts b/packages/eve/src/execution/catalog/connection-entry.test.ts
new file mode 100644
index 000000000..fa798e701
--- /dev/null
+++ b/packages/eve/src/execution/catalog/connection-entry.test.ts
@@ -0,0 +1,96 @@
+import { describe, expect, it, vi } from "vitest";
+
+import type { ApprovalContext, ApprovalPolicy } from "#approval/definition.js";
+import { ContextContainer, contextStorage } from "#context/container.js";
+import { resolveApprovalPolicy } from "#approval/definition.js";
+import type { ConnectionRegistry } from "#runtime/connections/registry-types.js";
+import type { ResolvedConnectionDefinition } from "#runtime/types.js";
+import type { ConnectionClient, ConnectionToolMetadata } from "#shared/connection-types.js";
+
+import { connectionEntry } from "./connection-entry.js";
+
+const tools: readonly ConnectionToolMetadata[] = [
+ {
+ annotations: { destructiveHint: true, readOnlyHint: false, title: "Delete issue" },
+ description: "Delete an issue.",
+ inputSchema: { type: "object" },
+ name: "delete_issue",
+ },
+ { description: "List issues.", inputSchema: { type: "object" }, name: "list_issues" },
+];
+
+/** Bob's tracker connection, whose approval policy records each context it receives. */
+function setup(getToolMetadata: ConnectionClient["getToolMetadata"] = async () => tools) {
+ const seen: ApprovalContext[] = [];
+ const policy = vi.fn<ApprovalPolicy>((context) => {
+ seen.push(context);
+ return "user-approval";
+ });
+ const connection = {
+ approval: policy,
+ connectionName: "tracker",
+ description: "Issue tracker.",
+ logicalPath: "connections/tracker.ts",
+ protocol: "mcp",
+ sourceId: "tracker",
+ sourceKind: "module",
+ url: "https://tracker.example.com/mcp",
+ } as ResolvedConnectionDefinition;
+ const client: ConnectionClient = {
+ close: async () => {},
+ connect: async () => undefined,
+ executeTool: async () => {
+ throw new Error("Approval never runs the tool.");
+ },
+ getToolMetadata,
+ };
+ const registry: ConnectionRegistry = {
+ dispose: async () => {},
+ getClient: () => client,
+ getConnectionApproval: () => policy,
+ getConnectionNames: () => ["tracker"],
+ getConnections: () => [connection],
+ };
+ const request = (toolName: string) => {
+ const approval = connectionEntry(registry, connection, toolName).approval!;
+ const context: ApprovalContext = {
+ abortSignal: new AbortController().signal,
+ approvedTools: new Set<string>(),
+ callId: `call-${toolName}`,
+ getSandbox: () => Promise.reject(new Error("Approval never opens a sandbox.")),
+ session: {} as ApprovalContext["session"],
+ toolName: `tracker__${toolName}`,
+ };
+ return contextStorage.run(new ContextContainer(), () =>
+ resolveApprovalPolicy(approval)(context),
+ );
+ };
+ return { request, seen };
+}
+
+describe("connection approval context", () => {
+ it("passes the annotations the server declared for the called tool", async () => {
+ const { request, seen } = setup();
+ await expect(request("delete_issue")).resolves.toBe("user-approval");
+ expect(seen[0]?.toolAnnotations).toEqual({
+ destructiveHint: true,
+ readOnlyHint: false,
+ title: "Delete issue",
+ });
+ expect(seen[0]?.toolName).toBe("tracker__delete_issue");
+ });
+
+ it("leaves annotations out when the server declared none", async () => {
+ const { request, seen } = setup();
+ await request("list_issues");
+ expect(seen[0]).not.toHaveProperty("toolAnnotations");
+ });
+
+ it("still asks the policy when the tools can't be listed", async () => {
+ const { request, seen } = setup(async () => {
+ throw new Error("tracker is down");
+ });
+ await expect(request("delete_issue")).resolves.toBe("user-approval");
+ expect(seen[0]).not.toHaveProperty("toolAnnotations");
+ });
+});
diff --git a/packages/eve/src/execution/catalog/connection-entry.ts b/packages/eve/src/execution/catalog/connection-entry.ts
index 0a78d66d2..8df9ccc7a 100644
--- a/packages/eve/src/execution/catalog/connection-entry.ts
+++ b/packages/eve/src/execution/catalog/connection-entry.ts
@@ -15,12 +15,13 @@ import {
type ApprovalResponseDecision,
type ApprovalResponsePolicy,
type ApprovalStatus,
+ type ConnectionToolAnnotations,
} from "#approval/definition.js";
import { isConnectionAuthorizationRequiredError } from "#connections/errors.js";
import { connectionToolName } from "#connections/ownership.js";
import { loadContext } from "#context/container.js";
import { ContextKey } from "#context/key.js";
-import { isApprovalRecheck } from "#harness/approval-recheck.js";
+import { isApprovalRecheck, markApprovalRecheck } from "#harness/approval-recheck.js";
import type { AuthorizationSignal } from "#harness/authorization.js";
import type { HarnessToolDefinition } from "#harness/execute-tool.js";
import type { ConnectionRegistry } from "#runtime/connections/registry-types.js";
@@ -78,7 +79,7 @@ export function connectionEntry(
): HarnessToolDefinition {
const label = `${displayProperName(connection.connectionName)}: ${displayTitle(toolName)}`;
return {
- approval: connectionApproval(connection),
+ approval: connectionApproval(registry, connection, toolName),
deferred: true,
description: "",
execute: (input: unknown, options: ToolExecuteOptions) =>
@@ -260,11 +261,20 @@ function unknownToolMessage(
* phase exists only when the connection defines one; without it, the pin is
* checked when the approved call runs.
*/
-function connectionApproval(connection: ResolvedConnectionDefinition): Approval | undefined {
+function connectionApproval(
+ registry: ConnectionRegistry,
+ connection: ResolvedConnectionDefinition,
+ toolName: string,
+): Approval | undefined {
const { approval } = connection;
if (approval === undefined) return undefined;
const policy = resolveApprovalPolicy(approval);
- const request = (context: ApprovalContext) => requestApproval(connection, policy, context);
+ const request = async (context: ApprovalContext) =>
+ requestApproval(
+ connection,
+ policy,
+ withToolAnnotations(context, await toolAnnotations(registry, connection, toolName)),
+ );
const response = typeof approval === "function" ? undefined : approval.response;
if (response === undefined) return request;
return {
@@ -291,6 +301,33 @@ async function requestApproval(
return status;
}
+/** What the server declared about `toolName`, or nothing when it declared none or can't list. */
+async function toolAnnotations(
+ registry: ConnectionRegistry,
+ connection: ResolvedConnectionDefinition,
+ toolName: string,
+): Promise<ConnectionToolAnnotations | undefined> {
+ try {
+ const tools = await listToolMetadata(
+ connection.connectionName,
+ registry.getClient(connection.connectionName),
+ );
+ return tools.find((tool) => tool.name === toolName)?.annotations;
+ } catch {
+ // Input validation already reported a listing failure; a sign-in the call needs comes later.
+ return undefined;
+ }
+}
+
+function withToolAnnotations(
+ context: ApprovalContext,
+ annotations: ConnectionToolAnnotations | undefined,
+): ApprovalContext {
+ if (annotations === undefined) return context;
+ const annotated = { ...context, toolAnnotations: annotations };
+ return isApprovalRecheck(context) ? markApprovalRecheck(annotated) : annotated;
+}
+
function parksForApproval(status: ApprovalStatus): boolean {
return (
status === true ||
diff --git a/packages/eve/src/public/definitions/approval.ts b/packages/eve/src/public/definitions/approval.ts
index 87bb1711c..3abfd6462 100644
--- a/packages/eve/src/public/definitions/approval.ts
+++ b/packages/eve/src/public/definitions/approval.ts
@@ -11,5 +11,6 @@ export type {
ApprovalResponsePolicy,
ApprovalResponseSession,
ApprovalStatus,
+ ConnectionToolAnnotations,
} from "#approval/definition.js";
export { resolveApprovalPolicy } from "#approval/definition.js";
diff --git a/packages/eve/src/public/tools/approval/index.ts b/packages/eve/src/public/tools/approval/index.ts
index 5fe6a0963..b62ea7854 100644
--- a/packages/eve/src/public/tools/approval/index.ts
+++ b/packages/eve/src/public/tools/approval/index.ts
@@ -15,6 +15,7 @@ export type {
ApprovalResponsePolicy,
ApprovalResponseSession,
ApprovalStatus,
+ ConnectionToolAnnotations,
} from "#public/definitions/approval.js";
export type { AutoApprovalOptions } from "#tools/approval/policies.js";
export { always, auto, never, once } from "#tools/approval/policies.js";