@mcp-use/agent 2.0.0-beta.17 → 2.0.0-beta.19
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/README.md +145 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters/base.d.ts +31 -28
- package/dist/adapters/base.d.ts.map +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/langchain_adapter.d.ts +10 -0
- package/dist/adapters/langchain_adapter.d.ts.map +1 -1
- package/dist/adapters/native_adapter.d.ts +27 -2
- package/dist/adapters/native_adapter.d.ts.map +1 -1
- package/dist/agents/agent_options.d.ts +47 -4
- package/dist/agents/agent_options.d.ts.map +1 -1
- package/dist/agents/display.d.ts.map +1 -1
- package/dist/agents/mcp_agent.d.ts +85 -14
- package/dist/agents/mcp_agent.d.ts.map +1 -1
- package/dist/agents/mcp_agent_langchain.d.ts +103 -38
- package/dist/agents/mcp_agent_langchain.d.ts.map +1 -1
- package/dist/agents/prompts/index.d.ts +7 -0
- package/dist/agents/prompts/index.d.ts.map +1 -1
- package/dist/agents/remote.d.ts +39 -14
- package/dist/agents/remote.d.ts.map +1 -1
- package/dist/agents/run_options.d.ts +15 -0
- package/dist/agents/run_options.d.ts.map +1 -1
- package/dist/agents/types.d.ts +45 -23
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/utils/ai_sdk.d.ts +14 -5
- package/dist/agents/utils/ai_sdk.d.ts.map +1 -1
- package/dist/agents/utils/index.d.ts +1 -1
- package/dist/agents/utils/index.d.ts.map +1 -1
- package/dist/agents/utils/llm_provider.d.ts +31 -23
- package/dist/agents/utils/llm_provider.d.ts.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +101 -22
- package/dist/index.js.map +1 -1
- package/dist/langchain.d.ts +9 -2
- package/dist/langchain.d.ts.map +1 -1
- package/dist/langchain.js +372 -42786
- package/dist/langchain.js.map +1 -1
- package/dist/llm/chat.d.ts +8 -1
- package/dist/llm/chat.d.ts.map +1 -1
- package/dist/llm/messageFormat.d.ts +36 -6
- package/dist/llm/messageFormat.d.ts.map +1 -1
- package/dist/llm/provider_config.d.ts +25 -1
- package/dist/llm/provider_config.d.ts.map +1 -1
- package/dist/llm/providers/ollama/utils.d.ts +22 -0
- package/dist/llm/providers/ollama/utils.d.ts.map +1 -1
- package/dist/llm/providers/openai-chat-completions.d.ts +8 -1
- package/dist/llm/providers/openai-chat-completions.d.ts.map +1 -1
- package/dist/llm/types.d.ts +85 -18
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/managers/server_manager.d.ts +30 -0
- package/dist/managers/server_manager.d.ts.map +1 -1
- package/dist/managers/tools/acquire_active_mcp_server.d.ts +5 -0
- package/dist/managers/tools/acquire_active_mcp_server.d.ts.map +1 -1
- package/dist/managers/tools/add_server_from_config.d.ts +12 -0
- package/dist/managers/tools/add_server_from_config.d.ts.map +1 -1
- package/dist/managers/tools/base.d.ts +7 -0
- package/dist/managers/tools/base.d.ts.map +1 -1
- package/dist/managers/tools/connect_mcp_server.d.ts +9 -0
- package/dist/managers/tools/connect_mcp_server.d.ts.map +1 -1
- package/dist/managers/tools/list_mcp_servers.d.ts +5 -0
- package/dist/managers/tools/list_mcp_servers.d.ts.map +1 -1
- package/dist/managers/tools/release_mcp_server_connection.d.ts +5 -0
- package/dist/managers/tools/release_mcp_server_connection.d.ts.map +1 -1
- package/dist/managers/types.d.ts +9 -0
- package/dist/managers/types.d.ts.map +1 -1
- package/dist/observability/index.d.ts +1 -1
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/manager.d.ts +20 -8
- package/dist/observability/manager.d.ts.map +1 -1
- package/package.json +5 -10
- package/dist/browser-agent.d.ts +0 -9
- package/dist/browser-agent.d.ts.map +0 -1
- package/dist/browser-agent.js +0 -3318
- package/dist/browser-agent.js.map +0 -1
|
@@ -1,53 +1,61 @@
|
|
|
1
1
|
import type { LanguageModel } from "../types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Configuration for LLM instances
|
|
4
|
-
*/
|
|
2
|
+
/** Constructor settings forwarded to a dynamically loaded LangChain model. */
|
|
5
3
|
export interface LLMConfig {
|
|
4
|
+
/** Provider API key. When omitted, the provider environment variable is used. */
|
|
6
5
|
apiKey?: string;
|
|
6
|
+
/** Sampling temperature. */
|
|
7
7
|
temperature?: number;
|
|
8
|
+
/** Maximum number of output tokens. */
|
|
8
9
|
maxTokens?: number;
|
|
10
|
+
/** Nucleus sampling probability. */
|
|
9
11
|
topP?: number;
|
|
12
|
+
/** Additional provider-specific constructor settings. */
|
|
10
13
|
[key: string]: any;
|
|
11
14
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Supported LLM providers
|
|
14
|
-
*/
|
|
15
|
+
/** LangChain providers supported by {@link createLLMFromString}. */
|
|
15
16
|
export type LLMProvider = "openai" | "anthropic" | "google" | "groq";
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* - "openai/gpt-4" -> { provider: "openai", model: "gpt-4" }
|
|
20
|
-
* - "anthropic/claude-sonnet-4-6" -> { provider: "anthropic", model: "claude-sonnet-4-6" }
|
|
21
|
-
* - "google/gemini-pro" -> { provider: "google", model: "gemini-pro" }
|
|
22
|
-
*/
|
|
23
|
-
export declare function parseLLMString(llmString: string): {
|
|
17
|
+
/** Parsed components of a LangChain model identifier. */
|
|
18
|
+
export interface ParsedLLMString {
|
|
19
|
+
/** Normalized provider name. */
|
|
24
20
|
provider: LLMProvider;
|
|
21
|
+
/** Provider-specific model name. */
|
|
25
22
|
model: string;
|
|
26
|
-
}
|
|
23
|
+
}
|
|
27
24
|
/**
|
|
28
|
-
*
|
|
25
|
+
* Parses an LLM identifier in `"provider/model"` format.
|
|
26
|
+
*
|
|
27
|
+
* @param llmString - Provider and model separated by one slash.
|
|
28
|
+
* @returns The normalized provider and model.
|
|
29
|
+
* @throws Error if the format is invalid or the provider is unsupported.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseLLMString(llmString: string): ParsedLLMString;
|
|
32
|
+
/**
|
|
33
|
+
* Dynamically imports and instantiates a LangChain chat model.
|
|
29
34
|
*
|
|
30
35
|
* @param llmString - LLM specification in format "provider/model" (e.g., "openai/gpt-4")
|
|
31
36
|
* @param config - Optional configuration for the LLM (apiKey, temperature, etc.)
|
|
32
|
-
* @returns
|
|
37
|
+
* @returns The instantiated LangChain model.
|
|
38
|
+
* @throws Error if credentials are unavailable, the provider package is not
|
|
39
|
+
* installed, or the model cannot be constructed.
|
|
33
40
|
*
|
|
34
41
|
* @example
|
|
35
|
-
* ```
|
|
42
|
+
* ```ts
|
|
36
43
|
* const llm = await createLLMFromString('openai/gpt-4', { temperature: 0.7 });
|
|
37
44
|
* ```
|
|
38
45
|
*
|
|
39
46
|
* @example
|
|
40
|
-
* ```
|
|
47
|
+
* ```ts
|
|
41
48
|
* const llm = await createLLMFromString('anthropic/claude-sonnet-4-6');
|
|
42
49
|
* ```
|
|
43
50
|
*/
|
|
44
51
|
export declare function createLLMFromString(llmString: string, config?: LLMConfig): Promise<LanguageModel>;
|
|
45
52
|
/**
|
|
46
|
-
*
|
|
53
|
+
* Tests whether an LLM identifier has a supported provider and valid format.
|
|
54
|
+
*
|
|
55
|
+
* @param llmString - Candidate `"provider/model"` identifier.
|
|
56
|
+
* @returns `true` when {@link parseLLMString} accepts the identifier.
|
|
47
57
|
*/
|
|
48
58
|
export declare function isValidLLMString(llmString: string): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Get list of supported providers
|
|
51
|
-
*/
|
|
59
|
+
/** @returns A new array containing every supported LangChain provider. */
|
|
52
60
|
export declare function getSupportedProviders(): LLMProvider[];
|
|
53
61
|
//# sourceMappingURL=llm_provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm_provider.d.ts","sourceRoot":"","sources":["../../../src/agents/utils/llm_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD
|
|
1
|
+
{"version":3,"file":"llm_provider.d.ts","sourceRoot":"","sources":["../../../src/agents/utils/llm_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,8EAA8E;AAC9E,MAAM,WAAW,SAAS;IACxB,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,oEAAoE;AACpE,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;AAErE,yDAAyD;AACzD,MAAM,WAAW,eAAe;IAC9B,gCAAgC;IAChC,QAAQ,EAAE,WAAW,CAAC;IACtB,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;CACf;AAgCD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CA4BjE;AAyCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,aAAa,CAAC,CA8ExB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAO3D;AAED,0EAA0E;AAC1E,wBAAgB,qBAAqB,IAAI,WAAW,EAAE,CAErD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* `@mcp-use/agent` — Native cross-platform MCP agent.
|
|
3
3
|
*
|
|
4
|
-
* Inspector → MCPAgent → loop → raw fetch +
|
|
5
|
-
* LangChain integration lives in
|
|
4
|
+
* Inspector → MCPAgent → loop → raw fetch + `@mcp-use/client`.
|
|
5
|
+
* LangChain integration lives in `@mcp-use/agent/langchain`.
|
|
6
6
|
*/
|
|
7
7
|
export { MCPAgent, convertMessagesToProvider, parseLLMStringToProviderConfig, providerConfigFromOptions, type MCPAgentOptions, type McpConnectionLike, type McpServersInput, type RunOptions, type AgentStep, type ProviderName, type ProviderConfig, type ProviderMessage, type LlmStreamEvent, type TokenUsage, type LLMConfig, } from "./agents/mcp_agent.js";
|
|
8
|
+
export type { BaseMessage, MCPServerConfig } from "./agents/types.js";
|
|
9
|
+
export type { AgentAction } from "./agents/mcp_agent.js";
|
|
10
|
+
export type { NativeLLMConfig } from "./llm/provider_config.js";
|
|
11
|
+
export type { ContentPart, ImageContentPart, LlmDoneEvent, LlmErrorEvent, LlmTextDeltaEvent, LlmToolCallArgsDeltaEvent, LlmToolCallReadyEvent, LlmToolCallStartEvent, LlmToolResultEvent, LlmUsageEvent, ProviderTool, ProviderToolCall, TextContentPart, } from "./llm/types.js";
|
|
8
12
|
export { LlmRequestError } from "./llm/providers/openai-chat-completions.js";
|
|
9
13
|
export { completeChat, completeChat as chat } from "./llm/chat.js";
|
|
14
|
+
export type { InspectorAttachment, InspectorMessageLike, InspectorMessagePart, } from "./llm/messageFormat.js";
|
|
10
15
|
export { buildOllamaApiUrl, DEFAULT_OLLAMA_BASE_URL, normalizeOllamaBaseUrl, OllamaCorsError, } from "./llm/providers/ollama/utils.js";
|
|
11
|
-
export { RemoteAgent } from "./agents/remote.js";
|
|
16
|
+
export { RemoteAgent, type RemoteAgentOptions } from "./agents/remote.js";
|
|
12
17
|
export { PROMPTS } from "./agents/prompts/index.js";
|
|
13
|
-
export { BaseAdapter, NativeAdapter } from "./adapters/index.js";
|
|
18
|
+
export { BaseAdapter, NativeAdapter, type NativeCallToolFn, type NativeToolEntry, } from "./adapters/index.js";
|
|
14
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,QAAQ,EACR,yBAAyB,EACzB,8BAA8B,EAC9B,yBAAyB,EACzB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,SAAS,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,YAAY,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,GAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,QAAQ,EACR,yBAAyB,EACzB,8BAA8B,EAC9B,yBAAyB,EACzB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,SAAS,GACf,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,YAAY,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACnE,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,GAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EACL,WAAW,EACX,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,9 @@ var BaseAdapter = class {
|
|
|
16
16
|
* generated for it.
|
|
17
17
|
*/
|
|
18
18
|
connectorToolMap = /* @__PURE__ */ new Map();
|
|
19
|
+
/**
|
|
20
|
+
* @param disallowedTools - MCP tool names to omit during conversion.
|
|
21
|
+
*/
|
|
19
22
|
constructor(disallowedTools) {
|
|
20
23
|
this.disallowedTools = disallowedTools ?? [];
|
|
21
24
|
}
|
|
@@ -25,9 +28,9 @@ var BaseAdapter = class {
|
|
|
25
28
|
* This is the recommended way to create tools from an MCPClient, as it handles
|
|
26
29
|
* session creation and connector extraction automatically.
|
|
27
30
|
*
|
|
28
|
-
* @param client
|
|
29
|
-
* @param disallowedTools Optional list of tool names to exclude.
|
|
30
|
-
* @returns
|
|
31
|
+
* @param client - The MCPClient to extract tools from.
|
|
32
|
+
* @param disallowedTools - Optional list of tool names to exclude.
|
|
33
|
+
* @returns A promise that resolves with a list of converted tools.
|
|
31
34
|
*/
|
|
32
35
|
static async createTools(client, disallowedTools) {
|
|
33
36
|
const adapter = new this(disallowedTools);
|
|
@@ -44,8 +47,8 @@ var BaseAdapter = class {
|
|
|
44
47
|
/**
|
|
45
48
|
* Dynamically load tools for a specific connector.
|
|
46
49
|
*
|
|
47
|
-
* @param connector The connector to load tools for.
|
|
48
|
-
* @returns
|
|
50
|
+
* @param connector - The connector to load tools for.
|
|
51
|
+
* @returns The list of tools that were loaded in the target framework's format.
|
|
49
52
|
*/
|
|
50
53
|
async loadToolsForConnector(connector) {
|
|
51
54
|
if (this.connectorToolMap.has(connector)) {
|
|
@@ -73,8 +76,8 @@ var BaseAdapter = class {
|
|
|
73
76
|
/**
|
|
74
77
|
* Create tools from MCP tools in all provided connectors.
|
|
75
78
|
*
|
|
76
|
-
* @param connectors List of MCP connectors to create tools from.
|
|
77
|
-
* @returns
|
|
79
|
+
* @param connectors - List of MCP connectors to create tools from.
|
|
80
|
+
* @returns A promise that resolves with all converted tools.
|
|
78
81
|
*/
|
|
79
82
|
async createToolsFromConnectors(connectors) {
|
|
80
83
|
const tools = [];
|
|
@@ -88,8 +91,8 @@ var BaseAdapter = class {
|
|
|
88
91
|
/**
|
|
89
92
|
* Dynamically load resources for a specific connector.
|
|
90
93
|
*
|
|
91
|
-
* @param connector The connector to load resources for.
|
|
92
|
-
* @returns
|
|
94
|
+
* @param connector - The connector to load resources for.
|
|
95
|
+
* @returns The list of resources that were loaded in the target framework's format.
|
|
93
96
|
*/
|
|
94
97
|
async loadResourcesForConnector(connector) {
|
|
95
98
|
const connectorResources = [];
|
|
@@ -119,8 +122,8 @@ var BaseAdapter = class {
|
|
|
119
122
|
/**
|
|
120
123
|
* Dynamically load prompts for a specific connector.
|
|
121
124
|
*
|
|
122
|
-
* @param connector The connector to load prompts for.
|
|
123
|
-
* @returns
|
|
125
|
+
* @param connector - The connector to load prompts for.
|
|
126
|
+
* @returns The list of prompts that were loaded in the target framework's format.
|
|
124
127
|
*/
|
|
125
128
|
async loadPromptsForConnector(connector) {
|
|
126
129
|
const connectorPrompts = [];
|
|
@@ -150,8 +153,8 @@ var BaseAdapter = class {
|
|
|
150
153
|
/**
|
|
151
154
|
* Create resources from MCP resources in all provided connectors.
|
|
152
155
|
*
|
|
153
|
-
* @param connectors List of MCP connectors to create resources from.
|
|
154
|
-
* @returns
|
|
156
|
+
* @param connectors - List of MCP connectors to create resources from.
|
|
157
|
+
* @returns A promise that resolves with all converted resources.
|
|
155
158
|
*/
|
|
156
159
|
async createResourcesFromConnectors(connectors) {
|
|
157
160
|
const resources = [];
|
|
@@ -165,8 +168,8 @@ var BaseAdapter = class {
|
|
|
165
168
|
/**
|
|
166
169
|
* Create prompts from MCP prompts in all provided connectors.
|
|
167
170
|
*
|
|
168
|
-
* @param connectors List of MCP connectors to create prompts from.
|
|
169
|
-
* @returns
|
|
171
|
+
* @param connectors - List of MCP connectors to create prompts from.
|
|
172
|
+
* @returns A promise that resolves with all converted prompts.
|
|
170
173
|
*/
|
|
171
174
|
async createPromptsFromConnectors(connectors) {
|
|
172
175
|
const prompts = [];
|
|
@@ -180,8 +183,8 @@ var BaseAdapter = class {
|
|
|
180
183
|
/**
|
|
181
184
|
* Check if a connector is initialized and has tools.
|
|
182
185
|
*
|
|
183
|
-
* @param connector The connector to check.
|
|
184
|
-
* @returns
|
|
186
|
+
* @param connector - The connector to check.
|
|
187
|
+
* @returns True if the connector is initialized and has tools, false otherwise.
|
|
185
188
|
*/
|
|
186
189
|
checkConnectorInitialized(connector) {
|
|
187
190
|
return Boolean(connector.tools && connector.tools.length);
|
|
@@ -189,8 +192,8 @@ var BaseAdapter = class {
|
|
|
189
192
|
/**
|
|
190
193
|
* Ensure a connector is initialized.
|
|
191
194
|
*
|
|
192
|
-
* @param connector The connector to initialize.
|
|
193
|
-
* @returns
|
|
195
|
+
* @param connector - The connector to initialize.
|
|
196
|
+
* @returns True if initialization succeeded, false otherwise.
|
|
194
197
|
*/
|
|
195
198
|
async ensureConnectorInitialized(connector) {
|
|
196
199
|
if (!this.checkConnectorInitialized(connector)) {
|
|
@@ -214,14 +217,29 @@ function sanitizeToolName(name) {
|
|
|
214
217
|
var NativeAdapter = class extends BaseAdapter {
|
|
215
218
|
usedToolNames = /* @__PURE__ */ new Set();
|
|
216
219
|
handlers = /* @__PURE__ */ new Map();
|
|
220
|
+
/**
|
|
221
|
+
* @param disallowedTools - MCP tool names to omit during conversion.
|
|
222
|
+
*/
|
|
217
223
|
constructor(disallowedTools = []) {
|
|
218
224
|
super(disallowedTools);
|
|
219
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Converts MCP tools from all connectors and resets the dispatch table.
|
|
228
|
+
*
|
|
229
|
+
* @param connectors - Connected MCP connectors.
|
|
230
|
+
* @returns Provider-neutral tool entries.
|
|
231
|
+
*/
|
|
220
232
|
async createToolsFromConnectors(connectors) {
|
|
221
233
|
this.usedToolNames.clear();
|
|
222
234
|
this.handlers.clear();
|
|
223
235
|
return super.createToolsFromConnectors(connectors);
|
|
224
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Creates a dispatcher for the entries loaded by this adapter.
|
|
239
|
+
*
|
|
240
|
+
* @returns A function that invokes tools, reads resources, or gets prompts.
|
|
241
|
+
* @throws Error if the requested exposed tool name is unknown.
|
|
242
|
+
*/
|
|
225
243
|
createCallTool() {
|
|
226
244
|
const handlers = this.handlers;
|
|
227
245
|
return async (name, args) => {
|
|
@@ -244,6 +262,12 @@ var NativeAdapter = class extends BaseAdapter {
|
|
|
244
262
|
}
|
|
245
263
|
};
|
|
246
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Removes internal dispatch metadata from native tool entries.
|
|
267
|
+
*
|
|
268
|
+
* @param entries - Entries created by this adapter.
|
|
269
|
+
* @returns Provider-neutral definitions safe to send to an LLM provider.
|
|
270
|
+
*/
|
|
247
271
|
toProviderTools(entries) {
|
|
248
272
|
return entries.map(({ name, description, inputSchema }) => ({
|
|
249
273
|
name,
|
|
@@ -1349,6 +1373,9 @@ function buildOllamaApiUrl(baseUrl, path) {
|
|
|
1349
1373
|
return `${normalizeOllamaBaseUrl(baseUrl)}${path}`;
|
|
1350
1374
|
}
|
|
1351
1375
|
var OllamaCorsError = class extends Error {
|
|
1376
|
+
/**
|
|
1377
|
+
* @param cause - Original network error.
|
|
1378
|
+
*/
|
|
1352
1379
|
constructor(cause) {
|
|
1353
1380
|
super(
|
|
1354
1381
|
"Could not reach Ollama. If it's running, allow this origin by starting Ollama with `OLLAMA_ORIGINS=*` (or your inspector origin) and try again."
|
|
@@ -1554,8 +1581,15 @@ async function chat3(params) {
|
|
|
1554
1581
|
|
|
1555
1582
|
// src/llm/providers/openai-chat-completions.ts
|
|
1556
1583
|
var LlmRequestError = class extends Error {
|
|
1584
|
+
/** HTTP response status. */
|
|
1557
1585
|
status;
|
|
1586
|
+
/** Parsed JSON response body, or the raw response text. */
|
|
1558
1587
|
body;
|
|
1588
|
+
/**
|
|
1589
|
+
* @param status - HTTP response status.
|
|
1590
|
+
* @param message - Error message.
|
|
1591
|
+
* @param body - Parsed or raw provider response body.
|
|
1592
|
+
*/
|
|
1559
1593
|
constructor(status, message, body) {
|
|
1560
1594
|
super(message);
|
|
1561
1595
|
this.name = "LlmRequestError";
|
|
@@ -2637,7 +2671,7 @@ function providerConfigFromOptions(provider, model, config) {
|
|
|
2637
2671
|
}
|
|
2638
2672
|
|
|
2639
2673
|
// src/version.ts
|
|
2640
|
-
var VERSION = "2.0.0-beta.
|
|
2674
|
+
var VERSION = "2.0.0-beta.19";
|
|
2641
2675
|
function getPackageVersion() {
|
|
2642
2676
|
return VERSION;
|
|
2643
2677
|
}
|
|
@@ -2699,6 +2733,11 @@ var RemoteAgent = class {
|
|
|
2699
2733
|
apiKey;
|
|
2700
2734
|
baseUrl;
|
|
2701
2735
|
chatId = null;
|
|
2736
|
+
/**
|
|
2737
|
+
* @param options - Hosted agent identifier and API connection settings.
|
|
2738
|
+
* @throws Error if no API key is supplied or available from
|
|
2739
|
+
* `MCP_USE_API_KEY`.
|
|
2740
|
+
*/
|
|
2702
2741
|
constructor(options) {
|
|
2703
2742
|
this.agentId = options.agentId;
|
|
2704
2743
|
this.baseUrl = options.baseUrl ?? "https://cloud.manufact.com";
|
|
@@ -2924,6 +2963,7 @@ Raw error: ${result}`
|
|
|
2924
2963
|
);
|
|
2925
2964
|
return result;
|
|
2926
2965
|
}
|
|
2966
|
+
/** Releases local remote-agent state. */
|
|
2927
2967
|
async close() {
|
|
2928
2968
|
logger4.debug("\u{1F50C} Remote agent client closed");
|
|
2929
2969
|
}
|
|
@@ -2931,6 +2971,7 @@ Raw error: ${result}`
|
|
|
2931
2971
|
|
|
2932
2972
|
// src/agents/mcp_agent.ts
|
|
2933
2973
|
var MCPAgent = class {
|
|
2974
|
+
/** @returns The installed `@mcp-use/agent` package version. */
|
|
2934
2975
|
static getPackageVersion() {
|
|
2935
2976
|
return getPackageVersion();
|
|
2936
2977
|
}
|
|
@@ -2958,6 +2999,15 @@ var MCPAgent = class {
|
|
|
2958
2999
|
conversationMessages = [];
|
|
2959
3000
|
memoryEnabled;
|
|
2960
3001
|
boundConnections;
|
|
3002
|
+
/**
|
|
3003
|
+
* Creates an MCP agent.
|
|
3004
|
+
*
|
|
3005
|
+
* Call {@link initialize} before the first local run unless
|
|
3006
|
+
* `autoInitialize` is enabled. Setting `agentId` creates a remote agent.
|
|
3007
|
+
*
|
|
3008
|
+
* @param options - Model, MCP connection, and execution settings.
|
|
3009
|
+
* @throws Error if local execution has no MCP servers, client, or connectors.
|
|
3010
|
+
*/
|
|
2961
3011
|
constructor(options) {
|
|
2962
3012
|
if (options.agentId) {
|
|
2963
3013
|
this.isRemote = true;
|
|
@@ -2977,7 +3027,6 @@ var MCPAgent = class {
|
|
|
2977
3027
|
return;
|
|
2978
3028
|
}
|
|
2979
3029
|
this.maxSteps = options.maxSteps ?? 10;
|
|
2980
|
-
this.autoInitialize = options.autoInitialize ?? false;
|
|
2981
3030
|
this.systemPrompt = options.systemPrompt ?? "You are a helpful assistant with access to MCP tools.";
|
|
2982
3031
|
this.disallowedTools = options.disallowedTools ?? [];
|
|
2983
3032
|
this.exposeResourcesAsTools = options.exposeResourcesAsTools ?? true;
|
|
@@ -3017,6 +3066,7 @@ var MCPAgent = class {
|
|
|
3017
3066
|
parseLLMStringToProviderConfig(this.llmString, this.llmConfig)
|
|
3018
3067
|
);
|
|
3019
3068
|
}
|
|
3069
|
+
this.autoInitialize = options.autoInitialize ?? this.isSimplifiedMode;
|
|
3020
3070
|
}
|
|
3021
3071
|
resolveMcpServers(mcpServers) {
|
|
3022
3072
|
if (!mcpServers) return;
|
|
@@ -3029,6 +3079,14 @@ var MCPAgent = class {
|
|
|
3029
3079
|
hasLiveConnections() {
|
|
3030
3080
|
return (this.boundConnections?.length ?? 0) > 0;
|
|
3031
3081
|
}
|
|
3082
|
+
/**
|
|
3083
|
+
* Resolves the model configuration, connects MCP servers, and loads tools.
|
|
3084
|
+
*
|
|
3085
|
+
* Calling this method more than once has no effect until {@link close}.
|
|
3086
|
+
*
|
|
3087
|
+
* @throws Error if the model configuration is incomplete or no driver can
|
|
3088
|
+
* be created.
|
|
3089
|
+
*/
|
|
3032
3090
|
async initialize() {
|
|
3033
3091
|
if (this.isRemote) {
|
|
3034
3092
|
this.initialized = true;
|
|
@@ -3168,12 +3226,21 @@ var MCPAgent = class {
|
|
|
3168
3226
|
}
|
|
3169
3227
|
return messages;
|
|
3170
3228
|
}
|
|
3229
|
+
/**
|
|
3230
|
+
* @returns A shallow copy of stored provider-neutral conversation history.
|
|
3231
|
+
*/
|
|
3171
3232
|
getConversationHistory() {
|
|
3172
3233
|
return [...this.conversationMessages];
|
|
3173
3234
|
}
|
|
3235
|
+
/** Removes all stored user and assistant messages. */
|
|
3174
3236
|
clearConversationHistory() {
|
|
3175
3237
|
this.conversationMessages = [];
|
|
3176
3238
|
}
|
|
3239
|
+
/**
|
|
3240
|
+
* Replaces the system instruction used by subsequent runs.
|
|
3241
|
+
*
|
|
3242
|
+
* @param message - New system instruction.
|
|
3243
|
+
*/
|
|
3177
3244
|
setSystemMessage(message) {
|
|
3178
3245
|
this.systemPrompt = message;
|
|
3179
3246
|
}
|
|
@@ -3285,7 +3352,13 @@ var MCPAgent = class {
|
|
|
3285
3352
|
await this.ensureReady(options.manageConnector ?? true);
|
|
3286
3353
|
yield* streamNativeAgent(this.driver, this.nativeRunParams(options));
|
|
3287
3354
|
}
|
|
3288
|
-
/**
|
|
3355
|
+
/**
|
|
3356
|
+
* Runs a single model completion without MCP tools.
|
|
3357
|
+
*
|
|
3358
|
+
* @param options - Provider-neutral messages and optional cancellation
|
|
3359
|
+
* signal.
|
|
3360
|
+
* @returns Final assistant text.
|
|
3361
|
+
*/
|
|
3289
3362
|
async chat(options) {
|
|
3290
3363
|
await this.ensureReady();
|
|
3291
3364
|
const result = await this.driver.complete({
|
|
@@ -3295,6 +3368,11 @@ var MCPAgent = class {
|
|
|
3295
3368
|
});
|
|
3296
3369
|
return result.text;
|
|
3297
3370
|
}
|
|
3371
|
+
/**
|
|
3372
|
+
* Closes MCP sessions created by this agent and resets initialization state.
|
|
3373
|
+
*
|
|
3374
|
+
* Existing clients supplied by the caller remain open.
|
|
3375
|
+
*/
|
|
3298
3376
|
async close() {
|
|
3299
3377
|
if (this.clientOwnedByAgent && this.client) {
|
|
3300
3378
|
await this.client.closeAllSessions?.();
|
|
@@ -3317,6 +3395,7 @@ async function completeChat(params) {
|
|
|
3317
3395
|
// src/agents/prompts/index.ts
|
|
3318
3396
|
var CODE_MODE_PROMPT = "Use code execution mode to discover and call MCP tools programmatically.";
|
|
3319
3397
|
var PROMPTS = {
|
|
3398
|
+
/** Instruction used to enable code-based MCP tool discovery and calls. */
|
|
3320
3399
|
CODE_MODE: CODE_MODE_PROMPT
|
|
3321
3400
|
};
|
|
3322
3401
|
export {
|