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.
| 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 |
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());
initialize — sends client name, version, capabilitiesinitialized — confirms handshake completetools in its capabilities, your client should not attempt to list or call tools.