|
| 1 | +<h1 align="center">Unified MCP Client Library</h1> |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/@modelcontextprotocol/mcp-client) |
| 4 | +[](https://www.npmjs.com/package/@modelcontextprotocol/mcp-client) |
| 5 | +[](https://github.com/zandko/mcp-use/blob/main/LICENSE) |
| 6 | +[](https://eslint.org) |
| 7 | +[](https://github.com/zandko/mcp-use/stargazers) |
| 8 | + |
| 9 | +🌐 **MCP Client** is the open-source way to connect **any LLM to any MCP server** in TypeScript/Node.js, letting you build custom agents with tool access without closed-source dependencies. |
| 10 | + |
| 11 | +💡 Let developers easily connect any LLM via LangChain.js to tools like web browsing, file operations, 3D modeling, and more. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## ✨ Key Features |
| 16 | + |
| 17 | +| Feature | Description | |
| 18 | +| ------------------------------- | -------------------------------------------------------------------------- | |
| 19 | +| 🔄 **Ease of use** | Create an MCP-capable agent in just a few lines of TypeScript. | |
| 20 | +| 🤖 **LLM Flexibility** | Works with any LangChain.js-supported LLM that supports tool calling. | |
| 21 | +| 🌐 **HTTP Support** | Direct SSE/HTTP connection to MCP servers. | |
| 22 | +| ⚙️ **Dynamic Server Selection** | Agents select the right MCP server from a pool on the fly. | |
| 23 | +| 🧩 **Multi-Server Support** | Use multiple MCP servers in one agent. | |
| 24 | +| 🛡️ **Tool Restrictions** | Restrict unsafe tools like filesystem or network. | |
| 25 | +| 🔧 **Custom Agents** | Build your own agents with LangChain.js adapter or implement new adapters. | |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## 🚀 Quick Start |
| 30 | + |
| 31 | +### Installation |
| 32 | + |
| 33 | +```bash |
| 34 | +# Install from npm |
| 35 | +npm install mcp-use |
| 36 | +# LangChain.js and your LLM provider (e.g., OpenAI) |
| 37 | +npm install langchain @langchain/openai dotenv |
| 38 | +``` |
| 39 | + |
| 40 | +Create a `.env`: |
| 41 | + |
| 42 | +```ini |
| 43 | +OPENAI_API_KEY=your_api_key |
| 44 | +``` |
| 45 | + |
| 46 | +### Basic Usage |
| 47 | + |
| 48 | +```ts |
| 49 | +import { ChatOpenAI } from '@langchain/openai' |
| 50 | +import { MCPAgent, MCPClient } from 'mcp-use' |
| 51 | +import 'dotenv/config' |
| 52 | + |
| 53 | +async function main() { |
| 54 | + // 1. Configure MCP servers |
| 55 | + const config = { |
| 56 | + mcpServers: { |
| 57 | + playwright: { command: 'npx', args: ['@playwright/mcp@latest'] } |
| 58 | + } |
| 59 | + } |
| 60 | + const client = MCPClient.fromDict(config) |
| 61 | + |
| 62 | + // 2. Create LLM |
| 63 | + const llm = new ChatOpenAI({ modelName: 'gpt-4o' }) |
| 64 | + |
| 65 | + // 3. Instantiate agent |
| 66 | + const agent = new MCPAgent({ llm, client, maxSteps: 20 }) |
| 67 | + |
| 68 | + // 4. Run query |
| 69 | + const result = await agent.run('Find the best restaurant in Tokyo using Google Search') |
| 70 | + console.log('Result:', result) |
| 71 | +} |
| 72 | + |
| 73 | +main().catch(console.error) |
| 74 | +``` |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## 📂 Configuration File |
| 79 | + |
| 80 | +You can store servers in a JSON file: |
| 81 | + |
| 82 | +```json |
| 83 | +{ |
| 84 | + "mcpServers": { |
| 85 | + "playwright": { |
| 86 | + "command": "npx", |
| 87 | + "args": ["@playwright/mcp@latest"] |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +Load it: |
| 94 | + |
| 95 | +```ts |
| 96 | +import { MCPClient } from 'mcp-use' |
| 97 | +const client = MCPClient.fromConfigFile('./mcp-config.json') |
| 98 | +``` |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## 🔄 Multi-Server Example |
| 103 | + |
| 104 | +```ts |
| 105 | +const config = { |
| 106 | + mcpServers: { |
| 107 | + airbnb: { command: 'npx', args: ['@openbnb/mcp-server-airbnb'] }, |
| 108 | + playwright: { command: 'npx', args: ['@playwright/mcp@latest'] } |
| 109 | + } |
| 110 | +} |
| 111 | +const client = MCPClient.fromDict(config) |
| 112 | +const agent = new MCPAgent({ llm, client, useServerManager: true }) |
| 113 | +await agent.run('Search Airbnb in Barcelona, then Google restaurants nearby') |
| 114 | +``` |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## 🔒 Tool Access Control |
| 119 | + |
| 120 | +```ts |
| 121 | +const agent = new MCPAgent({ |
| 122 | + llm, |
| 123 | + client, |
| 124 | + disallowedTools: ['file_system', 'network'] |
| 125 | +}) |
| 126 | +``` |
| 127 | + |
| 128 | +## 📜 License |
| 129 | + |
| 130 | +MIT © [Zane](https://github.com/zandko) |
0 commit comments