Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
env:
# Pinned to a commit on stackone-ai-python's main, not the branch, so a Python change never
# silently changes what this job grades. Bump it deliberately.
PYTHON_SDK_REF: d76c26663c9141bf106a19d385252da9a8c7e75d
PYTHON_SDK_REF: 05398a3f1e119297beb7e514f92c17601a75583e
steps:
- name: Check conformance token is configured
env:
Expand All @@ -166,7 +166,7 @@ jobs:
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: StackOneHQ/sdk-conformance
ref: 4ead1c25bb443ef1fd1986d5f053b2d1475d0e90
ref: 6aba490ee49b298643e3a0bb9fbbaecf36c0edd7
token: ${{ secrets.CONFORMANCE_REPO_TOKEN }}
path: sdk-conformance
persist-credentials: false
Expand Down
9 changes: 4 additions & 5 deletions src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ export class Tools implements Iterable<BaseTool> {

constructor(tools: BaseTool[]) {
this.tools = [...tools];
warnOnDuplicateNames(this.tools);
Comment thread
glebedel marked this conversation as resolved.
Resolved
}

/**
Expand All @@ -705,7 +706,6 @@ export class Tools implements Iterable<BaseTool> {
* Claude Agent SDK refuses the second outright.
*/
#uniqueTools(): BaseTool[] {
warnOnDuplicateNames(this.tools);
const seen = new Set<string>();
return this.tools.filter((tool) => {
if (seen.has(tool.name)) {
Expand Down Expand Up @@ -951,11 +951,10 @@ export class Tools implements Iterable<BaseTool> {

/**
* Two accounts on one provider serve identically named tools. Every lookup and adapter keeps the
* first one listed — the lowest account id — and drops the rest, so warn that the others are
* unreachable by name: once when the tools are fetched, and again from each adapter that drops
* them.
* first one listed and drops the rest, so warn once, when the collection is built, that the others
* are unreachable by name.
*/
export function warnOnDuplicateNames(tools: readonly BaseTool[]): void {
function warnOnDuplicateNames(tools: readonly BaseTool[]): void {
const counts = new Map<string, number>();
for (const tool of tools) {
counts.set(tool.name, (counts.get(tool.name) ?? 0) + 1);
Expand Down
20 changes: 16 additions & 4 deletions src/toolsets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { server } from '../mocks/node';
import { FAILED_ACCOUNT_RETRY_MS } from './consts';
import { listMcpTools } from './mcp-client';
import type { McpToolDefinition as ListedTool } from './mcp-client';
import { StackOneMcpTool, StackOneTool } from './tool';
import { StackOneMcpTool, StackOneTool, Tools } from './tool';
import type { BaseTool } from './tool';
import { StackOneToolSet } from './toolsets';
import { StackOneAPIError } from './utils/error-stackone-api';
Expand Down Expand Up @@ -1099,9 +1099,21 @@ describe('duplicate tool names', () => {
expect(Object.keys(aiSdk)).toEqual(expected);
expect(aiSdk.hibob_list_employees?.description).toBe('on a');
await expect(tools.toClaudeAgentSdk()).resolves.toBeDefined();
// Once from fetchTools(), then once from each adapter call that dropped a duplicate.
expect(warnSpy).toHaveBeenCalledTimes(8);
expect(new Set(warnSpy.mock.calls.map(([message]: unknown[]) => message)).size).toBe(1);
// Once from fetchTools(); the adapters drop the duplicate without repeating it.
expect(warnSpy).toHaveBeenCalledTimes(1);
});

it('warns when collections fetched separately are merged into one', async () => {
fakeListing(() => [def('hibob_list_employees')]);
const toolset = newToolSet();
const a = await toolset.fetchTools({ accountIds: ['a'] });
const b = await toolset.fetchTools({ accountIds: ['b'] });
expect(warnSpy).not.toHaveBeenCalled();

const merged = new Tools([...a, ...b]);
merged.toOpenAI();

expect(warnSpy).toHaveBeenCalledTimes(1);
});

it('stays quiet when names are unique', async () => {
Expand Down
3 changes: 1 addition & 2 deletions src/toolsets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from './mcp-client';
import type { EndUserSource, McpToolDefinition } from './mcp-client';
import { cloneJson, toolParametersFromInputSchema } from './schema';
import { StackOneMcpTool, Tools, warnOnDuplicateNames } from './tool';
import { StackOneMcpTool, Tools } from './tool';
import type { StackOneTool } from './tool';
import type {
ActionResult,
Expand Down Expand Up @@ -1177,7 +1177,6 @@ export class StackOneToolSet {
isAskedFor(tool.name, mode === 'search_execute' ? { actions: options.actions } : options),
);

warnOnDuplicateNames(tools);
return new Tools(tools);
} catch (error) {
// StackOneAPIError carries the HTTP status. Re-wrapping it would throw that away, so a
Expand Down
2 changes: 1 addition & 1 deletion tests/vectors/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
"python": true,
"node": true
},
"notes": "Language-neutral wording: neither SDK's method or parameter names. Emitted once when a fetched collection holds a clashing name, and again by every adapter that keeps the first tool per name and drops the rest: OpenAI, LangChain, Pydantic AI, AI SDK and Claude Agent SDK. Listing order is ascending account id, so the first is the lowest account id's."
"notes": "Language-neutral wording: neither SDK's method or parameter names. Emitted once, when a tool collection holding a clashing name is built: by listing, or by the caller combining collections. The adapters that keep the first tool per name and drop the rest (OpenAI, LangChain, Pydantic AI, AI SDK and Claude Agent SDK) do not repeat it. Listing order is ascending account id, so the first is the lowest account id's."
},
{
"id": "mcp-timeout",
Expand Down
Loading