Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): distinct toolResultFrom identity for connections sharing a host (#4745)

roboeve[bot]57d4272b7a39
diff --git a/.changeset/toolresultfrom-same-host-connections.md b/.changeset/toolresultfrom-same-host-connections.md
new file mode 100644
index 000000000..8e7e20a53
--- /dev/null
+++ b/.changeset/toolresultfrom-same-host-connections.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Connections that share a host, such as Jira and Confluence on one Atlassian domain, no longer trigger the "could not assign a unique toolResultFrom identity" warning, and `toolResultFrom` now accepts OpenAPI connections, including ones without a `baseUrl`.
diff --git a/docs/guides/hooks.md b/docs/guides/hooks.md
index 32c0b46a8..06e29e1fe 100644
--- a/docs/guides/hooks.md
+++ b/docs/guides/hooks.md
@@ -97,7 +97,7 @@ when the parent's current model step ends if one is running.
### Narrowing tool results
-`toolResultFrom` narrows an `action.result` event to a specific authored tool or MCP connection and returns typed output. Import it from `eve/tools`:
+`toolResultFrom` narrows an `action.result` event to a specific authored tool or connection (MCP or OpenAPI) and returns typed output. Import it from `eve/tools`:
```ts
import { defineHook } from "eve/hooks";
@@ -114,7 +114,7 @@ export default defineHook({
console.log(weather.output.temperature);
}
- // MCP connection: output is unknown, toolName is qualified
+ // Connection: output is unknown, toolName is qualified
const linearResult = toolResultFrom(event.data.result, linear);
if (linearResult) {
console.log(linearResult.connectionToolName, linearResult.output);
diff --git a/packages/eve/extension-contracts/compatibility/tool/v88.ts b/packages/eve/extension-contracts/compatibility/tool/v88.ts
new file mode 100644
index 000000000..a3c62d96d
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/tool/v88.ts
@@ -0,0 +1,10 @@
+import { defineMcpClientConnection } from "#public/connections/index.js";
+import { toolResultFrom } from "#public/tools/index.js";
+import type { RuntimeActionResult } from "#shared/action-types.js";
+
+// Epoch 88 extensions narrowed connection results through an MCP connection.
+const linear = defineMcpClientConnection({ description: "Linear", url: "https://mcp.linear.app" });
+
+export function linearToolName(result: RuntimeActionResult): string | undefined {
+ return toolResultFrom(result, linear)?.connectionToolName;
+}
diff --git a/packages/eve/extension-contracts/reports/tool/v89.json b/packages/eve/extension-contracts/reports/tool/v89.json
new file mode 100644
index 000000000..fcf0d8234
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/tool/v89.json
@@ -0,0 +1,29 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "tool",
+ "epoch": 89,
+ "sha256": "8b98133d92393dc0dc389abd4c107537f4f656ba621ee108f4fc967508d9081a",
+ "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/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.ts
index 49764ae63..3f070527e 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: 88,
+ current: 89,
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, 87, 88,
+ 85, 86, 87, 88, 89,
],
dropped: {
14: "TaskExec.delegated was removed; migrate to workflow-backed background tools",
diff --git a/packages/eve/src/internal/authored-definition/source-identity.ts b/packages/eve/src/internal/authored-definition/source-identity.ts
index d6cbad5b4..96101f6e3 100644
--- a/packages/eve/src/internal/authored-definition/source-identity.ts
+++ b/packages/eve/src/internal/authored-definition/source-identity.ts
@@ -43,6 +43,15 @@ export function stampDefinitionKey(definition: object, key: string): void {
Object.defineProperty(definition, DEFINITION_KEY, { configurable: true, value: key });
}
+/**
+ * Fallback key shared by the connection factories and the resolver. The
+ * description keeps connections on one host, such as Jira and Confluence,
+ * distinct.
+ */
+export function connectionDefinitionKey(url: string, description: string): string {
+ return `connection:${JSON.stringify([url, description])}`;
+}
+
/**
* Records a definition object eve loaded under one mounted name. The same
* object can be mounted more than once, for example when a subagent re-exports
diff --git a/packages/eve/src/public/definitions/connections/mcp.ts b/packages/eve/src/public/definitions/connections/mcp.ts
index f54d5ea38..dce49bc90 100644
--- a/packages/eve/src/public/definitions/connections/mcp.ts
+++ b/packages/eve/src/public/definitions/connections/mcp.ts
@@ -7,7 +7,10 @@ import type { ConnectionToolCallDefinition } from "#public/definitions/connectio
import { normalizeAuthorizationSpec } from "#shared/validate-authorization.js";
import { stampConnectionProtocol } from "#public/definitions/connections/protocol.js";
import type { Approval } from "#public/definitions/approval.js";
-import { stampDefinitionKey } from "#internal/authored-definition/source-identity.js";
+import {
+ connectionDefinitionKey,
+ stampDefinitionKey,
+} from "#internal/authored-definition/source-identity.js";
/**
* Public definition for an MCP client connection authored in
@@ -129,7 +132,7 @@ export function defineMcpClientConnection(
if (definition.auth !== undefined && typeof definition.auth !== "function") {
definition.auth = normalizeAuthorizationSpec(definition.auth, "defineMcpClientConnection:");
}
- stampDefinitionKey(definition, `connection:${definition.url}`);
+ stampDefinitionKey(definition, connectionDefinitionKey(definition.url, definition.description));
stampConnectionProtocol(definition, "mcp");
return definition;
}
diff --git a/packages/eve/src/public/definitions/connections/openapi.ts b/packages/eve/src/public/definitions/connections/openapi.ts
index faa416dc3..5bdc0fb71 100644
--- a/packages/eve/src/public/definitions/connections/openapi.ts
+++ b/packages/eve/src/public/definitions/connections/openapi.ts
@@ -6,7 +6,10 @@ import type {
import { normalizeAuthorizationSpec } from "#shared/validate-authorization.js";
import { stampConnectionProtocol } from "#public/definitions/connections/protocol.js";
import type { Approval } from "#public/definitions/approval.js";
-import { stampDefinitionKey } from "#internal/authored-definition/source-identity.js";
+import {
+ connectionDefinitionKey,
+ stampDefinitionKey,
+} from "#internal/authored-definition/source-identity.js";
import type { ConnectionToolCallDefinition } from "#public/definitions/connections/tool-call.js";
/**
@@ -132,10 +135,10 @@ export function defineOpenAPIConnection(
if (definition.auth !== undefined && typeof definition.auth !== "function") {
definition.auth = normalizeAuthorizationSpec(definition.auth, "defineOpenAPIConnection:");
}
- const definitionKey =
- definition.baseUrl ??
- (typeof definition.spec === "string" ? definition.spec : definition.description);
- stampDefinitionKey(definition, `connection:${definitionKey}`);
+ stampDefinitionKey(
+ definition,
+ connectionDefinitionKey(definition.baseUrl ?? "", definition.description),
+ );
stampConnectionProtocol(definition, "openapi");
return definition;
}
diff --git a/packages/eve/src/public/tools/result.test.ts b/packages/eve/src/public/tools/result.test.ts
index bb2ef0ac8..5e6ea7703 100644
--- a/packages/eve/src/public/tools/result.test.ts
+++ b/packages/eve/src/public/tools/result.test.ts
@@ -4,7 +4,10 @@ import { z } from "#compiled/zod/index.js";
import type { RuntimeActionResult } from "#shared/action-types.js";
import { defineMcpClientConnection } from "#public/definitions/connections/mcp.js";
import { defineTool } from "#tools/definition.js";
-import { registerDefinitionSource } from "#internal/authored-definition/source-identity.js";
+import {
+ connectionDefinitionKey,
+ registerDefinitionSource,
+} from "#internal/authored-definition/source-identity.js";
import {
toolResultFrom,
type MatchedConnectionResult,
@@ -63,7 +66,7 @@ describe("toolResultFrom", () => {
registerDefinitionSource(
linearConnection,
{ kind: "connection", name: "linear" },
- "connection:https://mcp.linear.app",
+ connectionDefinitionKey("https://mcp.linear.app", "Linear"),
);
it("matches an authored tool result and returns typed output", () => {
@@ -219,32 +222,32 @@ describe("toolResultFrom", () => {
expect(result).toBeUndefined();
});
- it("uses loaded definitions to distinguish connections with the same URL", () => {
+ it("uses loaded definitions to distinguish connections with the same URL and description", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const first = defineMcpClientConnection({
url: "https://mcp.example.test",
- description: "First",
+ description: "Shared",
});
const second = defineMcpClientConnection({
url: "https://mcp.example.test",
- description: "Second",
+ description: "Shared",
});
registerDefinitionSource(
first,
{ kind: "connection", logicalPath: "connections/first.ts", name: "first" },
- "connection:https://mcp.example.test",
+ connectionDefinitionKey("https://mcp.example.test", "Shared"),
);
registerDefinitionSource(
second,
{ kind: "connection", logicalPath: "connections/second.ts", name: "second" },
- "connection:https://mcp.example.test",
+ connectionDefinitionKey("https://mcp.example.test", "Shared"),
);
expect(warn).toHaveBeenCalledOnce();
expect(warn).toHaveBeenCalledWith(
expect.stringContaining(
- 'eve could not assign a unique toolResultFrom identity for "connection:https://mcp.example.test"',
+ `eve could not assign a unique toolResultFrom identity for ${JSON.stringify(connectionDefinitionKey("https://mcp.example.test", "Shared"))}`,
),
);
expect(warn).toHaveBeenCalledWith(
diff --git a/packages/eve/src/public/tools/result.ts b/packages/eve/src/public/tools/result.ts
index f086f4c6a..1fbb0e085 100644
--- a/packages/eve/src/public/tools/result.ts
+++ b/packages/eve/src/public/tools/result.ts
@@ -1,5 +1,6 @@
import type { RuntimeActionResult } from "#shared/action-types.js";
import type { McpClientConnectionDefinition } from "#public/definitions/connections/mcp.js";
+import type { OpenAPIConnectionDefinition } from "#public/definitions/connections/openapi.js";
import { readDefinitionSource } from "#internal/authored-definition/source-identity.js";
import type { ToolDefinition } from "#tools/definition.js";
@@ -17,10 +18,10 @@ export interface MatchedToolResult<TOutput> {
/**
* Narrowed tool result returned by {@link toolResultFrom} when the
- * action result matches an MCP connection.
+ * action result matches an MCP or OpenAPI connection.
*
- * `output` stays `unknown` because MCP tool schemas are remote.
- * `connectionToolName` is the unqualified MCP tool name (e.g.
+ * `output` stays `unknown` because connection tool schemas are remote.
+ * `connectionToolName` is the unqualified connection tool name (e.g.
* `"list_issues"`) while `toolName` is the full qualified name
* (e.g. `"linear__list_issues"`).
*/
@@ -33,6 +34,8 @@ export interface MatchedConnectionResult {
const CONNECTION_TOOL_SEPARATOR = "__";
+type ConnectionDefinition = McpClientConnectionDefinition | OpenAPIConnectionDefinition;
+
/**
* Overloaded signature for {@link toolResultFrom}.
*/
@@ -44,7 +47,7 @@ export interface ToolResultFromFn {
(
result: RuntimeActionResult,
- connection: McpClientConnectionDefinition,
+ connection: ConnectionDefinition,
): MatchedConnectionResult | undefined;
}
@@ -52,9 +55,9 @@ export interface ToolResultFromFn {
* Narrows a {@link RuntimeActionResult} to a typed tool or connection
* result by matching against an authored definition object.
*
- * Pass a `ToolDefinition` to get a typed `output`; pass a
- * `McpClientConnectionDefinition` to match any tool from that
- * connection (`output` stays `unknown`).
+ * Pass a `ToolDefinition` to get a typed `output`; pass an MCP or OpenAPI
+ * connection definition to match any tool from that connection (`output`
+ * stays `unknown`).
*
* Returns `undefined` when the result doesn't match, or when
* `isError` is `true`.
@@ -67,11 +70,11 @@ function toolResultFromImpl<TInput, TOutput>(
): MatchedToolResult<TOutput> | undefined;
function toolResultFromImpl(
result: RuntimeActionResult,
- connection: McpClientConnectionDefinition,
+ connection: ConnectionDefinition,
): MatchedConnectionResult | undefined;
function toolResultFromImpl(
result: RuntimeActionResult,
- source: ToolDefinition<unknown, unknown> | McpClientConnectionDefinition,
+ source: ToolDefinition<unknown, unknown> | ConnectionDefinition,
): MatchedToolResult<unknown> | MatchedConnectionResult | undefined {
if (result.kind !== "tool-result") return undefined;
if (result.isError === true) return undefined;
diff --git a/packages/eve/src/runtime/resolve-connection.test.ts b/packages/eve/src/runtime/resolve-connection.test.ts
index 712873543..39b3fd811 100644
--- a/packages/eve/src/runtime/resolve-connection.test.ts
+++ b/packages/eve/src/runtime/resolve-connection.test.ts
@@ -1,4 +1,4 @@
-import { describe, expect, it } from "vitest";
+import { describe, expect, it, vi } from "vitest";
import {
ROOT_COMPILED_AGENT_NODE_ID,
@@ -6,7 +6,10 @@ import {
} from "#compiler/manifest.js";
import type { CompiledModuleMap } from "#compiler/module-map.js";
import type { ConnectionToolCallDefinition } from "#public/definitions/connections/tool-call.js";
+import { defineOpenAPIConnection } from "#public/definitions/connections/openapi.js";
+import { toolResultFrom } from "#public/tools/result.js";
import { resolveConnectionDefinition } from "#runtime/resolve-connection.js";
+import type { RuntimeActionResult } from "#shared/action-types.js";
import type { ConnectionAuthResolver, HeadersDefinition } from "#shared/connection-types.js";
describe("resolveConnectionDefinition", () => {
@@ -52,3 +55,87 @@ describe("resolveConnectionDefinition", () => {
expect(resolved.toolCall).toBe(toolCall);
});
});
+
+describe("toolResultFrom identity for connections sharing a host (#202)", () => {
+ it("narrows each same-host OpenAPI connection through a copy of its definition", async () => {
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
+ const baseUrl = "https://example.atlassian.net";
+ const defineJira = () =>
+ defineOpenAPIConnection({ baseUrl, description: "Jira", spec: { openapi: "3.0.0" } });
+ const defineConfluence = () =>
+ defineOpenAPIConnection({ baseUrl, description: "Confluence", spec: { openapi: "3.0.0" } });
+
+ for (const [connectionName, loaded] of [
+ ["jira", defineJira()],
+ ["confluence", defineConfluence()],
+ ] as const) {
+ const sourceId = `connections/${connectionName}`;
+ await resolveConnectionDefinition(
+ {
+ connectionName,
+ description: loaded.description,
+ logicalPath: `${sourceId}.ts`,
+ protocol: "openapi",
+ sourceId,
+ sourceKind: "module",
+ url: baseUrl,
+ },
+ {
+ nodes: {
+ [ROOT_COMPILED_AGENT_NODE_ID]: { modules: { [sourceId]: { default: loaded } } },
+ },
+ },
+ undefined,
+ );
+ }
+
+ // A hook bundled separately imports its own instance of each connection module.
+ const jira = defineJira();
+ const confluence = defineConfluence();
+ const result = (toolName: string): RuntimeActionResult => ({
+ callId: "call_1",
+ kind: "tool-result",
+ output: {},
+ toolName,
+ });
+
+ expect(warn).not.toHaveBeenCalled();
+ expect(toolResultFrom(result("jira__getIssue"), jira)?.connectionToolName).toBe("getIssue");
+ expect(toolResultFrom(result("confluence__getPage"), confluence)?.connectionToolName).toBe(
+ "getPage",
+ );
+ expect(toolResultFrom(result("confluence__getPage"), jira)).toBeUndefined();
+ });
+
+ it("narrows an OpenAPI connection without baseUrl through a copy of its definition", async () => {
+ const define = () =>
+ defineOpenAPIConnection({
+ description: "Spec-only API",
+ spec: "https://spec-only.example.com/openapi.json",
+ });
+ const sourceId = "connections/spec-only";
+ await resolveConnectionDefinition(
+ {
+ connectionName: "spec_only",
+ description: "Spec-only API",
+ logicalPath: `${sourceId}.ts`,
+ protocol: "openapi",
+ sourceId,
+ sourceKind: "module",
+ url: "",
+ },
+ {
+ nodes: {
+ [ROOT_COMPILED_AGENT_NODE_ID]: { modules: { [sourceId]: { default: define() } } },
+ },
+ },
+ undefined,
+ );
+
+ const match = toolResultFrom(
+ { callId: "call_1", kind: "tool-result", output: {}, toolName: "spec_only__list" },
+ define(),
+ );
+ expect(match?.connectionToolName).toBe("list");
+ });
+});
diff --git a/packages/eve/src/runtime/resolve-connection.ts b/packages/eve/src/runtime/resolve-connection.ts
index 772b1fa8e..eea2b87a9 100644
--- a/packages/eve/src/runtime/resolve-connection.ts
+++ b/packages/eve/src/runtime/resolve-connection.ts
@@ -7,7 +7,10 @@ import {
normalizeOpenApiConnectionDefinition,
} from "#internal/authored-definition/connection.js";
import { readStampedConnectionProtocol } from "#public/definitions/connections/protocol.js";
-import { registerDefinitionSource } from "#internal/authored-definition/source-identity.js";
+import {
+ connectionDefinitionKey,
+ registerDefinitionSource,
+} from "#internal/authored-definition/source-identity.js";
import { toErrorMessage } from "#shared/errors.js";
import type {
ConnectionAuthResolver,
@@ -48,14 +51,10 @@ export async function resolveConnectionDefinition(
`Expected the connection export "${definition.exportName ?? "default"}" from "${definition.logicalPath}" to return an object.`,
);
- // Use the compiled `url` (the MCP endpoint or OpenAPI base URL) as
- // the fallback key so it matches the authoring-time key stamped by
- // the `define*` factory for both protocols. The live record only
- // carries `url` for MCP connections.
registerDefinitionSource(
resolvedRecord,
{ kind: "connection", logicalPath: definition.logicalPath, name: definition.connectionName },
- `connection:${definition.url}`,
+ connectionDefinitionKey(definition.url, definition.description),
);
const hasAuth = resolvedRecord.auth !== undefined;