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.
- package/dist/chunk-2HFIPY7C.js +429 -0
- package/dist/chunk-4DEFXVWT.js +680 -0
- package/dist/chunk-JXLQRAW2.js +532 -0
- package/dist/chunk-SHUYVCID.js +6 -0
- package/dist/chunk-YUSC6R6V.js +299 -0
- package/dist/index.cjs +5762 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3767 -22
- package/dist/langfuse-YA2S23SM.js +13 -0
- package/dist/src/agents/remote.d.ts.map +1 -1
- package/dist/src/agents/utils/ai_sdk.d.ts.map +1 -1
- package/dist/src/auth/browser-provider.d.ts +52 -0
- package/dist/src/auth/browser-provider.d.ts.map +1 -0
- package/dist/src/auth/callback.d.ts +6 -0
- package/dist/src/auth/callback.d.ts.map +1 -0
- package/dist/src/auth/index.d.ts +7 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/types.d.ts +18 -0
- package/dist/src/auth/types.d.ts.map +1 -0
- package/dist/src/browser.cjs +323 -0
- package/dist/src/browser.d.ts +8 -0
- package/dist/src/browser.d.ts.map +1 -0
- package/dist/src/browser.js +9 -0
- package/dist/src/client/base.d.ts +32 -0
- package/dist/src/client/base.d.ts.map +1 -0
- package/dist/src/client.d.ts +19 -16
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/logging.d.ts +1 -1
- package/dist/src/logging.d.ts.map +1 -1
- package/dist/src/oauth-helper.d.ts +125 -0
- package/dist/src/oauth-helper.d.ts.map +1 -0
- package/dist/src/react/index.cjs +986 -0
- package/dist/src/react/index.d.ts +9 -0
- package/dist/src/react/index.d.ts.map +1 -0
- package/dist/src/react/index.js +11 -0
- package/dist/src/react/types.d.ts +139 -0
- package/dist/src/react/types.d.ts.map +1 -0
- package/dist/src/react/useMcp.d.ts +3 -0
- package/dist/src/react/useMcp.d.ts.map +1 -0
- package/dist/src/server/index.cjs +566 -0
- package/dist/src/server/index.d.ts +3 -0
- package/dist/src/server/index.d.ts.map +1 -0
- package/dist/src/server/index.js +9 -0
- package/dist/src/server/logging.d.ts +16 -0
- package/dist/src/server/logging.d.ts.map +1 -0
- package/dist/src/server/mcp-server.d.ts +282 -0
- package/dist/src/server/mcp-server.d.ts.map +1 -0
- package/dist/src/server/types.d.ts +47 -0
- package/dist/src/server/types.d.ts.map +1 -0
- package/dist/src/utils/assert.d.ts +8 -0
- package/dist/src/utils/assert.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +72 -40
- package/dist/examples/add_server_tool.d.ts +0 -8
- package/dist/examples/add_server_tool.d.ts.map +0 -1
- package/dist/examples/add_server_tool.js +0 -79
- package/dist/examples/ai_sdk_example.d.ts +0 -23
- package/dist/examples/ai_sdk_example.d.ts.map +0 -1
- package/dist/examples/ai_sdk_example.js +0 -213
- package/dist/examples/airbnb_use.d.ts +0 -10
- package/dist/examples/airbnb_use.d.ts.map +0 -1
- package/dist/examples/airbnb_use.js +0 -43
- package/dist/examples/blender_use.d.ts +0 -15
- package/dist/examples/blender_use.d.ts.map +0 -1
- package/dist/examples/blender_use.js +0 -39
- package/dist/examples/browser_use.d.ts +0 -10
- package/dist/examples/browser_use.d.ts.map +0 -1
- package/dist/examples/browser_use.js +0 -46
- package/dist/examples/chat_example.d.ts +0 -10
- package/dist/examples/chat_example.d.ts.map +0 -1
- package/dist/examples/chat_example.js +0 -86
- package/dist/examples/filesystem_use.d.ts +0 -11
- package/dist/examples/filesystem_use.d.ts.map +0 -1
- package/dist/examples/filesystem_use.js +0 -43
- package/dist/examples/http_example.d.ts +0 -18
- package/dist/examples/http_example.d.ts.map +0 -1
- package/dist/examples/http_example.js +0 -37
- package/dist/examples/mcp_everything.d.ts +0 -6
- package/dist/examples/mcp_everything.d.ts.map +0 -1
- package/dist/examples/mcp_everything.js +0 -25
- package/dist/examples/multi_server_example.d.ts +0 -10
- package/dist/examples/multi_server_example.d.ts.map +0 -1
- package/dist/examples/multi_server_example.js +0 -51
- package/dist/examples/observability.d.ts +0 -6
- package/dist/examples/observability.d.ts.map +0 -1
- package/dist/examples/observability.js +0 -50
- package/dist/examples/stream_example.d.ts +0 -12
- package/dist/examples/stream_example.d.ts.map +0 -1
- package/dist/examples/stream_example.js +0 -198
- package/dist/examples/structured_output.d.ts +0 -9
- package/dist/examples/structured_output.d.ts.map +0 -1
- package/dist/examples/structured_output.js +0 -95
- package/dist/src/adapters/base.js +0 -124
- package/dist/src/adapters/index.js +0 -2
- package/dist/src/adapters/langchain_adapter.js +0 -49
- package/dist/src/agents/base.js +0 -9
- package/dist/src/agents/index.js +0 -3
- package/dist/src/agents/mcp_agent.js +0 -1002
- package/dist/src/agents/prompts/system_prompt_builder.js +0 -40
- package/dist/src/agents/prompts/templates.js +0 -39
- package/dist/src/agents/remote.js +0 -264
- package/dist/src/agents/utils/ai_sdk.js +0 -62
- package/dist/src/agents/utils/index.js +0 -1
- package/dist/src/client.js +0 -133
- package/dist/src/config.js +0 -34
- package/dist/src/connectors/base.js +0 -143
- package/dist/src/connectors/http.js +0 -150
- package/dist/src/connectors/index.js +0 -4
- package/dist/src/connectors/stdio.js +0 -68
- package/dist/src/connectors/websocket.js +0 -157
- package/dist/src/logging.js +0 -217
- package/dist/src/managers/index.js +0 -2
- package/dist/src/managers/server_manager.js +0 -106
- package/dist/src/managers/tools/acquire_active_mcp_server.js +0 -17
- package/dist/src/managers/tools/add_server_from_config.js +0 -40
- package/dist/src/managers/tools/base.js +0 -17
- package/dist/src/managers/tools/connect_mcp_server.js +0 -46
- package/dist/src/managers/tools/index.js +0 -5
- package/dist/src/managers/tools/list_mcp_servers.js +0 -33
- package/dist/src/managers/tools/release_mcp_server_connection.js +0 -19
- package/dist/src/observability/index.js +0 -12
- package/dist/src/observability/langfuse.js +0 -211
- package/dist/src/observability/manager.js +0 -199
- package/dist/src/observability/types.js +0 -4
- package/dist/src/session.js +0 -23
- package/dist/src/task_managers/base.js +0 -127
- package/dist/src/task_managers/index.js +0 -5
- package/dist/src/task_managers/sse.js +0 -43
- package/dist/src/task_managers/stdio.js +0 -51
- package/dist/src/task_managers/streamable_http.js +0 -50
- package/dist/src/task_managers/websocket.js +0 -67
- package/dist/src/telemetry/events.js +0 -44
- package/dist/src/telemetry/index.js +0 -8
- package/dist/src/telemetry/telemetry.js +0 -324
- package/dist/src/telemetry/utils.js +0 -39
- package/dist/tests/ai_sdk_compatibility.test.js +0 -214
- package/dist/tests/stream_events.test.js +0 -307
- package/dist/tests/stream_events_simple.test.js +0 -179
- package/dist/vitest.config.js +0 -21
@@ -1,95 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Structured Output Example - City Research with Playwright
|
3
|
-
*
|
4
|
-
* This example demonstrates intelligent structured output by researching Padova, Italy.
|
5
|
-
* The agent becomes schema-aware and will intelligently retry to gather missing
|
6
|
-
* information until all required fields can be populated.
|
7
|
-
*/
|
8
|
-
import { ChatOpenAI } from '@langchain/openai';
|
9
|
-
import { config } from 'dotenv';
|
10
|
-
import { z } from 'zod';
|
11
|
-
import { MCPAgent, MCPClient } from '../index.js';
|
12
|
-
// Load environment variables from .env file
|
13
|
-
config();
|
14
|
-
// Define the structured output schema using Zod
|
15
|
-
const CityInfoSchema = z.object({
|
16
|
-
name: z.string().describe('Official name of the city'),
|
17
|
-
country: z.string().describe('Country where the city is located'),
|
18
|
-
region: z.string().describe('Region or state within the country'),
|
19
|
-
population: z.number().describe('Current population count'),
|
20
|
-
area_km2: z.number().describe('Area in square kilometers'),
|
21
|
-
foundation_date: z.string().describe('When the city was founded (approximate year or period)'),
|
22
|
-
mayor: z.string().describe('Current mayor or city leader'),
|
23
|
-
famous_landmarks: z.array(z.string()).describe('List of famous landmarks, monuments, or attractions'),
|
24
|
-
universities: z.array(z.string()).describe('List of major universities or educational institutions'),
|
25
|
-
economy_sectors: z.array(z.string()).describe('Main economic sectors or industries'),
|
26
|
-
sister_cities: z.array(z.string()).describe('Twin cities or sister cities partnerships'),
|
27
|
-
historical_significance: z.string().describe('Brief description of historical importance'),
|
28
|
-
climate_type: z.string().nullable().describe('Type of climate (e.g., Mediterranean, Continental)'),
|
29
|
-
elevation_meters: z.number().nullable().describe('Elevation above sea level in meters'),
|
30
|
-
});
|
31
|
-
async function main() {
|
32
|
-
const mcpConfig = {
|
33
|
-
mcpServers: {
|
34
|
-
playwright: {
|
35
|
-
command: 'npx',
|
36
|
-
args: ['@playwright/mcp@latest'],
|
37
|
-
env: {
|
38
|
-
DISPLAY: ':1',
|
39
|
-
},
|
40
|
-
},
|
41
|
-
},
|
42
|
-
};
|
43
|
-
const client = new MCPClient(mcpConfig);
|
44
|
-
const llm = new ChatOpenAI({ model: 'gpt-4o' });
|
45
|
-
const agent = new MCPAgent({ llm, client, maxSteps: 50, memoryEnabled: true });
|
46
|
-
try {
|
47
|
-
// Use structured output with intelligent retry
|
48
|
-
// The agent will:
|
49
|
-
// 1. Know exactly what information it needs to collect
|
50
|
-
// 2. Attempt structured output at finish points
|
51
|
-
// 3. Continue execution if required information is missing
|
52
|
-
// 4. Only finish when all required fields can be populated
|
53
|
-
const result = await agent.run(`
|
54
|
-
Research comprehensive information about the city of Padova (also known as Padua) in Italy.
|
55
|
-
|
56
|
-
Visit multiple reliable sources like Wikipedia, official city websites, tourism sites,
|
57
|
-
and university websites to gather detailed information including demographics, history,
|
58
|
-
governance, education, economy, landmarks, and international relationships.
|
59
|
-
`, 50, // maxSteps
|
60
|
-
true, // manageConnector
|
61
|
-
[], // externalHistory
|
62
|
-
CityInfoSchema);
|
63
|
-
// Now you have strongly-typed, validated data!
|
64
|
-
console.log(`Name: ${result.name}`);
|
65
|
-
console.log(`Country: ${result.country}`);
|
66
|
-
console.log(`Region: ${result.region}`);
|
67
|
-
console.log(`Population: ${result.population.toLocaleString()}`);
|
68
|
-
console.log(`Area: ${result.area_km2} km²`);
|
69
|
-
console.log(`Foundation: ${result.foundation_date}`);
|
70
|
-
console.log(`Mayor: ${result.mayor}`);
|
71
|
-
console.log(`Universities: ${result.universities.join(', ')}`);
|
72
|
-
console.log(`Economy: ${result.economy_sectors.join(', ')}`);
|
73
|
-
console.log(`Landmarks: ${result.famous_landmarks.join(', ')}`);
|
74
|
-
console.log(`Sister Cities: ${result.sister_cities.length > 0 ? result.sister_cities.join(', ') : 'None'}`);
|
75
|
-
console.log(`Historical Significance: ${result.historical_significance}`);
|
76
|
-
if (result.climate_type) {
|
77
|
-
console.log(`Climate: ${result.climate_type}`);
|
78
|
-
}
|
79
|
-
if (result.elevation_meters !== null) {
|
80
|
-
console.log(`Elevation: ${result.elevation_meters} meters`);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
catch (error) {
|
84
|
-
console.error('Error:', error);
|
85
|
-
}
|
86
|
-
finally {
|
87
|
-
await agent.close();
|
88
|
-
}
|
89
|
-
}
|
90
|
-
// Handle unhandled promise rejections
|
91
|
-
process.on('unhandledRejection', (reason, promise) => {
|
92
|
-
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
93
|
-
process.exit(1);
|
94
|
-
});
|
95
|
-
main().catch(console.error);
|
@@ -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,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
|
-
}
|
package/dist/src/agents/base.js
DELETED
package/dist/src/agents/index.js
DELETED