Testing with Claude
Testing Your MCP Server with Claude
Now that you've built your first MCP server, let's learn how to test it properly. You can test with Claude Desktop, the MCP Inspector tool, or programmatically.
typescript
// Method 1: Claude Desktop (easiest)
// Add to claude_desktop_config.json and restart Claude
// Then just chat with Claude and ask it to use your tools
// Method 2: MCP Inspector (for debugging)
// npx @modelcontextprotocol/inspector npx tsx src/index.ts
// Opens a web UI where you can test tools interactively
// Method 3: Programmatic testing
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const client = new Client({ name: "test-client", version: "1.0.0" });
const transport = new StdioClientTransport({
command: "npx",
args: ["tsx", "src/index.ts"],
});
await client.connect(transport);
const result = await client.callTool("add", { a: 5, b: 3 });
console.log(result); // { content: [{ type: "text", text: "8" }] }Tip:The MCP Inspector is your best friend during development. Run it with: npx @modelcontextprotocol/inspector npx tsx src/index.ts
PreviewTypeScriptRead Only
Copy this code and run it locally with
npx tsx server.ts