Skip to main content

The Client SDK — Client Development

← Back to Dashboard
1. The Client SDK2. Discovering & Calling Tools3. Remote Client Connections

The Client SDK

📚 Client Development⏱ 12 min⭐ 100 XP⌨ Hands-on lab

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 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

// 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): Calls server/discover to query supported protocol versions, capabilities, and server identity, then sends protocolVersion and clientCapabilities inline inside _meta on each request - no stateful handshake required.
  • Legacy 2024-11-05 – 2025-11-25 Fallback: 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 XP

Bootstrap an MCP client using @modelcontextprotocol/client (v2) or @modelcontextprotocol/sdk/client in Node.js.

1Verify the MCP Client SDK module loads.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
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