← Back to Dashboard
1. The Client SDK2. Discovering & Calling Tools3. Remote Client Connections
Discovering & Calling Tools
Interacting with Server Capabilities
Once connected, your client can discover and use everything the server offers.
Listing Available Tools
// Discover all tools the server offers
const { tools } = await client.listTools();
console.log("Available tools:");
for (const tool of tools) {
console.log(` - ${tool.name}: ${tool.description}`);
console.log(` Schema: ${JSON.stringify(tool.inputSchema)}`);
}
Calling a Tool
// Execute a tool with arguments
const result = await client.callTool("search_notes", {
query: "meeting agenda",
maxResults: 3
});
// Handle the response
for (const block of result.content) {
if (block.type === "text") {
console.log("Result:", block.text);
} else if (block.type === "image") {
console.log("Image:", block.mimeType, block.data.length, "bytes");
}
}
// Check for errors
if (result.isError) {
console.error("Tool returned an error:", result.content[0].text);
}
Reading Resources
// List all available resources
const { resources } = await client.listResources();
// Read a specific resource
const { contents } = await client.readResource("notes://note/meeting-notes.md");
console.log("Note content:", contents[0].text);
// List resource templates for dynamic access
const { resourceTemplates } = await client.listResourceTemplates();
Using Prompts
// List available prompts
const { prompts } = await client.listPrompts();
// Get a prompt with arguments
const { messages } = await client.getPrompt("summarize_topic", {
topic: "quarterly goals"
});
// Feed the messages to your LLM
const response = await llm.chat(messages);
Complete Client Pattern
| Operation | Method | Returns |
|---|---|---|
| Discover tools | client.listTools() | Array of tool schemas |
| Execute tool | client.callTool(name, args) | Content blocks (text/image) |
| List resources | client.listResources() | Array of resource URIs |
| Read resource | client.readResource(uri) | Resource contents |
| List prompts | client.listPrompts() | Array of prompt schemas |
| Get prompt | client.getPrompt(name, args) | Message array for LLM |
🎯 Pro Tip: Always check
result.isError after calling a tool. Servers return errors as content blocks with isError: true rather than throwing exceptions.🧪 Knowledge Check
Press 1-4 to select1 of 3
How do you discover what tools an MCP server offers?
Read the source code
Call client.listTools() which returns all tool names, descriptions, and schemas
Check package.json
Ask the LLM to guess