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 anMCPToolkit:
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
- Configuration — Timeouts, headers, tool filtering
- Resources — Read data from MCP servers
- Prompts — Use prompt templates