Skip to content

Commit e444f47

Browse files
fix: pass full server response in explore API client tool
The client tool was cherry-picking fields and dropping documentation, inputSchema, and outputSchema from the server response. Now spreads the full result, consistent with the Vercel AI SDK tool. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e788c6e commit e444f47

2 files changed

Lines changed: 30 additions & 37 deletions

File tree

__tests__/unit/explore-api.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,33 @@ describe('Explore API Tool', () => {
8282
expect(parsed[0].group).toBe('github');
8383
});
8484

85+
test('should include documentation from the server response', async () => {
86+
mockClient.exploreAPI.mockResolvedValue({
87+
type: 'directory',
88+
path: '/custom/myapi',
89+
items: [
90+
{ name: 'listItems', type: 'function' },
91+
{ name: 'createItem', type: 'function' },
92+
],
93+
documentation: {
94+
description: 'API for managing items',
95+
examples: ['listItems()', 'createItem({ name: "test" })'],
96+
tips: ['Use listItems before creating duplicates'],
97+
},
98+
});
99+
100+
const tool = createExploreApiTool(mockClient as any);
101+
const result = await tool.func({ paths: '/custom/myapi' });
102+
const parsed = JSON.parse(result);
103+
104+
expect(parsed).toHaveLength(1);
105+
expect(parsed[0].success).toBe(true);
106+
expect(parsed[0].documentation).toBeDefined();
107+
expect(parsed[0].documentation.description).toBe('API for managing items');
108+
expect(parsed[0].documentation.examples).toHaveLength(2);
109+
expect(parsed[0].documentation.tips).toEqual(['Use listItems before creating duplicates']);
110+
});
111+
85112
test('should handle errors gracefully', async () => {
86113
mockClient.exploreAPI.mockRejectedValue(new Error('Path not found'));
87114

packages/client/src/tools/explore-api.ts

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@ export const exploreApiInputSchema = z.object({
1313

1414
type ExploreApiInput = z.infer<typeof exploreApiInputSchema>;
1515

16-
interface ExploreResult {
17-
success: boolean;
18-
path: string;
19-
type?: 'directory' | 'function';
20-
items?: Array<{ name: string; type: string }>;
21-
name?: string;
22-
description?: string;
23-
definition?: unknown;
24-
group?: string;
25-
error?: string;
26-
}
27-
2816
function normalizePaths(paths: string | string[]): string[] {
2917
return Array.isArray(paths) ? paths : [paths];
3018
}
@@ -39,36 +27,14 @@ export function createExploreApiTool(client: AgentToolProtocolClient): Tool<Expl
3927
func: async (input: ExploreApiInput) => {
4028
const pathsToExplore = normalizePaths(input.paths);
4129

42-
const results: ExploreResult[] = await Promise.all(
30+
const results = await Promise.all(
4331
pathsToExplore.map(async (path) => {
4432
try {
4533
const result = await client.exploreAPI(path);
46-
47-
if (result.type === 'directory') {
48-
return {
49-
success: true,
50-
type: 'directory' as const,
51-
path: result.path,
52-
items: result.items,
53-
};
54-
} else {
55-
return {
56-
success: true,
57-
type: 'function' as const,
58-
name: result.name,
59-
description: result.description,
60-
definition: result.definition,
61-
group: result.group,
62-
path: result.path,
63-
};
64-
}
34+
return { success: true, ...result };
6535
} catch (error: unknown) {
6636
const message = error instanceof Error ? error.message : String(error);
67-
return {
68-
success: false,
69-
path,
70-
error: message,
71-
};
37+
return { success: false, path, error: message };
7238
}
7339
})
7440
);

0 commit comments

Comments
 (0)