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

The Client SDK

🔗 Client Development12 min100 BASE XP

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 CaseWhy Custom ClientExample
Custom AI appYour own chatbot or agent needs MCP toolsInternal support bot connecting to your CRM MCP server
Automation pipelineNon-interactive tool executionCI/CD pipeline that uses MCP tools for deployment
TestingProgrammatic server validationIntegration tests that verify server behavior
Gateway/ProxyAggregate multiple serversMCP 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

  1. Client → Server: initialize — sends client name, version, capabilities
  2. Server → Client: Response with server name, version, capabilities
  3. 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.
SYNAPSE VERIFICATION
QUERY 1 // 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
Watch: 139x Rust Speedup
The Client SDK | Client Development — MCP Academy