← Back to Dashboard
1. The Client SDK2. Discovering & Calling Tools3. Remote Client Connections
The Client SDK
Building Your Own MCP Client
Most developers interact with MCP through Host applications like Claude Desktop. But what if you want to build your own application that connects to MCP servers? You need the Client SDK.
When to Build a Custom Client
| Use Case | Why Custom Client | Example |
|---|---|---|
| Custom AI app | Your own chatbot or agent needs MCP tools | Internal support bot connecting to your CRM MCP server |
| Automation pipeline | Non-interactive tool execution | CI/CD pipeline that uses MCP tools for deployment |
| Testing | Programmatic server validation | Integration tests that verify server behavior |
| Gateway/Proxy | Aggregate multiple servers | MCP Gateway that routes requests across servers |
Client Connection Setup
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
// 1. Create client
const client = new Client({
name: "my-app",
version: "1.0.0"
}, {
capabilities: {
// Declare what your client supports
roots: { listChanged: true },
sampling: {}
}
});
// 2. Create transport (launches server as child process)
const transport = new StdioClientTransport({
command: "node",
args: ["./path/to/server/dist/index.js"],
env: { NOTES_DIR: "./notes" }
});
// 3. Connect (performs initialization handshake)
await client.connect(transport);
console.log("Connected! Server capabilities:", client.getServerCapabilities());
The Initialization Handshake
- Client → Server:
initialize- sends client name, version, capabilities - Server → Client: Response with server name, version, capabilities
- Client → Server:
initialized- confirms handshake complete
💡 Key Insight: The handshake is where both sides learn what the other supports. If the server doesn't declare
tools in its capabilities, your client should not attempt to list or call tools.🧪 Knowledge Check
Press 1-4 to select1 of 3
When should you build a custom MCP client instead of using Claude Desktop?
Always
When you need programmatic tool execution in automation, custom apps, or testing pipelines
Never - Claude Desktop handles everything
Only for debugging