mcp-use 0.1.20 → 0.3.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 (140) hide show
  1. package/dist/chunk-2HFIPY7C.js +429 -0
  2. package/dist/chunk-4DEFXVWT.js +680 -0
  3. package/dist/chunk-JXLQRAW2.js +532 -0
  4. package/dist/chunk-SHUYVCID.js +6 -0
  5. package/dist/chunk-YUSC6R6V.js +299 -0
  6. package/dist/index.cjs +5762 -0
  7. package/dist/index.d.ts +7 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3767 -22
  10. package/dist/langfuse-YA2S23SM.js +13 -0
  11. package/dist/src/agents/remote.d.ts.map +1 -1
  12. package/dist/src/agents/utils/ai_sdk.d.ts.map +1 -1
  13. package/dist/src/auth/browser-provider.d.ts +52 -0
  14. package/dist/src/auth/browser-provider.d.ts.map +1 -0
  15. package/dist/src/auth/callback.d.ts +6 -0
  16. package/dist/src/auth/callback.d.ts.map +1 -0
  17. package/dist/src/auth/index.d.ts +7 -0
  18. package/dist/src/auth/index.d.ts.map +1 -0
  19. package/dist/src/auth/types.d.ts +18 -0
  20. package/dist/src/auth/types.d.ts.map +1 -0
  21. package/dist/src/browser.cjs +323 -0
  22. package/dist/src/browser.d.ts +8 -0
  23. package/dist/src/browser.d.ts.map +1 -0
  24. package/dist/src/browser.js +9 -0
  25. package/dist/src/client/base.d.ts +32 -0
  26. package/dist/src/client/base.d.ts.map +1 -0
  27. package/dist/src/client.d.ts +19 -16
  28. package/dist/src/client.d.ts.map +1 -1
  29. package/dist/src/logging.d.ts +1 -1
  30. package/dist/src/logging.d.ts.map +1 -1
  31. package/dist/src/oauth-helper.d.ts +125 -0
  32. package/dist/src/oauth-helper.d.ts.map +1 -0
  33. package/dist/src/react/index.cjs +986 -0
  34. package/dist/src/react/index.d.ts +9 -0
  35. package/dist/src/react/index.d.ts.map +1 -0
  36. package/dist/src/react/index.js +11 -0
  37. package/dist/src/react/types.d.ts +139 -0
  38. package/dist/src/react/types.d.ts.map +1 -0
  39. package/dist/src/react/useMcp.d.ts +3 -0
  40. package/dist/src/react/useMcp.d.ts.map +1 -0
  41. package/dist/src/server/index.cjs +566 -0
  42. package/dist/src/server/index.d.ts +3 -0
  43. package/dist/src/server/index.d.ts.map +1 -0
  44. package/dist/src/server/index.js +9 -0
  45. package/dist/src/server/logging.d.ts +16 -0
  46. package/dist/src/server/logging.d.ts.map +1 -0
  47. package/dist/src/server/mcp-server.d.ts +282 -0
  48. package/dist/src/server/mcp-server.d.ts.map +1 -0
  49. package/dist/src/server/types.d.ts +47 -0
  50. package/dist/src/server/types.d.ts.map +1 -0
  51. package/dist/src/utils/assert.d.ts +8 -0
  52. package/dist/src/utils/assert.d.ts.map +1 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -0
  54. package/package.json +72 -40
  55. package/dist/examples/add_server_tool.d.ts +0 -8
  56. package/dist/examples/add_server_tool.d.ts.map +0 -1
  57. package/dist/examples/add_server_tool.js +0 -79
  58. package/dist/examples/ai_sdk_example.d.ts +0 -23
  59. package/dist/examples/ai_sdk_example.d.ts.map +0 -1
  60. package/dist/examples/ai_sdk_example.js +0 -213
  61. package/dist/examples/airbnb_use.d.ts +0 -10
  62. package/dist/examples/airbnb_use.d.ts.map +0 -1
  63. package/dist/examples/airbnb_use.js +0 -43
  64. package/dist/examples/blender_use.d.ts +0 -15
  65. package/dist/examples/blender_use.d.ts.map +0 -1
  66. package/dist/examples/blender_use.js +0 -39
  67. package/dist/examples/browser_use.d.ts +0 -10
  68. package/dist/examples/browser_use.d.ts.map +0 -1
  69. package/dist/examples/browser_use.js +0 -46
  70. package/dist/examples/chat_example.d.ts +0 -10
  71. package/dist/examples/chat_example.d.ts.map +0 -1
  72. package/dist/examples/chat_example.js +0 -86
  73. package/dist/examples/filesystem_use.d.ts +0 -11
  74. package/dist/examples/filesystem_use.d.ts.map +0 -1
  75. package/dist/examples/filesystem_use.js +0 -43
  76. package/dist/examples/http_example.d.ts +0 -18
  77. package/dist/examples/http_example.d.ts.map +0 -1
  78. package/dist/examples/http_example.js +0 -37
  79. package/dist/examples/mcp_everything.d.ts +0 -6
  80. package/dist/examples/mcp_everything.d.ts.map +0 -1
  81. package/dist/examples/mcp_everything.js +0 -25
  82. package/dist/examples/multi_server_example.d.ts +0 -10
  83. package/dist/examples/multi_server_example.d.ts.map +0 -1
  84. package/dist/examples/multi_server_example.js +0 -51
  85. package/dist/examples/observability.d.ts +0 -6
  86. package/dist/examples/observability.d.ts.map +0 -1
  87. package/dist/examples/observability.js +0 -50
  88. package/dist/examples/stream_example.d.ts +0 -12
  89. package/dist/examples/stream_example.d.ts.map +0 -1
  90. package/dist/examples/stream_example.js +0 -198
  91. package/dist/examples/structured_output.d.ts +0 -9
  92. package/dist/examples/structured_output.d.ts.map +0 -1
  93. package/dist/examples/structured_output.js +0 -95
  94. package/dist/src/adapters/base.js +0 -124
  95. package/dist/src/adapters/index.js +0 -2
  96. package/dist/src/adapters/langchain_adapter.js +0 -49
  97. package/dist/src/agents/base.js +0 -9
  98. package/dist/src/agents/index.js +0 -3
  99. package/dist/src/agents/mcp_agent.js +0 -1002
  100. package/dist/src/agents/prompts/system_prompt_builder.js +0 -40
  101. package/dist/src/agents/prompts/templates.js +0 -39
  102. package/dist/src/agents/remote.js +0 -264
  103. package/dist/src/agents/utils/ai_sdk.js +0 -62
  104. package/dist/src/agents/utils/index.js +0 -1
  105. package/dist/src/client.js +0 -133
  106. package/dist/src/config.js +0 -34
  107. package/dist/src/connectors/base.js +0 -143
  108. package/dist/src/connectors/http.js +0 -150
  109. package/dist/src/connectors/index.js +0 -4
  110. package/dist/src/connectors/stdio.js +0 -68
  111. package/dist/src/connectors/websocket.js +0 -157
  112. package/dist/src/logging.js +0 -217
  113. package/dist/src/managers/index.js +0 -2
  114. package/dist/src/managers/server_manager.js +0 -106
  115. package/dist/src/managers/tools/acquire_active_mcp_server.js +0 -17
  116. package/dist/src/managers/tools/add_server_from_config.js +0 -40
  117. package/dist/src/managers/tools/base.js +0 -17
  118. package/dist/src/managers/tools/connect_mcp_server.js +0 -46
  119. package/dist/src/managers/tools/index.js +0 -5
  120. package/dist/src/managers/tools/list_mcp_servers.js +0 -33
  121. package/dist/src/managers/tools/release_mcp_server_connection.js +0 -19
  122. package/dist/src/observability/index.js +0 -12
  123. package/dist/src/observability/langfuse.js +0 -211
  124. package/dist/src/observability/manager.js +0 -199
  125. package/dist/src/observability/types.js +0 -4
  126. package/dist/src/session.js +0 -23
  127. package/dist/src/task_managers/base.js +0 -127
  128. package/dist/src/task_managers/index.js +0 -5
  129. package/dist/src/task_managers/sse.js +0 -43
  130. package/dist/src/task_managers/stdio.js +0 -51
  131. package/dist/src/task_managers/streamable_http.js +0 -50
  132. package/dist/src/task_managers/websocket.js +0 -67
  133. package/dist/src/telemetry/events.js +0 -44
  134. package/dist/src/telemetry/index.js +0 -8
  135. package/dist/src/telemetry/telemetry.js +0 -324
  136. package/dist/src/telemetry/utils.js +0 -39
  137. package/dist/tests/ai_sdk_compatibility.test.js +0 -214
  138. package/dist/tests/stream_events.test.js +0 -307
  139. package/dist/tests/stream_events_simple.test.js +0 -179
  140. package/dist/vitest.config.js +0 -21
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "mcp-use",
3
3
  "type": "module",
4
- "version": "0.1.20",
5
- "packageManager": "pnpm@10.6.1",
6
- "description": "A utility library for integrating Model Context Protocol (MCP) with LangChain, Zod, and related tools. Provides helpers for schema conversion, event streaming, and SDK usage.",
4
+ "version": "0.3.0",
5
+ "description": "Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents and Clients + MCP Servers with support for MCP-UI.",
7
6
  "author": "mcp-use, Inc.",
8
7
  "license": "MIT",
9
8
  "homepage": "https://github.com/mcp-use/mcp-use-ts#readme",
@@ -17,7 +16,6 @@
17
16
  "keywords": [
18
17
  "MCP",
19
18
  "Model Context Protocol",
20
- "LangChain",
21
19
  "Zod",
22
20
  "schema",
23
21
  "SDK",
@@ -30,6 +28,18 @@
30
28
  ".": {
31
29
  "types": "./dist/index.d.ts",
32
30
  "import": "./dist/index.js"
31
+ },
32
+ "./browser": {
33
+ "types": "./dist/src/browser.d.ts",
34
+ "import": "./dist/src/browser.js"
35
+ },
36
+ "./react": {
37
+ "types": "./dist/src/react/index.d.ts",
38
+ "import": "./dist/src/react/index.js"
39
+ },
40
+ "./server": {
41
+ "types": "./dist/src/server/index.d.ts",
42
+ "import": "./dist/src/server/index.js"
33
43
  }
34
44
  },
35
45
  "main": "./dist/index.js",
@@ -42,46 +52,27 @@
42
52
  "node": ">=22.0.0"
43
53
  },
44
54
  "publishConfig": {
45
- "registry": "https://registry.npmjs.org"
46
- },
47
- "scripts": {
48
- "build": "rm -rf dist && tsc",
49
- "lint": "eslint",
50
- "lint:fix": "eslint --fix",
51
- "test": "vitest",
52
- "test:run": "vitest run",
53
- "test:simple": "vitest run tests/stream_events_simple.test.ts",
54
- "test:integration": "vitest run tests/stream_events.test.ts",
55
- "watch": "tsc --watch",
56
- "start": "node dist/index.js",
57
- "prepublishOnly": "npm run build",
58
- "fmt": "eslint --fix",
59
- "release": "npm version patch --tag-version-prefix=v && git push --follow-tags",
60
- "release:minor": "npm version minor --tag-version-prefix=v && git push --follow-tags",
61
- "release:major": "npm version major --tag-version-prefix=v && git push --follow-tags",
62
- "prepare": "husky",
63
- "example:airbnb": "npm run build && node dist/examples/airbnb_use.js",
64
- "example:browser": "npm run build && node dist/examples/browser_use.js",
65
- "example:chat": "npm run build && node dist/examples/chat_example.js",
66
- "example:stream": "npm run build && node dist/examples/stream_example.js",
67
- "example:stream_events": "npm run build && node dist/examples/stream_events_example.js",
68
- "example:ai_sdk": "npm run build && node dist/examples/ai_sdk_example.js",
69
- "example:filesystem": "npm run build && node dist/examples/filesystem_use.js",
70
- "example:http": "npm run build && node dist/examples/http_example.js",
71
- "example:everything": "npm run build && node dist/examples/mcp_everything.js",
72
- "example:multi": "npm run build && node dist/examples/multi_server_example.js",
73
- "example:sandbox": "npm run build && node dist/examples/sandbox_everything.js",
74
- "example:oauth": "npm run build && node dist/examples/simple_oauth_example.js",
75
- "example:blender": "npm run build && node dist/examples/blender_use.js",
76
- "example:add_server": "npm run build && node dist/examples/add_server_tool.js",
77
- "example:structured": "npm run build && node dist/examples/structured_output.js",
78
- "example:observability": "npm run build && node dist/examples/observability.js"
55
+ "registry": "https://registry.npmjs.org",
56
+ "access": "public"
79
57
  },
80
58
  "peerDependencies": {
59
+ "@mcp-use/inspector": "^0.2.1",
60
+ "cors": "^2.8.5",
61
+ "express": "^4.18.2",
81
62
  "langfuse": "^3.32.0",
82
- "langfuse-langchain": "^3.38.4"
63
+ "langfuse-langchain": "^3.38.4",
64
+ "react": "^18.0.0"
83
65
  },
84
66
  "peerDependenciesMeta": {
67
+ "@mcp-use/inspector": {
68
+ "optional": true
69
+ },
70
+ "cors": {
71
+ "optional": true
72
+ },
73
+ "express": {
74
+ "optional": true
75
+ },
85
76
  "langfuse": {
86
77
  "optional": true
87
78
  },
@@ -94,28 +85,40 @@
94
85
  "@langchain/anthropic": "^0.3.26",
95
86
  "@langchain/core": "^0.3.72",
96
87
  "@langchain/openai": "^0.6.9",
88
+ "@mcp-ui/server": "^5.11.0",
97
89
  "@modelcontextprotocol/sdk": "1.12.1",
98
90
  "@scarf/scarf": "^1.4.0",
99
91
  "ai": "^4.3.19",
92
+ "commander": "^14.0.1",
100
93
  "dotenv": "^16.5.0",
101
94
  "langchain": "^0.3.27",
102
95
  "lodash-es": "^4.17.21",
103
96
  "posthog-node": "^5.1.1",
97
+ "strict-url-sanitise": "^0.0.1",
98
+ "ts-node": "^10.9.2",
99
+ "tsx": "^4.20.6",
104
100
  "uuid": "^11.1.0",
105
101
  "winston": "^3.17.0",
102
+ "winston-transport-browserconsole": "^1.0.5",
106
103
  "ws": "^8.18.2",
107
104
  "zod": "^3.25.48",
108
105
  "zod-to-json-schema": "^3.24.6"
109
106
  },
110
107
  "devDependencies": {
111
108
  "@antfu/eslint-config": "^4.13.2",
109
+ "@types/cors": "^2.8.17",
110
+ "@types/express": "^4.17.21",
112
111
  "@types/lodash-es": "^4.17.12",
113
112
  "@types/node": "^20.19.8",
113
+ "@types/react": "^19.2.2",
114
114
  "@types/ws": "^8.18.1",
115
+ "cors": "^2.8.5",
115
116
  "eslint": "^9.28.0",
116
117
  "eslint-plugin-format": "^1.0.1",
118
+ "express": "^4.18.2",
117
119
  "husky": "^9.1.7",
118
120
  "lint-staged": "^15.2.11",
121
+ "react": "^19.2.0",
119
122
  "typescript": "^5.8.3",
120
123
  "vitest": "^2.1.9"
121
124
  },
@@ -128,5 +131,34 @@
128
131
  "eslint --fix",
129
132
  "eslint"
130
133
  ]
134
+ },
135
+ "scripts": {
136
+ "build": "rm -rf dist && tsup index.ts src/browser.ts src/react/index.ts src/server/index.ts --format cjs,esm --out-dir dist --keep-names && tsc --emitDeclarationOnly --declaration",
137
+ "test": "vitest",
138
+ "test:run": "vitest run",
139
+ "test:simple": "vitest run tests/stream_events_simple.test.ts",
140
+ "test:integration": "vitest run tests/stream_events.test.ts",
141
+ "watch": "tsc --watch",
142
+ "start": "node dist/index.js",
143
+ "fmt": "eslint --fix",
144
+ "release": "npm version patch --tag-version-prefix=v && git push --follow-tags",
145
+ "release:minor": "npm version minor --tag-version-prefix=v && git push --follow-tags",
146
+ "release:major": "npm version major --tag-version-prefix=v && git push --follow-tags",
147
+ "example:airbnb": "npm run build && node dist/examples/airbnb_use.js",
148
+ "example:browser": "npm run build && node dist/examples/browser_use.js",
149
+ "example:chat": "npm run build && node dist/examples/chat_example.js",
150
+ "example:stream": "npm run build && node dist/examples/stream_example.js",
151
+ "example:stream_events": "npm run build && node dist/examples/stream_events_example.js",
152
+ "example:ai_sdk": "npm run build && node dist/examples/ai_sdk_example.js",
153
+ "example:filesystem": "npm run build && node dist/examples/filesystem_use.js",
154
+ "example:http": "npm run build && node dist/examples/http_example.js",
155
+ "example:everything": "npm run build && node dist/examples/mcp_everything.js",
156
+ "example:multi": "npm run build && node dist/examples/multi_server_example.js",
157
+ "example:sandbox": "npm run build && node dist/examples/sandbox_everything.js",
158
+ "example:oauth": "npm run build && node dist/examples/simple_oauth_example.js",
159
+ "example:blender": "npm run build && node dist/examples/blender_use.js",
160
+ "example:add_server": "npm run build && node dist/examples/add_server_tool.js",
161
+ "example:structured": "npm run build && node dist/examples/structured_output.js",
162
+ "example:observability": "npm run build && node dist/examples/observability.js"
131
163
  }
132
- }
164
+ }
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"add_server_tool.d.ts","sourceRoot":"","sources":["../../examples/add_server_tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -1,79 +0,0 @@
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
- import { AddMCPServerFromConfigTool } from '../src/managers/tools/add_server_from_config.js';
13
- // Load environment variables from .env file
14
- config();
15
- async function main() {
16
- // Create an empty MCPClient. It has no servers to start with.
17
- const client = new MCPClient();
18
- // The LLM to power the agent
19
- const llm = new ChatOpenAI({ model: 'gpt-4o', temperature: 0 });
20
- const serverManager = new ServerManager(client, new LangChainAdapter());
21
- serverManager.setManagementTools([new AddMCPServerFromConfigTool(serverManager)]);
22
- // Create the agent, enabling the ServerManager
23
- const agent = new MCPAgent({
24
- llm,
25
- client,
26
- maxSteps: 30,
27
- autoInitialize: true,
28
- useServerManager: true,
29
- serverManagerFactory: () => serverManager,
30
- });
31
- // Define the server configuration that the agent will be asked to add.
32
- const serverConfigA = {
33
- command: 'npx',
34
- args: ['@playwright/mcp@latest', '--headless'],
35
- env: {
36
- DISPLAY: ':1',
37
- },
38
- };
39
- const serverConfigB = {
40
- command: 'npx',
41
- args: ['-y', '@openbnb/mcp-server-airbnb', '--ignore-robots-txt'],
42
- };
43
- // We'll pass the config as a JSON string in the prompt.
44
- const serverConfigStringA = JSON.stringify(serverConfigA, null, 2);
45
- const serverConfigStringB = JSON.stringify(serverConfigB, null, 2);
46
- const query = `I need to browse the web. To do this, please add and connect to a new MCP server for Playwright.
47
- The server name is 'playwright' and its configuration is:
48
- \`\`\`json
49
- ${serverConfigStringA}
50
- \`\`\`
51
- 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.
52
-
53
- Then, please add and connect to a new MCP server for Airbnb.
54
- The server name is 'airbnb' and its configuration is:
55
- \`\`\`json
56
- ${serverConfigStringB}
57
- \`\`\`
58
- and give me a house in the location of the company mcp-use.
59
- `;
60
- // Run the agent. We call `stream()` to get the async generator.
61
- const stepIterator = agent.stream(query);
62
- let result;
63
- while (true) {
64
- const { done, value } = await stepIterator.next();
65
- if (done) {
66
- result = value;
67
- break;
68
- }
69
- // You can inspect the intermediate steps here.
70
- console.log('--- Agent Step ---');
71
- console.dir(value, { depth: 4 });
72
- }
73
- console.log(`\n✅ Final Result:\n${result}`);
74
- // Clean up the session created by the agent
75
- await client.closeAllSessions();
76
- }
77
- if (import.meta.url === `file://${process.argv[1]}`) {
78
- main().catch(console.error);
79
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * AI SDK Integration Example
3
- *
4
- * This example demonstrates how to use MCPAgent's streamEvents() method
5
- * with Vercel AI SDK's LangChainAdapter for building streaming UIs.
6
- *
7
- * This pattern is useful for:
8
- * - Next.js API routes with useCompletion/useChat hooks
9
- * - Real-time streaming applications
10
- * - Building chat interfaces with token-by-token updates
11
- */
12
- import type { StreamEvent } from '../index.js';
13
- declare function streamEventsToAISDK(streamEvents: AsyncGenerator<StreamEvent, void, void>): AsyncGenerator<string, void, void>;
14
- declare function createReadableStreamFromGenerator(generator: AsyncGenerator<string, void, void>): ReadableStream<string>;
15
- declare function streamEventsToAISDKWithTools(streamEvents: AsyncGenerator<StreamEvent, void, void>): AsyncGenerator<string, void, void>;
16
- declare function createApiHandler(): Promise<(request: {
17
- prompt: string;
18
- }) => Promise<Response>>;
19
- declare function createEnhancedApiHandler(): Promise<(request: {
20
- prompt: string;
21
- }) => Promise<Response>>;
22
- export { createApiHandler, createEnhancedApiHandler, createReadableStreamFromGenerator, streamEventsToAISDK, streamEventsToAISDKWithTools, };
23
- //# sourceMappingURL=ai_sdk_example.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai_sdk_example.d.ts","sourceRoot":"","sources":["../../examples/ai_sdk_example.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAU9C,iBAAgB,mBAAmB,CACjC,YAAY,EAAE,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,GACpD,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAUpC;AAGD,iBAAS,iCAAiC,CACxC,SAAS,EAAE,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,GAC5C,cAAc,CAAC,MAAM,CAAC,CAcxB;AAGD,iBAAgB,4BAA4B,CAC1C,YAAY,EAAE,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,GACpD,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAqBpC;AAGD,iBAAe,gBAAgB,sBAwBM;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,wBAsBtD;AAGD,iBAAe,wBAAwB,sBAuBM;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,wBAkB9D;AAoFD,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,iCAAiC,EACjC,mBAAmB,EACnB,4BAA4B,GAC7B,CAAA"}
@@ -1,213 +0,0 @@
1
- /**
2
- * AI SDK Integration Example
3
- *
4
- * This example demonstrates how to use MCPAgent's streamEvents() method
5
- * with Vercel AI SDK's LangChainAdapter for building streaming UIs.
6
- *
7
- * This pattern is useful for:
8
- * - Next.js API routes with useCompletion/useChat hooks
9
- * - Real-time streaming applications
10
- * - Building chat interfaces with token-by-token updates
11
- */
12
- import { ChatAnthropic } from '@langchain/anthropic';
13
- import { LangChainAdapter } from 'ai';
14
- import { config } from 'dotenv';
15
- import { MCPAgent, MCPClient } from '../index.js';
16
- // Load environment variables
17
- config();
18
- // Utility function to convert streamEvents to AI SDK compatible stream
19
- async function* streamEventsToAISDK(streamEvents) {
20
- for await (const event of streamEvents) {
21
- // Only yield the actual content tokens from chat model streams
22
- if (event.event === 'on_chat_model_stream' && event.data?.chunk?.text) {
23
- const textContent = event.data.chunk.text;
24
- if (typeof textContent === 'string' && textContent.length > 0) {
25
- yield textContent;
26
- }
27
- }
28
- }
29
- }
30
- // Convert async generator to ReadableStream for AI SDK compatibility
31
- function createReadableStreamFromGenerator(generator) {
32
- return new ReadableStream({
33
- async start(controller) {
34
- try {
35
- for await (const chunk of generator) {
36
- controller.enqueue(chunk);
37
- }
38
- controller.close();
39
- }
40
- catch (error) {
41
- controller.error(error);
42
- }
43
- },
44
- });
45
- }
46
- // Enhanced adapter that includes tool information
47
- async function* streamEventsToAISDKWithTools(streamEvents) {
48
- for await (const event of streamEvents) {
49
- switch (event.event) {
50
- case 'on_chat_model_stream':
51
- if (event.data?.chunk?.text) {
52
- const textContent = event.data.chunk.text;
53
- if (typeof textContent === 'string' && textContent.length > 0) {
54
- yield textContent;
55
- }
56
- }
57
- break;
58
- case 'on_tool_start':
59
- yield `\n🔧 Using tool: ${event.name}\n`;
60
- break;
61
- case 'on_tool_end':
62
- yield `\n✅ Tool completed: ${event.name}\n`;
63
- break;
64
- }
65
- }
66
- }
67
- // Example: Basic AI SDK API route handler
68
- async function createApiHandler() {
69
- const everythingServer = {
70
- mcpServers: {
71
- everything: {
72
- command: 'npx',
73
- args: ['-y', '@modelcontextprotocol/server-everything'],
74
- },
75
- },
76
- };
77
- const client = new MCPClient(everythingServer);
78
- const llm = new ChatAnthropic({
79
- model: 'claude-sonnet-4-20250514',
80
- temperature: 0.1,
81
- });
82
- const agent = new MCPAgent({
83
- llm,
84
- client,
85
- maxSteps: 5,
86
- verbose: false,
87
- });
88
- // Simulate an API route handler
89
- const apiHandler = async (request) => {
90
- try {
91
- // Get streamEvents from MCPAgent
92
- const streamEvents = agent.streamEvents(request.prompt);
93
- // Convert to AI SDK compatible format
94
- const aiSDKStream = streamEventsToAISDK(streamEvents);
95
- const readableStream = createReadableStreamFromGenerator(aiSDKStream);
96
- // Use LangChainAdapter to create a Response compatible with AI SDK
97
- return LangChainAdapter.toDataStreamResponse(readableStream);
98
- }
99
- catch (error) {
100
- console.error('Error in API handler:', error);
101
- throw error;
102
- }
103
- finally {
104
- await client.closeAllSessions();
105
- }
106
- };
107
- return apiHandler;
108
- }
109
- // Example: Enhanced API handler with tool visibility
110
- async function createEnhancedApiHandler() {
111
- const everythingServer = {
112
- mcpServers: {
113
- everything: {
114
- command: 'npx',
115
- args: ['-y', '@modelcontextprotocol/server-everything'],
116
- },
117
- },
118
- };
119
- const client = new MCPClient(everythingServer);
120
- const llm = new ChatAnthropic({
121
- model: 'claude-sonnet-4-20250514',
122
- temperature: 0.1,
123
- });
124
- const agent = new MCPAgent({
125
- llm,
126
- client,
127
- maxSteps: 8,
128
- verbose: false,
129
- });
130
- const enhancedApiHandler = async (request) => {
131
- try {
132
- const streamEvents = agent.streamEvents(request.prompt);
133
- const enhancedStream = streamEventsToAISDKWithTools(streamEvents);
134
- const readableStream = createReadableStreamFromGenerator(enhancedStream);
135
- return LangChainAdapter.toDataStreamResponse(readableStream);
136
- }
137
- catch (error) {
138
- console.error('Error in enhanced API handler:', error);
139
- throw error;
140
- }
141
- finally {
142
- await client.closeAllSessions();
143
- }
144
- };
145
- return enhancedApiHandler;
146
- }
147
- // Example: Simulated Next.js API route
148
- async function simulateNextJSApiRoute() {
149
- console.log('🚀 Simulating Next.js API Route with AI SDK Integration\n');
150
- const apiHandler = await createApiHandler();
151
- // Simulate a request
152
- const request = {
153
- prompt: 'What\'s the current time? Also, list the files in the current directory.',
154
- };
155
- console.log(`📝 Request: ${request.prompt}\n`);
156
- console.log('📡 Streaming response:\n');
157
- try {
158
- const response = await apiHandler(request);
159
- if (response.body) {
160
- const reader = response.body.getReader();
161
- const decoder = new TextDecoder();
162
- while (true) {
163
- const { done, value } = await reader.read();
164
- if (done)
165
- break;
166
- const chunk = decoder.decode(value);
167
- process.stdout.write(chunk);
168
- }
169
- }
170
- }
171
- catch (error) {
172
- console.error('❌ Error:', error);
173
- }
174
- console.log('\n\n✅ API Route simulation complete');
175
- }
176
- // Example: Enhanced streaming with tool visibility
177
- async function simulateEnhancedStreaming() {
178
- console.log('\n\n🚀 Enhanced Streaming with Tool Visibility\n');
179
- const enhancedHandler = await createEnhancedApiHandler();
180
- const request = {
181
- prompt: 'Check the current time and create a file with a timestamp. Then tell me what tools you used.',
182
- };
183
- console.log(`📝 Request: ${request.prompt}\n`);
184
- console.log('📡 Enhanced streaming response:\n');
185
- try {
186
- const response = await enhancedHandler(request);
187
- if (response.body) {
188
- const reader = response.body.getReader();
189
- const decoder = new TextDecoder();
190
- while (true) {
191
- const { done, value } = await reader.read();
192
- if (done)
193
- break;
194
- const chunk = decoder.decode(value);
195
- process.stdout.write(chunk);
196
- }
197
- }
198
- }
199
- catch (error) {
200
- console.error('❌ Error:', error);
201
- }
202
- console.log('\n\n✅ Enhanced streaming complete');
203
- }
204
- // Run all examples
205
- async function runAllExamples() {
206
- await simulateNextJSApiRoute();
207
- await simulateEnhancedStreaming();
208
- }
209
- // Export utilities for reuse
210
- export { createApiHandler, createEnhancedApiHandler, createReadableStreamFromGenerator, streamEventsToAISDK, streamEventsToAISDKWithTools, };
211
- if (import.meta.url === `file://${process.argv[1]}`) {
212
- runAllExamples().catch(console.error);
213
- }
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"airbnb_use.d.ts","sourceRoot":"","sources":["../../examples/airbnb_use.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -1,43 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"blender_use.d.ts","sourceRoot":"","sources":["../../examples/blender_use.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -1,39 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser_use.d.ts","sourceRoot":"","sources":["../../examples/browser_use.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}