mcp-use 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +66 -5
  2. package/dist/examples/add_server_tool.d.ts +8 -0
  3. package/dist/examples/add_server_tool.d.ts.map +1 -0
  4. package/dist/examples/add_server_tool.js +65 -0
  5. package/dist/examples/airbnb_use.d.ts +10 -0
  6. package/dist/examples/airbnb_use.d.ts.map +1 -0
  7. package/dist/examples/airbnb_use.js +43 -0
  8. package/dist/examples/blender_use.d.ts +15 -0
  9. package/dist/examples/blender_use.d.ts.map +1 -0
  10. package/dist/examples/blender_use.js +39 -0
  11. package/dist/examples/browser_use.d.ts +10 -0
  12. package/dist/examples/browser_use.d.ts.map +1 -0
  13. package/dist/examples/browser_use.js +46 -0
  14. package/dist/examples/chat_example.d.ts +10 -0
  15. package/dist/examples/chat_example.d.ts.map +1 -0
  16. package/dist/examples/chat_example.js +86 -0
  17. package/dist/examples/filesystem_use.d.ts +11 -0
  18. package/dist/examples/filesystem_use.d.ts.map +1 -0
  19. package/dist/examples/filesystem_use.js +43 -0
  20. package/dist/examples/http_example.d.ts +18 -0
  21. package/dist/examples/http_example.d.ts.map +1 -0
  22. package/dist/examples/http_example.js +36 -0
  23. package/dist/examples/mcp_everything.d.ts +6 -0
  24. package/dist/examples/mcp_everything.d.ts.map +1 -0
  25. package/dist/examples/mcp_everything.js +25 -0
  26. package/dist/examples/multi_server_example.d.ts +10 -0
  27. package/dist/examples/multi_server_example.d.ts.map +1 -0
  28. package/dist/examples/multi_server_example.js +51 -0
  29. package/dist/index.d.ts +2 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -0
  32. package/dist/src/adapters/langchain_adapter.js +1 -1
  33. package/dist/src/agents/index.d.ts +0 -1
  34. package/dist/src/agents/index.d.ts.map +1 -1
  35. package/dist/src/agents/index.js +0 -1
  36. package/dist/src/agents/mcp_agent.d.ts +1 -1
  37. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  38. package/dist/src/agents/mcp_agent.js +3 -3
  39. package/dist/src/client.d.ts +1 -1
  40. package/dist/src/client.d.ts.map +1 -1
  41. package/dist/src/client.js +6 -3
  42. package/dist/src/connectors/stdio.d.ts.map +1 -1
  43. package/dist/src/connectors/stdio.js +14 -1
  44. package/dist/src/logging.d.ts +15 -4
  45. package/dist/src/logging.d.ts.map +1 -1
  46. package/dist/src/logging.js +71 -38
  47. package/dist/src/managers/index.d.ts +3 -0
  48. package/dist/src/managers/index.d.ts.map +1 -0
  49. package/dist/src/managers/index.js +2 -0
  50. package/dist/src/managers/server_manager.d.ts +16 -0
  51. package/dist/src/managers/server_manager.d.ts.map +1 -0
  52. package/dist/src/managers/server_manager.js +100 -0
  53. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts +13 -0
  54. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts.map +1 -0
  55. package/dist/src/managers/tools/acquire_active_mcp_server.js +17 -0
  56. package/dist/src/managers/tools/add_server.d.ts +21 -0
  57. package/dist/src/managers/tools/add_server.d.ts.map +1 -0
  58. package/dist/src/managers/tools/add_server.js +40 -0
  59. package/dist/src/managers/tools/base.d.ts +24 -0
  60. package/dist/src/managers/tools/base.d.ts.map +1 -0
  61. package/dist/src/managers/tools/base.js +17 -0
  62. package/dist/src/managers/tools/connect_mcp_server.d.ts +26 -0
  63. package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -0
  64. package/dist/src/managers/tools/connect_mcp_server.js +46 -0
  65. package/dist/src/managers/tools/index.d.ts +5 -0
  66. package/dist/src/managers/tools/index.d.ts.map +1 -0
  67. package/dist/src/managers/tools/index.js +4 -0
  68. package/dist/src/managers/tools/list_mcp_servers.d.ts +13 -0
  69. package/dist/src/managers/tools/list_mcp_servers.d.ts.map +1 -0
  70. package/dist/src/managers/tools/list_mcp_servers.js +33 -0
  71. package/dist/src/managers/tools/release_mcp_server_connection.d.ts +13 -0
  72. package/dist/src/managers/tools/release_mcp_server_connection.d.ts.map +1 -0
  73. package/dist/src/managers/tools/release_mcp_server_connection.js +19 -0
  74. package/dist/src/session.d.ts +1 -9
  75. package/dist/src/session.d.ts.map +1 -1
  76. package/dist/src/session.js +1 -30
  77. package/package.json +52 -21
  78. package/dist/src/agents/server_manager.d.ts +0 -22
  79. package/dist/src/agents/server_manager.d.ts.map +0 -1
  80. package/dist/src/agents/server_manager.js +0 -152
package/README.md CHANGED
@@ -1,10 +1,31 @@
1
+ <div align="center" style="margin: 0 auto; max-width: 80%;">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="./static/logo_white.svg">
4
+ <source media="(prefers-color-scheme: light)" srcset="./static/logo_black.svg">
5
+ <img alt="mcp use logo" src="./static/logo_white.svg" width="80%" style="margin: 20px auto;">
6
+ </picture>
7
+ </div>
8
+
1
9
  <h1 align="center">Unified MCP Client Library</h1>
2
10
 
3
- [![](https://img.shields.io/npm/dw/mcp-use.svg)](https://www.npmjs.com/package/mcp-use)
4
- [![npm version](https://img.shields.io/npm/v/mcp-use.svg)](https://www.npmjs.com/package/mcp-use)
5
- [![License](https://img.shields.io/github/license/zandko/mcp-use)](https://github.com/zandko/mcp-use/blob/main/LICENSE)
6
- [![Code style: ESLint](https://img.shields.io/badge/code%20style-eslint-4B32C3.svg)](https://eslint.org)
7
- [![GitHub stars](https://img.shields.io/github/stars/zandko/mcp-use?style=social)](https://github.com/zandko/mcp-use/stargazers)
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/mcp-use" alt="NPM Downloads">
13
+ <img src="https://img.shields.io/npm/dw/mcp-use.svg"/></a>
14
+ <a href="https://www.npmjs.com/package/mcp-use" alt="NPM Version">
15
+ <img src="https://img.shields.io/npm/v/mcp-use.svg"/></a>
16
+ <a href="https://docs.mcp-use.io" alt="Documentation">
17
+ <img src="https://img.shields.io/badge/docs-mcp--use.io-blue" /></a>
18
+ <a href="https://mcp-use.io" alt="Website">
19
+ <img src="https://img.shields.io/badge/website-mcp--use.io-blue" /></a>
20
+ <a href="https://github.com/mcp-use/mcp-use-ts/blob/main/LICENSE" alt="License">
21
+ <img src="https://img.shields.io/github/license/mcp-use/mcp-use-ts" /></a>
22
+ <a href="https://eslint.org" alt="Code style: ESLint">
23
+ <img src="https://img.shields.io/badge/code%20style-eslint-4B32C3.svg" /></a>
24
+ <a href="https://github.com/mcp-use/mcp-use-ts/stargazers" alt="GitHub stars">
25
+ <img src="https://img.shields.io/github/stars/mcp-use/mcp-use-ts?style=social" /></a>
26
+ <a href="https://discord.gg/XkNkSkMz3V" alt="Discord">
27
+ <img src="https://dcbadge.limes.pink/api/server/XkNkSkMz3V?style=flat" /></a>
28
+ </p>
8
29
 
9
30
  🌐 **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
31
 
@@ -99,11 +120,44 @@ Load it:
99
120
 
100
121
  ```ts
101
122
  import { MCPClient } from 'mcp-use'
123
+
102
124
  const client = MCPClient.fromConfigFile('./mcp-config.json')
103
125
  ```
104
126
 
105
127
  ---
106
128
 
129
+ ## 📚 Examples
130
+
131
+ We provide a comprehensive set of examples demonstrating various use cases. All examples are located in the `examples/` directory with a dedicated README.
132
+
133
+ ### Running Examples
134
+
135
+ ```bash
136
+ # Install dependencies
137
+ npm install
138
+
139
+ # Run any example
140
+ npm run example:airbnb # Search accommodations with Airbnb
141
+ npm run example:browser # Browser automation with Playwright
142
+ npm run example:chat # Interactive chat with memory
143
+ npm run example:filesystem # File system operations
144
+ npm run example:http # HTTP server connection
145
+ npm run example:everything # Test MCP functionalities
146
+ npm run example:multi # Multiple servers in one session
147
+ ```
148
+
149
+ ### Example Highlights
150
+
151
+ - **Browser Automation**: Control browsers to navigate websites and extract information
152
+ - **File Operations**: Read, write, and manipulate files through MCP
153
+ - **Multi-Server**: Combine multiple MCP servers (Airbnb + Browser) in a single task
154
+ - **Sandboxed Execution**: Run MCP servers in isolated E2B containers
155
+ - **OAuth Flows**: Authenticate with services like Linear using OAuth2
156
+
157
+ See the [examples README](./examples/README.md) for detailed documentation and prerequisites.
158
+
159
+ ---
160
+
107
161
  ## 🔄 Multi-Server Example
108
162
 
109
163
  ```ts
@@ -141,6 +195,13 @@ const agent = new MCPAgent({
141
195
  <sub style="font-size:14px"><b>Zane</b></sub>
142
196
  </a>
143
197
  </td>
198
+ <td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
199
+ <a href=https://github.com/pietrozullo>
200
+ <img src=https://avatars.githubusercontent.com/u/62951181?v=4 width="100;" style="border-radius:50%;align-items:center;justify-content:center;overflow:hidden;padding-top:10px" alt=Pietro Zullo/>
201
+ <br />
202
+ <sub style="font-size:14px"><b>Pietro Zullo</b></sub>
203
+ </a>
204
+ </td>
144
205
  </tr>
145
206
  </table>
146
207
 
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Dynamic server management example for mcp-use.
3
+ *
4
+ * This example demonstrates how to equip an MCPAgent with a tool
5
+ * to dynamically add and connect to MCP servers during a run.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=add_server_tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add_server_tool.d.ts","sourceRoot":"","sources":["../../examples/add_server_tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Dynamic server management example for mcp-use.
3
+ *
4
+ * This example demonstrates how to equip an MCPAgent with a tool
5
+ * to dynamically add and connect to MCP servers during a run.
6
+ */
7
+ import { ChatOpenAI } from '@langchain/openai';
8
+ import { config } from 'dotenv';
9
+ import { MCPAgent, MCPClient } from '../index.js';
10
+ import { LangChainAdapter } from '../src/adapters/langchain_adapter.js';
11
+ import { ServerManager } from '../src/managers/server_manager.js';
12
+ // Load environment variables from .env file
13
+ config();
14
+ async function main() {
15
+ // Create an empty MCPClient. It has no servers to start with.
16
+ const client = new MCPClient();
17
+ // The LLM to power the agent
18
+ const llm = new ChatOpenAI({ model: 'gpt-4o', temperature: 0 });
19
+ // Create the agent, enabling the ServerManager
20
+ const agent = new MCPAgent({
21
+ llm,
22
+ client,
23
+ maxSteps: 30,
24
+ useServerManager: true,
25
+ serverManagerFactory: client => new ServerManager(client, new LangChainAdapter()),
26
+ autoInitialize: true,
27
+ });
28
+ // Define the server configuration that the agent will be asked to add.
29
+ const serverConfigA = {
30
+ command: 'npx',
31
+ args: ['@playwright/mcp@latest'],
32
+ env: {
33
+ DISPLAY: ':1',
34
+ },
35
+ };
36
+ const serverConfigB = {
37
+ command: 'npx',
38
+ args: ['-y', '@openbnb/mcp-server-airbnb', '--ignore-robots-txt'],
39
+ };
40
+ // We'll pass the config as a JSON string in the prompt.
41
+ const serverConfigStringA = JSON.stringify(serverConfigA, null, 2);
42
+ const serverConfigStringB = JSON.stringify(serverConfigB, null, 2);
43
+ const query = `I need to browse the web. To do this, please add and connect to a new MCP server for Playwright.
44
+ The server name is 'playwright' and its configuration is:
45
+ \`\`\`json
46
+ ${serverConfigStringA}
47
+ \`\`\`
48
+ Once the server is ready, navigate to https://github.com/mcp-use/mcp-use, give a star to the project, and then provide a concise summary of the project's README.
49
+
50
+ Then, please add and connect to a new MCP server for Airbnb.
51
+ The server name is 'airbnb' and its configuration is:
52
+ \`\`\`json
53
+ ${serverConfigStringB}
54
+ \`\`\`
55
+ and give me a house in the location of the company mcp-use.
56
+ `;
57
+ // Run the agent. It will first use the AddMCPServerTool, then the tools from the new server.
58
+ const result = await agent.run(query);
59
+ console.log(`\n✅ Final Result:\n${result}`);
60
+ // Clean up the session created by the agent
61
+ await client.closeAllSessions();
62
+ }
63
+ if (import.meta.url === `file://${process.argv[1]}`) {
64
+ main().catch(console.error);
65
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Example demonstrating how to use mcp-use with Airbnb.
3
+ *
4
+ * This example shows how to connect an LLM to Airbnb through MCP tools
5
+ * to perform tasks like searching for accommodations.
6
+ *
7
+ * Special Thanks to https://github.com/openbnb-org/mcp-server-airbnb for the server.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=airbnb_use.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"airbnb_use.d.ts","sourceRoot":"","sources":["../../examples/airbnb_use.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Example demonstrating how to use mcp-use with Airbnb.
3
+ *
4
+ * This example shows how to connect an LLM to Airbnb through MCP tools
5
+ * to perform tasks like searching for accommodations.
6
+ *
7
+ * Special Thanks to https://github.com/openbnb-org/mcp-server-airbnb for the server.
8
+ */
9
+ import { ChatOpenAI } from '@langchain/openai';
10
+ import { config } from 'dotenv';
11
+ import { MCPAgent, MCPClient } from '../index.js';
12
+ // Load environment variables from .env file
13
+ config();
14
+ async function runAirbnbExample() {
15
+ // Create MCPClient with Airbnb configuration
16
+ const config = {
17
+ mcpServers: {
18
+ airbnb: {
19
+ command: 'npx',
20
+ args: ['-y', '@openbnb/mcp-server-airbnb', '--ignore-robots-txt'],
21
+ },
22
+ },
23
+ };
24
+ const client = new MCPClient(config);
25
+ // Create LLM - you can choose between different models
26
+ const llm = new ChatOpenAI({ model: 'gpt-4o' });
27
+ // Create agent with the client
28
+ const agent = new MCPAgent({ llm, client, maxSteps: 30 });
29
+ try {
30
+ // Run a query to search for accommodations
31
+ const result = await agent.run('Find me a nice place to stay in Barcelona for 2 adults '
32
+ + 'for a week in August. I prefer places with a pool and '
33
+ + 'good reviews. Show me the top 3 options.', 30);
34
+ console.error(`\nResult: ${result}`);
35
+ }
36
+ finally {
37
+ // Ensure we clean up resources properly
38
+ await client.closeAllSessions();
39
+ }
40
+ }
41
+ if (import.meta.url === `file://${process.argv[1]}`) {
42
+ runAirbnbExample().catch(console.error);
43
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Blender MCP example for mcp-use.
3
+ *
4
+ * This example demonstrates how to use the mcp-use library with MCPClient
5
+ * to connect an LLM to Blender through MCP tools via WebSocket.
6
+ * The example assumes you have installed the Blender MCP addon from:
7
+ * https://github.com/ahujasid/blender-mcp
8
+ *
9
+ * Make sure the addon is enabled in Blender preferences and the WebSocket
10
+ * server is running before executing this script.
11
+ *
12
+ * Special thanks to https://github.com/ahujasid/blender-mcp for the server.
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=blender_use.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blender_use.d.ts","sourceRoot":"","sources":["../../examples/blender_use.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Blender MCP example for mcp-use.
3
+ *
4
+ * This example demonstrates how to use the mcp-use library with MCPClient
5
+ * to connect an LLM to Blender through MCP tools via WebSocket.
6
+ * The example assumes you have installed the Blender MCP addon from:
7
+ * https://github.com/ahujasid/blender-mcp
8
+ *
9
+ * Make sure the addon is enabled in Blender preferences and the WebSocket
10
+ * server is running before executing this script.
11
+ *
12
+ * Special thanks to https://github.com/ahujasid/blender-mcp for the server.
13
+ */
14
+ import { ChatAnthropic } from '@langchain/anthropic';
15
+ import { config } from 'dotenv';
16
+ import { MCPAgent, MCPClient } from '../index.js';
17
+ // Load environment variables from .env file
18
+ config();
19
+ async function runBlenderExample() {
20
+ // Create MCPClient with Blender MCP configuration
21
+ const config = { mcpServers: { blender: { command: 'uvx', args: ['blender-mcp'] } } };
22
+ const client = MCPClient.fromDict(config);
23
+ // Create LLM
24
+ const llm = new ChatAnthropic({ model: 'claude-3-5-sonnet-20240620' });
25
+ // Create agent with the client
26
+ const agent = new MCPAgent({ llm, client, maxSteps: 30 });
27
+ try {
28
+ // Run the query
29
+ const result = await agent.run('Create an inflatable cube with soft material and a plane as ground.', 30);
30
+ console.error(`\nResult: ${result}`);
31
+ }
32
+ finally {
33
+ // Ensure we clean up resources properly
34
+ await client.closeAllSessions();
35
+ }
36
+ }
37
+ if (import.meta.url === `file://${process.argv[1]}`) {
38
+ runBlenderExample().catch(console.error);
39
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Basic usage example for mcp-use.
3
+ *
4
+ * This example demonstrates how to use the mcp-use library with MCPClient
5
+ * to connect any LLM to MCP tools through a unified interface.
6
+ *
7
+ * Special thanks to https://github.com/microsoft/playwright-mcp for the server.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=browser_use.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser_use.d.ts","sourceRoot":"","sources":["../../examples/browser_use.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Basic usage example for mcp-use.
3
+ *
4
+ * This example demonstrates how to use the mcp-use library with MCPClient
5
+ * to connect any LLM to MCP tools through a unified interface.
6
+ *
7
+ * Special thanks to https://github.com/microsoft/playwright-mcp for the server.
8
+ */
9
+ import path from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { ChatOpenAI } from '@langchain/openai';
12
+ import { config } from 'dotenv';
13
+ import { MCPAgent, MCPClient } from '../index.js';
14
+ // Load environment variables from .env file
15
+ config();
16
+ const __filename = fileURLToPath(import.meta.url);
17
+ const __dirname = path.dirname(__filename);
18
+ async function main() {
19
+ const config = {
20
+ mcpServers: {
21
+ playwright: {
22
+ command: 'npx',
23
+ args: ['@playwright/mcp@latest'],
24
+ env: {
25
+ DISPLAY: ':1',
26
+ },
27
+ },
28
+ },
29
+ };
30
+ // Create MCPClient from config file
31
+ const client = new MCPClient(config);
32
+ // Create LLM
33
+ const llm = new ChatOpenAI({ model: 'gpt-4o' });
34
+ // const llm = init_chat_model({ model: "llama-3.1-8b-instant", model_provider: "groq" })
35
+ // const llm = new ChatAnthropic({ model: "claude-3-" })
36
+ // const llm = new ChatGroq({ model: "llama3-8b-8192" })
37
+ // Create agent with the client
38
+ const agent = new MCPAgent({ llm, client, maxSteps: 30 });
39
+ // Run the query
40
+ const result = await agent.run(`Navigate to https://github.com/mcp-use/mcp-use, give a star to the project and write
41
+ a summary of the project.`, 30);
42
+ console.error(`\nResult: ${result}`);
43
+ }
44
+ if (import.meta.url === `file://${process.argv[1]}`) {
45
+ main().catch(console.error);
46
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Simple chat example using MCPAgent with built-in conversation memory.
3
+ *
4
+ * This example demonstrates how to use the MCPAgent with its built-in
5
+ * conversation history capabilities for better contextual interactions.
6
+ *
7
+ * Special thanks to https://github.com/microsoft/playwright-mcp for the server.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=chat_example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat_example.d.ts","sourceRoot":"","sources":["../../examples/chat_example.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Simple chat example using MCPAgent with built-in conversation memory.
3
+ *
4
+ * This example demonstrates how to use the MCPAgent with its built-in
5
+ * conversation history capabilities for better contextual interactions.
6
+ *
7
+ * Special thanks to https://github.com/microsoft/playwright-mcp for the server.
8
+ */
9
+ import readline from 'node:readline';
10
+ import { ChatOpenAI } from '@langchain/openai';
11
+ import { config } from 'dotenv';
12
+ import { MCPAgent, MCPClient } from '../index.js';
13
+ // Load environment variables from .env file
14
+ config();
15
+ async function runMemoryChat() {
16
+ // Config file path - change this to your config file
17
+ const config = {
18
+ mcpServers: {
19
+ airbnb: {
20
+ command: 'npx',
21
+ args: ['-y', '@openbnb/mcp-server-airbnb', '--ignore-robots-txt'],
22
+ },
23
+ },
24
+ };
25
+ console.error('Initializing chat...');
26
+ // Create MCP client and agent with memory enabled
27
+ const client = new MCPClient(config);
28
+ const llm = new ChatOpenAI({ model: 'gpt-4o-mini' });
29
+ // Create agent with memory_enabled=true
30
+ const agent = new MCPAgent({
31
+ llm,
32
+ client,
33
+ maxSteps: 15,
34
+ memoryEnabled: true, // Enable built-in conversation memory
35
+ });
36
+ console.error('\n===== Interactive MCP Chat =====');
37
+ console.error('Type \'exit\' or \'quit\' to end the conversation');
38
+ console.error('Type \'clear\' to clear conversation history');
39
+ console.error('==================================\n');
40
+ // Create readline interface for user input
41
+ const rl = readline.createInterface({
42
+ input: process.stdin,
43
+ output: process.stdout,
44
+ });
45
+ const question = (prompt) => {
46
+ return new Promise((resolve) => {
47
+ rl.question(prompt, resolve);
48
+ });
49
+ };
50
+ try {
51
+ // Main chat loop
52
+ while (true) {
53
+ // Get user input
54
+ const userInput = await question('\nYou: ');
55
+ // Check for exit command
56
+ if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
57
+ console.error('Ending conversation...');
58
+ break;
59
+ }
60
+ // Check for clear history command
61
+ if (userInput.toLowerCase() === 'clear') {
62
+ agent.clearConversationHistory();
63
+ console.error('Conversation history cleared.');
64
+ continue;
65
+ }
66
+ // Get response from agent
67
+ process.stdout.write('\nAssistant: ');
68
+ try {
69
+ // Run the agent with the user input (memory handling is automatic)
70
+ const response = await agent.run(userInput);
71
+ console.error(response);
72
+ }
73
+ catch (error) {
74
+ console.error(`\nError: ${error}`);
75
+ }
76
+ }
77
+ }
78
+ finally {
79
+ // Clean up
80
+ rl.close();
81
+ await client.closeAllSessions();
82
+ }
83
+ }
84
+ if (import.meta.url === `file://${process.argv[1]}`) {
85
+ runMemoryChat().catch(console.error);
86
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Basic usage example for mcp-use.
3
+ *
4
+ * This example demonstrates how to use the mcp-use library with MCPClient
5
+ * to connect any LLM to MCP tools through a unified interface.
6
+ *
7
+ * Special Thanks to https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem
8
+ * for the server.
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=filesystem_use.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem_use.d.ts","sourceRoot":"","sources":["../../examples/filesystem_use.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Basic usage example for mcp-use.
3
+ *
4
+ * This example demonstrates how to use the mcp-use library with MCPClient
5
+ * to connect any LLM to MCP tools through a unified interface.
6
+ *
7
+ * Special Thanks to https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem
8
+ * for the server.
9
+ */
10
+ import { ChatOpenAI } from '@langchain/openai';
11
+ import { config } from 'dotenv';
12
+ import { MCPAgent, MCPClient } from '../index.js';
13
+ // Load environment variables from .env file
14
+ config();
15
+ const serverConfig = {
16
+ mcpServers: {
17
+ filesystem: {
18
+ command: 'npx',
19
+ args: [
20
+ '-y',
21
+ '@modelcontextprotocol/server-filesystem',
22
+ 'THE_PATH_TO_YOUR_DIRECTORY',
23
+ ],
24
+ },
25
+ },
26
+ };
27
+ async function main() {
28
+ // Create MCPClient from config
29
+ const client = MCPClient.fromDict(serverConfig);
30
+ // Create LLM
31
+ const llm = new ChatOpenAI({ model: 'gpt-4o' });
32
+ // const llm = init_chat_model({ model: "llama-3.1-8b-instant", model_provider: "groq" })
33
+ // const llm = new ChatAnthropic({ model: "claude-3-" })
34
+ // const llm = new ChatGroq({ model: "llama3-8b-8192" })
35
+ // Create agent with the client
36
+ const agent = new MCPAgent({ llm, client, maxSteps: 30 });
37
+ // Run the query
38
+ const result = await agent.run('Hello can you give me a list of files and directories in the current directory', 30);
39
+ console.log(`\nResult: ${result}`);
40
+ }
41
+ if (import.meta.url === `file://${process.argv[1]}`) {
42
+ main().catch(console.error);
43
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * HTTP Example for mcp-use.
3
+ *
4
+ * This example demonstrates how to use the mcp-use library with MCPClient
5
+ * to connect to an MCP server running on a specific HTTP port.
6
+ *
7
+ * Before running this example, you need to start the Playwright MCP server
8
+ * in another terminal with:
9
+ *
10
+ * npx @playwright/mcp@latest --port 8931
11
+ *
12
+ * This will start the server on port 8931. Resulting in the config you find below.
13
+ * Of course you can run this with any server you want at any URL.
14
+ *
15
+ * Special thanks to https://github.com/microsoft/playwright-mcp for the server.
16
+ */
17
+ export {};
18
+ //# sourceMappingURL=http_example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http_example.d.ts","sourceRoot":"","sources":["../../examples/http_example.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * HTTP Example for mcp-use.
3
+ *
4
+ * This example demonstrates how to use the mcp-use library with MCPClient
5
+ * to connect to an MCP server running on a specific HTTP port.
6
+ *
7
+ * Before running this example, you need to start the Playwright MCP server
8
+ * in another terminal with:
9
+ *
10
+ * npx @playwright/mcp@latest --port 8931
11
+ *
12
+ * This will start the server on port 8931. Resulting in the config you find below.
13
+ * Of course you can run this with any server you want at any URL.
14
+ *
15
+ * Special thanks to https://github.com/microsoft/playwright-mcp for the server.
16
+ */
17
+ import { ChatOpenAI } from '@langchain/openai';
18
+ import { config } from 'dotenv';
19
+ import { MCPAgent, MCPClient } from '../index.js';
20
+ // Load environment variables from .env file
21
+ config();
22
+ async function main() {
23
+ const config = { mcpServers: { http: { url: 'https://hf.com/mcp' } } };
24
+ // Create MCPClient from config
25
+ const client = MCPClient.fromDict(config);
26
+ // Create LLM
27
+ const llm = new ChatOpenAI({ model: 'gpt-4o' });
28
+ // Create agent with the client
29
+ const agent = new MCPAgent({ llm, client, maxSteps: 30 });
30
+ // Run the query
31
+ const result = await agent.run('Find the best restaurant in San Francisco USING GOOGLE SEARCH', 30);
32
+ console.log(`\nResult: ${result}`);
33
+ }
34
+ if (import.meta.url === `file://${process.argv[1]}`) {
35
+ main().catch(console.error);
36
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This example shows how to test the different functionalities of MCPs using the MCP server from
3
+ * anthropic.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=mcp_everything.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp_everything.d.ts","sourceRoot":"","sources":["../../examples/mcp_everything.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * This example shows how to test the different functionalities of MCPs using the MCP server from
3
+ * anthropic.
4
+ */
5
+ import { ChatOpenAI } from '@langchain/openai';
6
+ import { config } from 'dotenv';
7
+ import { MCPAgent, MCPClient } from '../index.js';
8
+ // Load environment variables from .env file
9
+ config();
10
+ const everythingServer = {
11
+ mcpServers: { everything: { command: 'npx', args: ['-y', '@modelcontextprotocol/server-everything'] } },
12
+ };
13
+ async function main() {
14
+ const client = new MCPClient(everythingServer);
15
+ const llm = new ChatOpenAI({ model: 'gpt-4o', temperature: 0 });
16
+ const agent = new MCPAgent({ llm, client, maxSteps: 30 });
17
+ const result = await agent.run(`Hello, you are a tester can you please answer the follwing questions:
18
+ - Which resources do you have access to?
19
+ - Which prompts do you have access to?
20
+ - Which tools do you have access to?`, 30);
21
+ console.log(`\nResult: ${result}`);
22
+ }
23
+ if (import.meta.url === `file://${process.argv[1]}`) {
24
+ main().catch(console.error);
25
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Example demonstrating how to use MCPClient with multiple servers.
3
+ *
4
+ * This example shows how to:
5
+ * 1. Configure multiple MCP servers
6
+ * 2. Create and manage sessions for each server
7
+ * 3. Use tools from different servers in a single agent
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=multi_server_example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi_server_example.d.ts","sourceRoot":"","sources":["../../examples/multi_server_example.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}