The Client SDK — Client Development
← 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 (@modelcontextprotocol/client in TypeScript SDK v2, succeeding v1's @modelcontextprotocol/sdk/client).
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
// TypeScript SDK v2 (@modelcontextprotocol/client)
// v1 legacy path: "@modelcontextprotocol/sdk/client/index.js" & "stdio.js"
import { Client, StdioClientTransport } from "@modelcontextprotocol/client";
// 1. Create client
const client = new Client({
name: "my-app",
version: "1.0.0"
}, {
capabilities: {
// Declare client capabilities (e.g., elicitation; roots/sampling are deprecated in 2026-07-28)
elicitation: { form: {}, url: {} }
}
});
// 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 (discovers server capabilities automatically)
await client.connect(transport);
console.log("Connected! Server capabilities:", client.getServerCapabilities());
Capability Discovery & Protocol Negotiation
When you call client.connect(transport), the Client SDK negotiates protocol versions and capabilities automatically:
- Stateless
2026-07-28(Current): Callsserver/discoverto query supported protocol versions, capabilities, and server identity, then sendsprotocolVersionandclientCapabilitiesinline inside_metaon each request - no stateful handshake required. - Legacy
2024-11-05–2025-11-25Fallback: Performs the 3-step stateful handshake (initialize→ server capabilities response →notifications/initialized).
💡 Key Insight: Capability discovery ensures both sides know what the other supports before invoking methods. If the server doesn't declare
tools in its capabilities, your client should not attempt to list or call tools.⌨ HANDS-ON LABVerify Client SDK Module Loading
⭐ +125 XPBootstrap an MCP client using @modelcontextprotocol/client (v2) or @modelcontextprotocol/sdk/client in Node.js.
1Verify the MCP Client SDK module loads.
OBJECTIVE 1 / 1 — type "hint" if stuck
🧪 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