Skip to main content

MCP Client

mcp-use provides a complete MCP client implementation for TypeScript that enables your applications to connect to and interact with any MCP server. Whether you’re building AI agents, automation tools, or integrations, the MCPClient gives you full access to MCP protocol features with a clean, type-safe API.

Key Features

  • Multi-server support: Connect to multiple MCP servers simultaneously
  • Multiple connection types: STDIO, HTTP, and SSE transports
  • Full MCP protocol: Complete support for tools, resources, prompts, and notifications
  • Type-safe: Full TypeScript support with automatic type inference
  • Middleware support: Add logging, metrics, and custom middleware
  • Sandbox mode: Secure execution environment for untrusted code

Installation

Install the mcp-use package:
npm install mcp-use

Quick Start

Here’s a basic example of connecting to an MCP server and calling a tool: Edit mcp-client-getting-started
import { MCPClient } from 'mcp-use'

// Create client and connect
const client = new MCPClient({
  mcpServers: {
    'my-server': {
      command: 'npx',
      args: ['-y', '@modelcontextprotocol/server-everything']
    }
  }
})
await client.createAllSessions()

// Get a session for a specific server
const session = client.getSession('my-server')

// List available tools
const tools = await session.listTools()
console.log('Available tools:', tools)

// Call a tool
const result = await session.callTool('tool_name', { 
  param: 'value' 
})
console.log('Result:', result)

// Cleanup
await client.closeAllSessions()

Next Steps