Skip to main content
This guide walks you through connecting to an MCP server, discovering its tools, and using them in an agent.

Prerequisites

  • An MCP server to connect to (we’ll use the filesystem server from npm)
  • Node.js installed (for npx)

Step 1: Define the Server

Create a configuration for the MCP server:

Step 2: Create the Toolkit

Wrap the configuration in an MCPToolkit:

Step 3: Connect and Use

Use the toolkit as a context manager to manage the server connection lifecycle:

Complete Example

Using SSE or HTTP Transports

For remote servers, use SSE or HTTP:

Sync Usage

If you’re not in an async context, use the sync wrappers:

Next Steps