This directory contains examples demonstrating how to use the mcp-use library with various MCP servers.
- Node.js: Ensure you have Node.js 22+ installed
- Environment Variables: Create a
.envfile in the project root with your API keys:ANTHROPIC_API_KEY=your_anthropic_key OPENAI_API_KEY=your_openai_key E2B_API_KEY=your_e2b_key # Only for sandbox example
First, build the library:
npm run buildThen run any example using Node.js:
node dist/examples/example_name.jsOr use the npm scripts:
npm run example:airbnb
npm run example:browser
npm run example:chat
# ... etcSearch for accommodations using the Airbnb MCP server.
npm run example:airbnbControl a browser using Playwright MCP server.
npm run example:browserInteractive chat session with conversation memory.
npm run example:chatAccess and manipulate files using the filesystem MCP server.
# First, edit the example to set your directory path
npm run example:filesystemConnect to an MCP server via HTTP.
# First, start the Playwright server in another terminal:
npx @playwright/mcp@latest --port 8931
# Then run the example:
npm run example:httpTest various MCP functionalities.
npm run example:everythingUse multiple MCP servers in a single session.
# First, edit the example to set your directory path
npm run example:multiRun MCP servers in an E2B sandbox (requires E2B_API_KEY).
npm run example:sandboxOAuth flow example with Linear.
# First, register your app with Linear and update the client_id
npm run example:oauthControl Blender 3D through MCP.
# First, install and enable the Blender MCP addon
npm run example:blenderSome examples use JSON configuration files:
airbnb_mcp.json- Airbnb server configurationbrowser_mcp.json- Browser server configuration
Different examples require different API keys:
- ANTHROPIC_API_KEY: For examples using Claude (airbnb, multi_server, blender)
- OPENAI_API_KEY: For examples using GPT (browser, chat, filesystem, http, everything)
- E2B_API_KEY: Only for the sandbox example
- Module not found: Make sure to build the project first with
npm run build - API key errors: Check your
.envfile has the required keys - Server connection failed: Some examples require external servers to be running
- Permission errors: Some examples may need specific permissions (e.g., filesystem access)
To create a new example:
-
Import the necessary modules:
import { ChatOpenAI } from '@langchain/openai' import { MCPAgent, MCPClient } from '../index.js'
-
Configure your MCP server:
const config = { mcpServers: { yourServer: { command: 'npx', args: ['your-mcp-server'] } } }
-
Create client, LLM, and agent:
const client = MCPClient.fromDict(config) const llm = new ChatOpenAI({ model: 'gpt-4o' }) const agent = new MCPAgent({ llm, client, maxSteps: 30 })
-
Run your queries:
const result = await agent.run('Your prompt here', { maxSteps: 30 })
Feel free to add more examples! Make sure to:
- Follow the existing code style
- Add appropriate documentation
- Update this README with your example
- Add a corresponding npm script in package.json