[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3

Discovering & Calling Tools

🔗 Client Development10 min100 BASE XP

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

OperationMethodReturns
Discover toolsclient.listTools()Array of tool schemas
Execute toolclient.callTool(name, args)Content blocks (text/image)
List resourcesclient.listResources()Array of resource URIs
Read resourceclient.readResource(uri)Resource contents
List promptsclient.listPrompts()Array of prompt schemas
Get promptclient.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.
SYNAPSE VERIFICATION
QUERY 1 // 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
Watch: 139x Rust Speedup
Discovering & Calling Tools | Client Development — MCP Academy