mcp-use 0.2.0 → 1.0.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 +5 -46
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +9 -75
- package/dist/src/oauth-helper.d.ts +2 -12
- package/dist/src/oauth-helper.d.ts.map +1 -1
- 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 +67 -40
- 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/base.js +0 -119
- package/dist/src/client.js +0 -50
- 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 -232
- 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/oauth-helper.js +0 -427
- 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
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Entry point for the React integration.
|
3
|
+
* Provides the useMcp hook and related types.
|
4
|
+
*/
|
5
|
+
export { useMcp } from './useMcp.js';
|
6
|
+
export type { UseMcpOptions, UseMcpResult } from './types.js';
|
7
|
+
export { onMcpAuthorization } from '../auth/callback.js';
|
8
|
+
export type { Tool, Resource, ResourceTemplate, Prompt } from '@modelcontextprotocol/sdk/types.js';
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAGxD,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAA"}
|
@@ -0,0 +1,139 @@
|
|
1
|
+
import type { Tool, Resource, ResourceTemplate, Prompt } from '@modelcontextprotocol/sdk/types.js';
|
2
|
+
export type UseMcpOptions = {
|
3
|
+
/** The /sse URL of your remote MCP server */
|
4
|
+
url?: string;
|
5
|
+
/** Enable/disable the connection (similar to TanStack Query). When false, no connection will be attempted (default: true) */
|
6
|
+
enabled?: boolean;
|
7
|
+
/** OAuth client name for registration (if dynamic registration is used) */
|
8
|
+
clientName?: string;
|
9
|
+
/** OAuth client URI for registration (if dynamic registration is used) */
|
10
|
+
clientUri?: string;
|
11
|
+
/** Custom callback URL for OAuth redirect (defaults to /oauth/callback on the current origin) */
|
12
|
+
callbackUrl?: string;
|
13
|
+
/** Storage key prefix for OAuth data in localStorage (defaults to "mcp:auth") */
|
14
|
+
storageKeyPrefix?: string;
|
15
|
+
/** Custom configuration for the MCP client identity */
|
16
|
+
clientConfig?: {
|
17
|
+
name?: string;
|
18
|
+
version?: string;
|
19
|
+
};
|
20
|
+
/** Custom headers that can be used to bypass auth */
|
21
|
+
customHeaders?: Record<string, string>;
|
22
|
+
/** Whether to enable verbose debug logging to the console and the log state */
|
23
|
+
debug?: boolean;
|
24
|
+
/** Auto retry connection if initial connection fails, with delay in ms (default: false) */
|
25
|
+
autoRetry?: boolean | number;
|
26
|
+
/** Auto reconnect if an established connection is lost, with delay in ms (default: 3000) */
|
27
|
+
autoReconnect?: boolean | number;
|
28
|
+
/** Popup window features string (dimensions and behavior) for OAuth */
|
29
|
+
popupFeatures?: string;
|
30
|
+
/** Transport type preference: 'auto' (HTTP with SSE fallback), 'http' (HTTP only), 'sse' (SSE only) */
|
31
|
+
transportType?: 'auto' | 'http' | 'sse';
|
32
|
+
/** Prevent automatic authentication popup on initial connection (default: false) */
|
33
|
+
preventAutoAuth?: boolean;
|
34
|
+
/**
|
35
|
+
* Callback function that is invoked just before the authentication popup window is opened.
|
36
|
+
* @param url The URL that will be opened in the popup.
|
37
|
+
* @param features The features string for the popup window.
|
38
|
+
*/
|
39
|
+
onPopupWindow?: (url: string, features: string, window: globalThis.Window | null) => void;
|
40
|
+
};
|
41
|
+
export type UseMcpResult = {
|
42
|
+
/** List of tools available from the connected MCP server */
|
43
|
+
tools: Tool[];
|
44
|
+
/** List of resources available from the connected MCP server */
|
45
|
+
resources: Resource[];
|
46
|
+
/** List of resource templates available from the connected MCP server */
|
47
|
+
resourceTemplates: ResourceTemplate[];
|
48
|
+
/** List of prompts available from the connected MCP server */
|
49
|
+
prompts: Prompt[];
|
50
|
+
/**
|
51
|
+
* The current state of the MCP connection:
|
52
|
+
* - 'discovering': Checking server existence and capabilities (including auth requirements).
|
53
|
+
* - 'pending_auth': Authentication is required but auto-popup was prevented. User action needed.
|
54
|
+
* - 'authenticating': Authentication is required and the process (e.g., popup) has been initiated.
|
55
|
+
* - 'connecting': Establishing the SSE connection to the server.
|
56
|
+
* - 'loading': Connected; loading resources like the tool list.
|
57
|
+
* - 'ready': Connected and ready for tool calls.
|
58
|
+
* - 'failed': Connection or authentication failed. Check the `error` property.
|
59
|
+
*/
|
60
|
+
state: 'discovering' | 'pending_auth' | 'authenticating' | 'connecting' | 'loading' | 'ready' | 'failed';
|
61
|
+
/** If the state is 'failed', this provides the error message */
|
62
|
+
error?: string;
|
63
|
+
/**
|
64
|
+
* If authentication requires user interaction (e.g., popup was blocked),
|
65
|
+
* this URL can be presented to the user to complete authentication manually in a new tab.
|
66
|
+
*/
|
67
|
+
authUrl?: string;
|
68
|
+
/** Array of internal log messages (useful for debugging) */
|
69
|
+
log: {
|
70
|
+
level: 'debug' | 'info' | 'warn' | 'error';
|
71
|
+
message: string;
|
72
|
+
timestamp: number;
|
73
|
+
}[];
|
74
|
+
/**
|
75
|
+
* Function to call a tool on the MCP server.
|
76
|
+
* @param name The name of the tool to call.
|
77
|
+
* @param args Optional arguments for the tool.
|
78
|
+
* @returns A promise that resolves with the tool's result.
|
79
|
+
* @throws If the client is not in the 'ready' state or the call fails.
|
80
|
+
*/
|
81
|
+
callTool: (name: string, args?: Record<string, unknown>) => Promise<any>;
|
82
|
+
/**
|
83
|
+
* Function to list resources from the MCP server.
|
84
|
+
* @returns A promise that resolves when resources are refreshed.
|
85
|
+
* @throws If the client is not in the 'ready' state.
|
86
|
+
*/
|
87
|
+
listResources: () => Promise<void>;
|
88
|
+
/**
|
89
|
+
* Function to read a resource from the MCP server.
|
90
|
+
* @param uri The URI of the resource to read.
|
91
|
+
* @returns A promise that resolves with the resource contents.
|
92
|
+
* @throws If the client is not in the 'ready' state or the read fails.
|
93
|
+
*/
|
94
|
+
readResource: (uri: string) => Promise<{
|
95
|
+
contents: Array<{
|
96
|
+
uri: string;
|
97
|
+
mimeType?: string;
|
98
|
+
text?: string;
|
99
|
+
blob?: string;
|
100
|
+
}>;
|
101
|
+
}>;
|
102
|
+
/**
|
103
|
+
* Function to list prompts from the MCP server.
|
104
|
+
* @returns A promise that resolves when prompts are refreshed.
|
105
|
+
* @throws If the client is not in the 'ready' state.
|
106
|
+
*/
|
107
|
+
listPrompts: () => Promise<void>;
|
108
|
+
/**
|
109
|
+
* Function to get a specific prompt from the MCP server.
|
110
|
+
* @param name The name of the prompt to get.
|
111
|
+
* @param args Optional arguments for the prompt.
|
112
|
+
* @returns A promise that resolves with the prompt messages.
|
113
|
+
* @throws If the client is not in the 'ready' state or the get fails.
|
114
|
+
*/
|
115
|
+
getPrompt: (name: string, args?: Record<string, string>) => Promise<{
|
116
|
+
messages: Array<{
|
117
|
+
role: 'user' | 'assistant';
|
118
|
+
content: {
|
119
|
+
type: string;
|
120
|
+
text?: string;
|
121
|
+
[key: string]: any;
|
122
|
+
};
|
123
|
+
}>;
|
124
|
+
}>;
|
125
|
+
/** Manually attempts to reconnect if the state is 'failed'. */
|
126
|
+
retry: () => void;
|
127
|
+
/** Disconnects the client from the MCP server. */
|
128
|
+
disconnect: () => void;
|
129
|
+
/**
|
130
|
+
* Manually triggers the authentication process. Useful if the initial attempt failed
|
131
|
+
* due to a blocked popup, allowing the user to initiate it via a button click.
|
132
|
+
* @returns A promise that resolves with the authorization URL opened (or intended to be opened),
|
133
|
+
* or undefined if auth cannot be started.
|
134
|
+
*/
|
135
|
+
authenticate: () => void;
|
136
|
+
/** Clears all stored authentication data (tokens, client info, etc.) for this server URL from localStorage. */
|
137
|
+
clearStorage: () => void;
|
138
|
+
};
|
139
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAA;AAElG,MAAM,MAAM,aAAa,GAAG;IAC1B,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,6HAA6H;IAC7H,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,iGAAiG;IACjG,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,iFAAiF;IACjF,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,uDAAuD;IACvD,YAAY,CAAC,EAAE;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB,CAAA;IACD,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACtC,+EAA+E;IAC/E,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,2FAA2F;IAC3F,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,4FAA4F;IAC5F,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAChC,uEAAuE;IACvE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,uGAAuG;IACvG,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAA;IACvC,oFAAoF;IACpF,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAA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