mcp-use 0.2.0 → 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 (97) 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 +5 -46
  23. package/dist/src/browser.d.ts.map +1 -1
  24. package/dist/src/browser.js +9 -75
  25. package/dist/src/oauth-helper.d.ts +2 -12
  26. package/dist/src/oauth-helper.d.ts.map +1 -1
  27. package/dist/src/react/index.cjs +986 -0
  28. package/dist/src/react/index.d.ts +9 -0
  29. package/dist/src/react/index.d.ts.map +1 -0
  30. package/dist/src/react/index.js +11 -0
  31. package/dist/src/react/types.d.ts +139 -0
  32. package/dist/src/react/types.d.ts.map +1 -0
  33. package/dist/src/react/useMcp.d.ts +3 -0
  34. package/dist/src/react/useMcp.d.ts.map +1 -0
  35. package/dist/src/server/index.cjs +566 -0
  36. package/dist/src/server/index.d.ts +3 -0
  37. package/dist/src/server/index.d.ts.map +1 -0
  38. package/dist/src/server/index.js +9 -0
  39. package/dist/src/server/logging.d.ts +16 -0
  40. package/dist/src/server/logging.d.ts.map +1 -0
  41. package/dist/src/server/mcp-server.d.ts +282 -0
  42. package/dist/src/server/mcp-server.d.ts.map +1 -0
  43. package/dist/src/server/types.d.ts +47 -0
  44. package/dist/src/server/types.d.ts.map +1 -0
  45. package/dist/src/utils/assert.d.ts +8 -0
  46. package/dist/src/utils/assert.d.ts.map +1 -0
  47. package/dist/tsconfig.tsbuildinfo +1 -0
  48. package/package.json +67 -40
  49. package/dist/src/adapters/base.js +0 -124
  50. package/dist/src/adapters/index.js +0 -2
  51. package/dist/src/adapters/langchain_adapter.js +0 -49
  52. package/dist/src/agents/base.js +0 -9
  53. package/dist/src/agents/index.js +0 -3
  54. package/dist/src/agents/mcp_agent.js +0 -1002
  55. package/dist/src/agents/prompts/system_prompt_builder.js +0 -40
  56. package/dist/src/agents/prompts/templates.js +0 -39
  57. package/dist/src/agents/remote.js +0 -264
  58. package/dist/src/agents/utils/ai_sdk.js +0 -62
  59. package/dist/src/agents/utils/index.js +0 -1
  60. package/dist/src/client/base.js +0 -119
  61. package/dist/src/client.js +0 -50
  62. package/dist/src/config.js +0 -34
  63. package/dist/src/connectors/base.js +0 -143
  64. package/dist/src/connectors/http.js +0 -150
  65. package/dist/src/connectors/index.js +0 -4
  66. package/dist/src/connectors/stdio.js +0 -68
  67. package/dist/src/connectors/websocket.js +0 -157
  68. package/dist/src/logging.js +0 -232
  69. package/dist/src/managers/index.js +0 -2
  70. package/dist/src/managers/server_manager.js +0 -106
  71. package/dist/src/managers/tools/acquire_active_mcp_server.js +0 -17
  72. package/dist/src/managers/tools/add_server_from_config.js +0 -40
  73. package/dist/src/managers/tools/base.js +0 -17
  74. package/dist/src/managers/tools/connect_mcp_server.js +0 -46
  75. package/dist/src/managers/tools/index.js +0 -5
  76. package/dist/src/managers/tools/list_mcp_servers.js +0 -33
  77. package/dist/src/managers/tools/release_mcp_server_connection.js +0 -19
  78. package/dist/src/oauth-helper.js +0 -427
  79. package/dist/src/observability/index.js +0 -12
  80. package/dist/src/observability/langfuse.js +0 -211
  81. package/dist/src/observability/manager.js +0 -199
  82. package/dist/src/observability/types.js +0 -4
  83. package/dist/src/session.js +0 -23
  84. package/dist/src/task_managers/base.js +0 -127
  85. package/dist/src/task_managers/index.js +0 -5
  86. package/dist/src/task_managers/sse.js +0 -43
  87. package/dist/src/task_managers/stdio.js +0 -51
  88. package/dist/src/task_managers/streamable_http.js +0 -50
  89. package/dist/src/task_managers/websocket.js +0 -67
  90. package/dist/src/telemetry/events.js +0 -44
  91. package/dist/src/telemetry/index.js +0 -8
  92. package/dist/src/telemetry/telemetry.js +0 -324
  93. package/dist/src/telemetry/utils.js +0 -39
  94. package/dist/tests/ai_sdk_compatibility.test.js +0 -214
  95. package/dist/tests/stream_events.test.js +0 -307
  96. package/dist/tests/stream_events_simple.test.js +0 -179
  97. 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.2.0",
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",
@@ -34,6 +32,14 @@
34
32
  "./browser": {
35
33
  "types": "./dist/src/browser.d.ts",
36
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"
37
43
  }
38
44
  },
39
45
  "main": "./dist/index.js",
@@ -46,46 +52,27 @@
46
52
  "node": ">=22.0.0"
47
53
  },
48
54
  "publishConfig": {
49
- "registry": "https://registry.npmjs.org"
50
- },
51
- "scripts": {
52
- "build": "rm -rf dist && tsc",
53
- "lint": "eslint",
54
- "lint:fix": "eslint --fix",
55
- "test": "vitest",
56
- "test:run": "vitest run",
57
- "test:simple": "vitest run tests/stream_events_simple.test.ts",
58
- "test:integration": "vitest run tests/stream_events.test.ts",
59
- "watch": "tsc --watch",
60
- "start": "node dist/index.js",
61
- "prepublishOnly": "npm run build",
62
- "fmt": "eslint --fix",
63
- "release": "npm version patch --tag-version-prefix=v && git push --follow-tags",
64
- "release:minor": "npm version minor --tag-version-prefix=v && git push --follow-tags",
65
- "release:major": "npm version major --tag-version-prefix=v && git push --follow-tags",
66
- "prepare": "husky",
67
- "example:airbnb": "npm run build && node dist/examples/airbnb_use.js",
68
- "example:browser": "npm run build && node dist/examples/browser_use.js",
69
- "example:chat": "npm run build && node dist/examples/chat_example.js",
70
- "example:stream": "npm run build && node dist/examples/stream_example.js",
71
- "example:stream_events": "npm run build && node dist/examples/stream_events_example.js",
72
- "example:ai_sdk": "npm run build && node dist/examples/ai_sdk_example.js",
73
- "example:filesystem": "npm run build && node dist/examples/filesystem_use.js",
74
- "example:http": "npm run build && node dist/examples/http_example.js",
75
- "example:everything": "npm run build && node dist/examples/mcp_everything.js",
76
- "example:multi": "npm run build && node dist/examples/multi_server_example.js",
77
- "example:sandbox": "npm run build && node dist/examples/sandbox_everything.js",
78
- "example:oauth": "npm run build && node dist/examples/simple_oauth_example.js",
79
- "example:blender": "npm run build && node dist/examples/blender_use.js",
80
- "example:add_server": "npm run build && node dist/examples/add_server_tool.js",
81
- "example:structured": "npm run build && node dist/examples/structured_output.js",
82
- "example:observability": "npm run build && node dist/examples/observability.js"
55
+ "registry": "https://registry.npmjs.org",
56
+ "access": "public"
83
57
  },
84
58
  "peerDependencies": {
59
+ "@mcp-use/inspector": "^0.2.1",
60
+ "cors": "^2.8.5",
61
+ "express": "^4.18.2",
85
62
  "langfuse": "^3.32.0",
86
- "langfuse-langchain": "^3.38.4"
63
+ "langfuse-langchain": "^3.38.4",
64
+ "react": "^18.0.0"
87
65
  },
88
66
  "peerDependenciesMeta": {
67
+ "@mcp-use/inspector": {
68
+ "optional": true
69
+ },
70
+ "cors": {
71
+ "optional": true
72
+ },
73
+ "express": {
74
+ "optional": true
75
+ },
89
76
  "langfuse": {
90
77
  "optional": true
91
78
  },
@@ -98,13 +85,18 @@
98
85
  "@langchain/anthropic": "^0.3.26",
99
86
  "@langchain/core": "^0.3.72",
100
87
  "@langchain/openai": "^0.6.9",
88
+ "@mcp-ui/server": "^5.11.0",
101
89
  "@modelcontextprotocol/sdk": "1.12.1",
102
90
  "@scarf/scarf": "^1.4.0",
103
91
  "ai": "^4.3.19",
92
+ "commander": "^14.0.1",
104
93
  "dotenv": "^16.5.0",
105
94
  "langchain": "^0.3.27",
106
95
  "lodash-es": "^4.17.21",
107
96
  "posthog-node": "^5.1.1",
97
+ "strict-url-sanitise": "^0.0.1",
98
+ "ts-node": "^10.9.2",
99
+ "tsx": "^4.20.6",
108
100
  "uuid": "^11.1.0",
109
101
  "winston": "^3.17.0",
110
102
  "winston-transport-browserconsole": "^1.0.5",
@@ -114,13 +106,19 @@
114
106
  },
115
107
  "devDependencies": {
116
108
  "@antfu/eslint-config": "^4.13.2",
109
+ "@types/cors": "^2.8.17",
110
+ "@types/express": "^4.17.21",
117
111
  "@types/lodash-es": "^4.17.12",
118
112
  "@types/node": "^20.19.8",
113
+ "@types/react": "^19.2.2",
119
114
  "@types/ws": "^8.18.1",
115
+ "cors": "^2.8.5",
120
116
  "eslint": "^9.28.0",
121
117
  "eslint-plugin-format": "^1.0.1",
118
+ "express": "^4.18.2",
122
119
  "husky": "^9.1.7",
123
120
  "lint-staged": "^15.2.11",
121
+ "react": "^19.2.0",
124
122
  "typescript": "^5.8.3",
125
123
  "vitest": "^2.1.9"
126
124
  },
@@ -133,5 +131,34 @@
133
131
  "eslint --fix",
134
132
  "eslint"
135
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"
136
163
  }
137
- }
164
+ }
@@ -1,124 +0,0 @@
1
- import { logger } from '../logging.js';
2
- /**
3
- * Abstract base class for converting MCP tools to other framework formats.
4
- *
5
- * This class defines the common interface that all adapter implementations
6
- * should follow to ensure consistency across different frameworks.
7
- */
8
- export class BaseAdapter {
9
- /**
10
- * List of tool names that should not be available.
11
- */
12
- disallowedTools;
13
- /**
14
- * Internal cache that maps a connector instance to the list of tools
15
- * generated for it.
16
- */
17
- connectorToolMap = new Map();
18
- constructor(disallowedTools) {
19
- this.disallowedTools = disallowedTools ?? [];
20
- }
21
- /**
22
- * Create tools from an MCPClient instance.
23
- *
24
- * This is the recommended way to create tools from an MCPClient, as it handles
25
- * session creation and connector extraction automatically.
26
- *
27
- * @param client The MCPClient to extract tools from.
28
- * @param disallowedTools Optional list of tool names to exclude.
29
- * @returns A promise that resolves with a list of converted tools.
30
- */
31
- static async createTools(client, disallowedTools) {
32
- // Create the adapter
33
- const adapter = new this(disallowedTools);
34
- // Ensure we have active sessions
35
- if (!client.activeSessions || Object.keys(client.activeSessions).length === 0) {
36
- logger.info('No active sessions found, creating new ones...');
37
- await client.createAllSessions();
38
- }
39
- // Get all active sessions
40
- const sessions = client.getAllActiveSessions();
41
- // Extract connectors from sessions
42
- const connectors = Object.values(sessions).map(session => session.connector);
43
- // Create tools from connectors
44
- return adapter.createToolsFromConnectors(connectors);
45
- }
46
- /**
47
- * Dynamically load tools for a specific connector.
48
- *
49
- * @param connector The connector to load tools for.
50
- * @returns The list of tools that were loaded in the target framework's format.
51
- */
52
- async loadToolsForConnector(connector) {
53
- // Return cached tools if we already processed this connector
54
- if (this.connectorToolMap.has(connector)) {
55
- const cached = this.connectorToolMap.get(connector);
56
- logger.debug(`Returning ${cached.length} existing tools for connector`);
57
- return cached;
58
- }
59
- const connectorTools = [];
60
- // Make sure the connector is initialized and has tools
61
- const success = await this.ensureConnectorInitialized(connector);
62
- if (!success) {
63
- return [];
64
- }
65
- // Convert and collect tools
66
- for (const tool of connector.tools) {
67
- const converted = this.convertTool(tool, connector);
68
- if (converted) {
69
- connectorTools.push(converted);
70
- }
71
- }
72
- // Cache the tools for this connector
73
- this.connectorToolMap.set(connector, connectorTools);
74
- // Log for debugging purposes
75
- logger.debug(`Loaded ${connectorTools.length} new tools for connector: ${connectorTools
76
- .map((t) => t?.name ?? String(t))
77
- .join(', ')}`);
78
- return connectorTools;
79
- }
80
- /**
81
- * Create tools from MCP tools in all provided connectors.
82
- *
83
- * @param connectors List of MCP connectors to create tools from.
84
- * @returns A promise that resolves with all converted tools.
85
- */
86
- async createToolsFromConnectors(connectors) {
87
- const tools = [];
88
- for (const connector of connectors) {
89
- const connectorTools = await this.loadToolsForConnector(connector);
90
- tools.push(...connectorTools);
91
- }
92
- logger.debug(`Available tools: ${tools.length}`);
93
- return tools;
94
- }
95
- /**
96
- * Check if a connector is initialized and has tools.
97
- *
98
- * @param connector The connector to check.
99
- * @returns True if the connector is initialized and has tools, false otherwise.
100
- */
101
- checkConnectorInitialized(connector) {
102
- return Boolean(connector.tools && connector.tools.length);
103
- }
104
- /**
105
- * Ensure a connector is initialized.
106
- *
107
- * @param connector The connector to initialize.
108
- * @returns True if initialization succeeded, false otherwise.
109
- */
110
- async ensureConnectorInitialized(connector) {
111
- if (!this.checkConnectorInitialized(connector)) {
112
- logger.debug('Connector doesn\'t have tools, initializing it');
113
- try {
114
- await connector.initialize();
115
- return true;
116
- }
117
- catch (err) {
118
- logger.error(`Error initializing connector: ${err}`);
119
- return false;
120
- }
121
- }
122
- return true;
123
- }
124
- }
@@ -1,2 +0,0 @@
1
- export { BaseAdapter } from './base.js';
2
- export { LangChainAdapter } from './langchain_adapter.js';
@@ -1,49 +0,0 @@
1
- import { JSONSchemaToZod } from '@dmitryrechkin/json-schema-to-zod';
2
- import { DynamicStructuredTool } from '@langchain/core/tools';
3
- import { z } from 'zod';
4
- import { logger } from '../logging.js';
5
- import { BaseAdapter } from './base.js';
6
- function schemaToZod(schema) {
7
- try {
8
- return JSONSchemaToZod.convert(schema);
9
- }
10
- catch (err) {
11
- logger.warn(`Failed to convert JSON schema to Zod: ${err}`);
12
- return z.any();
13
- }
14
- }
15
- export class LangChainAdapter extends BaseAdapter {
16
- constructor(disallowedTools = []) {
17
- super(disallowedTools);
18
- }
19
- /**
20
- * Convert a single MCP tool specification into a LangChainJS structured tool.
21
- */
22
- convertTool(mcpTool, connector) {
23
- // Filter out disallowed tools early.
24
- if (this.disallowedTools.includes(mcpTool.name)) {
25
- return null;
26
- }
27
- // Derive a strict Zod schema for the tool's arguments.
28
- const argsSchema = mcpTool.inputSchema
29
- ? schemaToZod(mcpTool.inputSchema)
30
- : z.object({}).optional();
31
- const tool = new DynamicStructuredTool({
32
- name: mcpTool.name ?? 'NO NAME',
33
- description: mcpTool.description ?? '', // Blank is acceptable but discouraged.
34
- schema: argsSchema,
35
- func: async (input) => {
36
- logger.debug(`MCP tool \"${mcpTool.name}\" received input: ${JSON.stringify(input)}`);
37
- try {
38
- const result = await connector.callTool(mcpTool.name, input);
39
- return JSON.stringify(result);
40
- }
41
- catch (err) {
42
- logger.error(`Error executing MCP tool: ${err.message}`);
43
- return `Error executing MCP tool: ${String(err)}`;
44
- }
45
- },
46
- });
47
- return tool;
48
- }
49
- }
@@ -1,9 +0,0 @@
1
- export class BaseAgent {
2
- session;
3
- /**
4
- * @param session MCP session used for tool invocation
5
- */
6
- constructor(session) {
7
- this.session = session;
8
- }
9
- }
@@ -1,3 +0,0 @@
1
- export { BaseAgent } from './base.js';
2
- export { MCPAgent } from './mcp_agent.js';
3
- export { RemoteAgent } from './remote.js';