Skip to content

Commit d6b5432

Browse files
authored
Refactor SDK method names (#6)
* (client) getToolSchemas -> getTools * (server) listTools -> getTools * Remove console messages
1 parent 9bc109a commit d6b5432

File tree

7 files changed

+47
-57
lines changed

7 files changed

+47
-57
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ console.log(servers);
4747
// Example: ['time', 'fetch', 'git']
4848

4949
// List tool definitions for a specific server
50-
const tools = await client.servers.time.listTools();
50+
const tools = await client.servers.time.getTools();
5151
console.log(tools);
5252

5353
// Dynamically call a tool via the .tools namespace
@@ -79,7 +79,7 @@ const client = new McpdClient({
7979
const servers: string[] = await client.listServers();
8080

8181
// Get tools with proper typing
82-
const tools: Tool[] = await client.servers.time.listTools();
82+
const tools: Tool[] = await client.servers.time.getTools();
8383

8484
// Dynamic tool invocation with error handling via .tools namespace
8585
try {
@@ -122,7 +122,7 @@ const servers = await client.listServers();
122122
// Returns: ['time', 'fetch', 'git']
123123
```
124124

125-
#### `client.getToolSchemas(options?)`
125+
#### `client.getTools(options?)`
126126

127127
Returns tool schemas from all (or specific) servers with names transformed to `serverName__toolName` format.
128128

@@ -136,24 +136,24 @@ This is useful for:
136136

137137
```typescript
138138
// Get all tools from all servers
139-
const allTools = await client.getToolSchemas();
139+
const allTools = await client.getTools();
140140
// Returns: [
141141
// { name: "time__get_current_time", description: "...", inputSchema: {...} },
142142
// { name: "fetch__fetch_url", description: "...", inputSchema: {...} },
143143
// { name: "git__commit", description: "...", inputSchema: {...} }
144144
// ]
145145

146146
// Get tools from specific servers only
147-
const someTools = await client.getToolSchemas({ servers: ["time", "fetch"] });
147+
const someTools = await client.getTools({ servers: ["time", "fetch"] });
148148
```
149149

150-
#### `client.servers.<server>.listTools()`
150+
#### `client.servers.<server>.getTools()`
151151

152152
Returns tool schemas for a specific server.
153153

154154
```typescript
155155
// Get tools for a specific server
156-
const timeTools = await client.servers.time.listTools();
156+
const timeTools = await client.servers.time.getTools();
157157
// Returns: [{ name: 'get_current_time', description: '...', inputSchema: {...} }]
158158
```
159159

@@ -172,21 +172,21 @@ const result = await client.servers.weather.tools.get_forecast({
172172
const time = await client.servers.time.tools.get_current_time();
173173
```
174174

175-
#### `client.servers.<server>.listTools()`
175+
#### `client.servers.<server>.getTools()`
176176

177-
List all tools available on a specific server.
177+
Get all tools available on a specific server.
178178

179179
```typescript
180180
// List tools for a server using property access
181-
const tools = await client.servers.time.listTools();
181+
const tools = await client.servers.time.getTools();
182182
for (const tool of tools) {
183183
console.log(`${tool.name}: ${tool.description}`);
184184
}
185185

186186
// Useful in loops with dynamic server names
187187
const servers = await client.listServers();
188188
for (const serverName of servers) {
189-
const tools = await client.servers[serverName].listTools();
189+
const tools = await client.servers[serverName].getTools();
190190
console.log(`${serverName}: ${tools.length} tools`);
191191
}
192192
```

examples/basic/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function main() {
3535
if (servers.includes('time')) {
3636
// Get tools for the time server
3737
console.log('Time server tools:');
38-
const tools = await client.servers.time.listTools();
38+
const tools = await client.servers.time.getTools();
3939
for (const tool of tools) {
4040
console.log(` - ${tool.name}: ${tool.description || 'No description'}`);
4141
}

src/client.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,20 @@ export class McpdClient {
295295
* @example
296296
* ```typescript
297297
* // Get all tools from all servers
298-
* const allTools = await client.getToolSchemas();
298+
* const allTools = await client.getTools();
299299
* // Returns: [
300300
* // { name: "time__get_current_time", description: "...", ... },
301301
* // { name: "fetch__fetch_url", description: "...", ... }
302302
* // ]
303303
*
304304
* // Get tools from specific servers only
305-
* const someTools = await client.getToolSchemas({ servers: ['time', 'fetch'] });
305+
* const someTools = await client.getTools({ servers: ['time', 'fetch'] });
306306
*
307307
* // Original tool name "get_current_time" becomes "time__get_current_time"
308308
* // This prevents clashes if multiple servers have tools with the same name
309309
* ```
310310
*/
311-
async getToolSchemas(options?: { servers?: string[] }): Promise<Tool[]> {
311+
async getTools(options?: { servers?: string[] }): Promise<Tool[]> {
312312
const { servers } = options || {};
313313

314314
// Get healthy servers (fetches list if not provided, then filters by health).
@@ -334,10 +334,8 @@ export class McpdClient {
334334
name: `${serverName}__${tool.name}`,
335335
});
336336
}
337-
} else {
338-
// If we can't get tools for a server, skip it with a warning
339-
console.warn(`Failed to get tools for server:`, result.reason);
340337
}
338+
// Silently skip failed servers - they're already filtered by health checks
341339
}
342340

343341
return allTools;
@@ -405,10 +403,9 @@ export class McpdClient {
405403
...prompt,
406404
name: `${serverName}__${prompt.name}`,
407405
}));
408-
} else {
409-
console.warn(`Failed to get prompts for server:`, result.reason);
410-
return []; // Return an empty array for rejected promises
411406
}
407+
// Silently skip failed servers - they're already filtered by health checks
408+
return [];
412409
});
413410

414411
return allPrompts;
@@ -550,10 +547,9 @@ export class McpdClient {
550547

551548
return namespacedResource;
552549
});
553-
} else {
554-
console.warn(`Failed to get resources for server:`, result.reason);
555-
return [];
556550
}
551+
// Silently skip failed servers - they're already filtered by health checks
552+
return [];
557553
});
558554

559555
return allResources;
@@ -624,13 +620,9 @@ export class McpdClient {
624620
_serverName: serverName,
625621
_templateName: template.name,
626622
}));
627-
} else {
628-
console.warn(
629-
`Failed to get resource templates for server:`,
630-
result.reason,
631-
);
632-
return [];
633623
}
624+
// Silently skip failed servers - they're already filtered by health checks
625+
return [];
634626
});
635627

636628
return allTemplates;
@@ -1165,10 +1157,8 @@ export class McpdClient {
11651157
);
11661158
agentTools.push(func);
11671159
}
1168-
} else {
1169-
// If we can't get tools for a server, skip it with a warning
1170-
console.warn(`Failed to get tools for server:`, result.reason);
11711160
}
1161+
// Silently skip failed servers - they're already filtered by health checks
11721162
}
11731163

11741164
return agentTools;

src/dynamicCaller.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class ServersNamespace {
130130
* const timeServer = client.servers.time; // Returns Server(...)
131131
*
132132
* // List available tools
133-
* const tools = await timeServer.listTools();
133+
* const tools = await timeServer.getTools();
134134
*
135135
* // Call tools through the .tools namespace:
136136
* await timeServer.tools.get_current_time({ timezone: "UTC" })
@@ -196,21 +196,21 @@ export class Server {
196196
}
197197

198198
/**
199-
* List all tools available on this server.
199+
* Get all tools available on this server.
200200
*
201201
* @returns Array of tool schemas
202202
* @throws {ServerNotFoundError} If the server doesn't exist
203203
* @throws {ServerUnhealthyError} If the server is unhealthy
204204
*
205205
* @example
206206
* ```typescript
207-
* const tools = await client.servers.time.listTools();
207+
* const tools = await client.servers.time.getTools();
208208
* for (const tool of tools) {
209209
* console.log(`${tool.name}: ${tool.description}`);
210210
* }
211211
* ```
212212
*/
213-
async listTools(): Promise<Tool[]> {
213+
async getTools(): Promise<Tool[]> {
214214
return this.#getTools(this.#serverName);
215215
}
216216

@@ -277,7 +277,7 @@ export class Server {
277277
if (!tool) {
278278
throw new ToolNotFoundError(
279279
`Tool '${toolName}' not found on server '${this.#serverName}'. ` +
280-
`Use client.servers.${this.#serverName}.listTools() to see available tools.`,
280+
`Use client.servers.${this.#serverName}.getTools() to see available tools.`,
281281
this.#serverName,
282282
toolName,
283283
);
@@ -542,7 +542,7 @@ export class ToolsNamespace {
542542
if (!tool) {
543543
throw new ToolNotFoundError(
544544
`Tool '${toolName}' not found on server '${target.#serverName}'. ` +
545-
`Use client.servers.${target.#serverName}.listTools() to see available tools.`,
545+
`Use client.servers.${target.#serverName}.getTools() to see available tools.`,
546546
target.#serverName,
547547
toolName,
548548
);

tests/unit/apiSurface.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("API Surface - Complete Test Coverage", () => {
7272
expect(isHealthy).toBe(true);
7373
});
7474

75-
it("client.servers.foo.listTools()", async () => {
75+
it("client.servers.foo.getTools()", async () => {
7676
mockFetch.mockResolvedValueOnce({
7777
ok: true,
7878
json: async () => ({ status: "ok" }),
@@ -82,11 +82,11 @@ describe("API Surface - Complete Test Coverage", () => {
8282
json: async () => ({ tools: [{ name: "tool1" }] }),
8383
});
8484

85-
const tools = await client.servers.time!.listTools();
85+
const tools = await client.servers.time!.getTools();
8686
expect(tools).toHaveLength(1);
8787
});
8888

89-
it('client.servers["foo"].listTools()', async () => {
89+
it('client.servers["foo"].getTools()', async () => {
9090
const serverName = "time";
9191
mockFetch.mockResolvedValueOnce({
9292
ok: true,
@@ -97,7 +97,7 @@ describe("API Surface - Complete Test Coverage", () => {
9797
json: async () => ({ tools: [{ name: "tool1" }] }),
9898
});
9999

100-
const tools = await client.servers[serverName]!.listTools();
100+
const tools = await client.servers[serverName]!.getTools();
101101
expect(tools).toHaveLength(1);
102102
});
103103

@@ -243,7 +243,7 @@ describe("API Surface - Complete Test Coverage", () => {
243243
expect(result).toEqual({ result: "12:00" });
244244
});
245245

246-
it("client.getToolSchemas() - no options", async () => {
246+
it("client.getTools() - no options", async () => {
247247
mockFetch.mockResolvedValueOnce({
248248
ok: true,
249249
json: async () => ["time"],
@@ -261,11 +261,11 @@ describe("API Surface - Complete Test Coverage", () => {
261261
}),
262262
});
263263

264-
const schemas = await client.getToolSchemas();
264+
const schemas = await client.getTools();
265265
expect(schemas[0]?.name).toBe("time__get_time");
266266
});
267267

268-
it("client.getToolSchemas(options) - with servers filter", async () => {
268+
it("client.getTools(options) - with servers filter", async () => {
269269
mockFetch.mockResolvedValueOnce({
270270
ok: true,
271271
json: async () => ({
@@ -279,7 +279,7 @@ describe("API Surface - Complete Test Coverage", () => {
279279
}),
280280
});
281281

282-
const schemas = await client.getToolSchemas({ servers: ["time"] });
282+
const schemas = await client.getTools({ servers: ["time"] });
283283
expect(schemas[0]?.name).toBe("time__get_time");
284284
});
285285

tests/unit/client.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe("McpdClient", () => {
122122
});
123123
});
124124

125-
describe("getToolSchemas()", () => {
125+
describe("getTools()", () => {
126126
it("should return all tools from all servers with transformed names", async () => {
127127
const mockTools = {
128128
time: [
@@ -186,7 +186,7 @@ describe("McpdClient", () => {
186186
json: async () => ({ tools: mockTools.math }),
187187
});
188188

189-
const tools = await client.getToolSchemas();
189+
const tools = await client.getTools();
190190

191191
expect(tools).toHaveLength(3);
192192
expect(tools[0]?.name).toBe("time__get_current_time");
@@ -227,7 +227,7 @@ describe("McpdClient", () => {
227227
json: async () => ({ tools: mockTools.time }),
228228
});
229229

230-
const tools = await client.getToolSchemas({ servers: ["time"] });
230+
const tools = await client.getTools({ servers: ["time"] });
231231

232232
expect(tools).toHaveLength(1);
233233
expect(tools[0]?.name).toBe("time__get_current_time");
@@ -248,7 +248,7 @@ describe("McpdClient", () => {
248248
}),
249249
});
250250

251-
const tools = await client.getToolSchemas();
251+
const tools = await client.getTools();
252252

253253
expect(tools).toHaveLength(0);
254254
});
@@ -298,7 +298,7 @@ describe("McpdClient", () => {
298298
json: async () => ({ tools: mockTools.time }),
299299
});
300300

301-
const tools = await client.getToolSchemas();
301+
const tools = await client.getTools();
302302

303303
// Should only get tools from healthy server
304304
expect(tools).toHaveLength(1);

tests/unit/dynamicCaller.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ToolNotFoundError } from "../../src/errors";
77
*
88
* These tests ensure that all documented API patterns work correctly:
99
* - client.servers[serverName]! (dynamic server access)
10-
* - client.servers.foo.listTools() (list tools)
10+
* - client.servers.foo.getTools() (list tools)
1111
* - client.servers.foo!.tools.bar!(args) (static tool call)
1212
* - client.servers.foo.callTool(name, args) (dynamic tool call)
1313
* - client.servers.foo.hasTool(name) (check tool existence)
@@ -61,14 +61,14 @@ describe("Dynamic Calling Patterns", () => {
6161
}),
6262
});
6363

64-
const tools = await client.servers[serverName]!.listTools();
64+
const tools = await client.servers[serverName]!.getTools();
6565

6666
expect(tools).toHaveLength(1);
6767
expect(tools[0]?.name).toBe("get_current_time");
6868
});
6969
});
7070

71-
describe("Pattern: client.servers.foo.listTools()", () => {
71+
describe("Pattern: client.servers.foo.getTools()", () => {
7272
it("should list tools with static property access", async () => {
7373
// Health check.
7474
mockFetch.mockResolvedValueOnce({
@@ -92,7 +92,7 @@ describe("Dynamic Calling Patterns", () => {
9292
}),
9393
});
9494

95-
const tools = await client.servers.time!.listTools();
95+
const tools = await client.servers.time!.getTools();
9696

9797
expect(tools).toHaveLength(2);
9898
expect(tools[0]?.name).toBe("tool1");
@@ -473,7 +473,7 @@ describe("Dynamic Calling Patterns", () => {
473473
});
474474

475475
// Mix dynamic server with static method.
476-
const tools = await client.servers[serverName]!.listTools();
476+
const tools = await client.servers[serverName]!.getTools();
477477

478478
expect(tools).toHaveLength(1);
479479
expect(tools[0]?.name).toBe("tool1");

0 commit comments

Comments
 (0)