@mcp-use/cli 1.0.14 → 1.0.15
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/cli.js +98 -35
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -279210,6 +279210,9 @@ var LLMService = class {
|
|
|
279210
279210
|
getAvailableProviders() {
|
|
279211
279211
|
return Object.entries(PROVIDERS).filter(([, providerInfo]) => this.getApiKey(providerInfo.envVar)).map(([providerName]) => providerName);
|
|
279212
279212
|
}
|
|
279213
|
+
getAllProviderNames() {
|
|
279214
|
+
return Object.keys(PROVIDERS);
|
|
279215
|
+
}
|
|
279213
279216
|
isAnyProviderAvailable() {
|
|
279214
279217
|
return this.getAvailableProviders().length > 0;
|
|
279215
279218
|
}
|
|
@@ -280377,7 +280380,13 @@ var CLIService = class {
|
|
|
280377
280380
|
registerCommands() {
|
|
280378
280381
|
this.commandRegistry.set("/model", {
|
|
280379
280382
|
handler: (args) => this.llmService.handleModelCommand(args),
|
|
280380
|
-
description: "Choose your LLM provider and model"
|
|
280383
|
+
description: "Choose your LLM provider and model",
|
|
280384
|
+
getSuggestions: async (args) => {
|
|
280385
|
+
if (args.length <= 1) {
|
|
280386
|
+
return this.llmService.getAllProviderNames();
|
|
280387
|
+
}
|
|
280388
|
+
return [];
|
|
280389
|
+
}
|
|
280381
280390
|
});
|
|
280382
280391
|
this.commandRegistry.set("/models", {
|
|
280383
280392
|
handler: () => this.llmService.handleListModelsCommand(),
|
|
@@ -280397,7 +280406,8 @@ var CLIService = class {
|
|
|
280397
280406
|
});
|
|
280398
280407
|
this.commandRegistry.set("/server", {
|
|
280399
280408
|
handler: (args) => this.handleServerCommand(args),
|
|
280400
|
-
description: "Manage MCP servers"
|
|
280409
|
+
description: "Manage MCP servers",
|
|
280410
|
+
getSuggestions: () => ["add", "connect", "disconnect"]
|
|
280401
280411
|
});
|
|
280402
280412
|
this.commandRegistry.set("/server add", {
|
|
280403
280413
|
handler: () => this.handleServerAddCommand(),
|
|
@@ -280405,11 +280415,19 @@ var CLIService = class {
|
|
|
280405
280415
|
});
|
|
280406
280416
|
this.commandRegistry.set("/server connect", {
|
|
280407
280417
|
handler: async (args) => this.handleServerConnectCommand(args),
|
|
280408
|
-
description: "Connect to a configured server"
|
|
280418
|
+
description: "Connect to a configured server",
|
|
280419
|
+
getSuggestions: async () => {
|
|
280420
|
+
const configured = Object.keys(
|
|
280421
|
+
this.mcpConfigService.getConfiguredServers()
|
|
280422
|
+
);
|
|
280423
|
+
const connected = this.agentService.getConnectedServerNames();
|
|
280424
|
+
return configured.filter((s5) => !connected.includes(s5));
|
|
280425
|
+
}
|
|
280409
280426
|
});
|
|
280410
280427
|
this.commandRegistry.set("/server disconnect", {
|
|
280411
280428
|
handler: async (args) => this.handleServerDisconnectCommand(args),
|
|
280412
|
-
description: "Disconnect from a server"
|
|
280429
|
+
description: "Disconnect from a server",
|
|
280430
|
+
getSuggestions: async () => this.agentService.getConnectedServerNames()
|
|
280413
280431
|
});
|
|
280414
280432
|
this.commandRegistry.set("/servers", {
|
|
280415
280433
|
handler: () => this.handleListServersCommand(),
|
|
@@ -280889,29 +280907,75 @@ Connected servers: ${connectedServers.join(
|
|
|
280889
280907
|
message: "Server name is required.\n\nUsage: /server disconnect <server_name>"
|
|
280890
280908
|
};
|
|
280891
280909
|
}
|
|
280892
|
-
if (!this.agentService.isServerConnected(serverName)) {
|
|
280893
|
-
return {
|
|
280894
|
-
type: "error",
|
|
280895
|
-
message: `Server "${serverName}" is not connected.`
|
|
280896
|
-
};
|
|
280897
|
-
}
|
|
280898
280910
|
try {
|
|
280899
|
-
this.agentService.disconnectServer(serverName);
|
|
280911
|
+
await this.agentService.disconnectServer(serverName);
|
|
280912
|
+
await this.initializeAgent();
|
|
280900
280913
|
return {
|
|
280901
|
-
type: "
|
|
280902
|
-
message:
|
|
280903
|
-
data: {
|
|
280914
|
+
type: "server_action",
|
|
280915
|
+
message: `Disconnected from server: ${serverName}`,
|
|
280916
|
+
data: {
|
|
280917
|
+
reinitializeAgent: true,
|
|
280918
|
+
serverName,
|
|
280919
|
+
action: "disconnect"
|
|
280920
|
+
}
|
|
280904
280921
|
};
|
|
280905
280922
|
} catch (error) {
|
|
280906
|
-
Logger.error(`Failed to disconnect from server ${serverName}`, {
|
|
280907
|
-
error: error instanceof Error ? error.message : String(error)
|
|
280908
|
-
});
|
|
280909
280923
|
return {
|
|
280910
280924
|
type: "error",
|
|
280911
|
-
message: `Failed to disconnect from
|
|
280925
|
+
message: `Failed to disconnect from ${serverName}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
280912
280926
|
};
|
|
280913
280927
|
}
|
|
280914
280928
|
}
|
|
280929
|
+
/**
|
|
280930
|
+
* Gets command suggestions based on the user's input.
|
|
280931
|
+
* It can suggest commands, subcommands, or arguments.
|
|
280932
|
+
* @param text The full input string from the user.
|
|
280933
|
+
* @returns A promise that resolves to an array of suggestion strings.
|
|
280934
|
+
*/
|
|
280935
|
+
async getSuggestions(text) {
|
|
280936
|
+
const parts = text.trim().split(/\s+/);
|
|
280937
|
+
const commandName = parts[0] || "";
|
|
280938
|
+
if (!text.includes(" ")) {
|
|
280939
|
+
return [...this.commandRegistry.keys()].filter(
|
|
280940
|
+
(c4) => c4.startsWith(commandName) && !c4.includes(" ")
|
|
280941
|
+
);
|
|
280942
|
+
}
|
|
280943
|
+
const getPotentialCommands = (input) => {
|
|
280944
|
+
const result = [];
|
|
280945
|
+
const ps = input.trim().split(" ");
|
|
280946
|
+
if (ps.length >= 2) {
|
|
280947
|
+
const twoPartCmd = `${ps[0]} ${ps[1]}`;
|
|
280948
|
+
if (this.commandRegistry.has(twoPartCmd)) {
|
|
280949
|
+
result.push({
|
|
280950
|
+
cmd: twoPartCmd,
|
|
280951
|
+
entry: this.commandRegistry.get(twoPartCmd),
|
|
280952
|
+
args: ps.slice(2)
|
|
280953
|
+
});
|
|
280954
|
+
}
|
|
280955
|
+
}
|
|
280956
|
+
if (this.commandRegistry.has(ps[0])) {
|
|
280957
|
+
result.push({
|
|
280958
|
+
cmd: ps[0],
|
|
280959
|
+
entry: this.commandRegistry.get(ps[0]),
|
|
280960
|
+
args: ps.slice(1)
|
|
280961
|
+
});
|
|
280962
|
+
}
|
|
280963
|
+
return result;
|
|
280964
|
+
};
|
|
280965
|
+
const potentialCommands = getPotentialCommands(text);
|
|
280966
|
+
if (potentialCommands.length === 0) {
|
|
280967
|
+
return [];
|
|
280968
|
+
}
|
|
280969
|
+
const { entry, args } = potentialCommands.length > 1 && potentialCommands[0].cmd.length > potentialCommands[1].cmd.length ? potentialCommands[0] : potentialCommands.at(-1);
|
|
280970
|
+
if (entry.getSuggestions) {
|
|
280971
|
+
const suggestions = await entry.getSuggestions(args);
|
|
280972
|
+
const lastArg = text.endsWith(" ") ? "" : args.at(-1) || "";
|
|
280973
|
+
const filtered = suggestions.filter((s5) => s5.startsWith(lastArg));
|
|
280974
|
+
const baseCommand = text.endsWith(" ") ? text : text.slice(0, -lastArg.length);
|
|
280975
|
+
return filtered.map((s5) => `${baseCommand}${s5}`);
|
|
280976
|
+
}
|
|
280977
|
+
return [];
|
|
280978
|
+
}
|
|
280915
280979
|
/**
|
|
280916
280980
|
* Returns the command registry.
|
|
280917
280981
|
* @returns The map of registered commands
|
|
@@ -283114,18 +283178,13 @@ function CommandSuggestions({
|
|
|
283114
283178
|
suggestions,
|
|
283115
283179
|
query
|
|
283116
283180
|
}) {
|
|
283117
|
-
const filteredSuggestions = suggestions.filter(
|
|
283118
|
-
([command]) => command.startsWith(query)
|
|
283119
|
-
);
|
|
283181
|
+
const filteredSuggestions = suggestions.filter((s5) => s5.startsWith(query));
|
|
283120
283182
|
if (filteredSuggestions.length === 0) {
|
|
283121
283183
|
return null;
|
|
283122
283184
|
}
|
|
283123
283185
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box_default, { flexDirection: "column", marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Box_default, { borderStyle: "round", paddingX: 1, flexDirection: "column", children: [
|
|
283124
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { bold: true, children: "
|
|
283125
|
-
filteredSuggestions.
|
|
283126
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box_default, { width: 20, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { children: command }) }),
|
|
283127
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { children: description })
|
|
283128
|
-
] }, command))
|
|
283186
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { bold: true, children: "SUGGESTIONS" }),
|
|
283187
|
+
filteredSuggestions.slice(0, 5).map((suggestion) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box_default, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { children: suggestion }) }, suggestion))
|
|
283129
283188
|
] }) });
|
|
283130
283189
|
}
|
|
283131
283190
|
|
|
@@ -283148,7 +283207,7 @@ function App2() {
|
|
|
283148
283207
|
const [inputHistory, setInputHistory] = (0, import_react26.useState)([]);
|
|
283149
283208
|
const [historyIndex, setHistoryIndex] = (0, import_react26.useState)(-1);
|
|
283150
283209
|
const [tempInput, setTempInput] = (0, import_react26.useState)("");
|
|
283151
|
-
const [
|
|
283210
|
+
const [suggestions, setSuggestions] = (0, import_react26.useState)([]);
|
|
283152
283211
|
const { stdout } = use_stdout_default();
|
|
283153
283212
|
(0, import_react26.useEffect)(() => {
|
|
283154
283213
|
const initializeMCP = async () => {
|
|
@@ -283162,7 +283221,6 @@ function App2() {
|
|
|
283162
283221
|
model,
|
|
283163
283222
|
connectedServers: servers
|
|
283164
283223
|
});
|
|
283165
|
-
setCommandSuggestions([...cliService.getCommandRegistry().entries()]);
|
|
283166
283224
|
setCurrentModel(model);
|
|
283167
283225
|
setConnectedServers(servers);
|
|
283168
283226
|
setShowInput(true);
|
|
@@ -283179,6 +283237,17 @@ function App2() {
|
|
|
283179
283237
|
};
|
|
283180
283238
|
initializeMCP();
|
|
283181
283239
|
}, []);
|
|
283240
|
+
(0, import_react26.useEffect)(() => {
|
|
283241
|
+
const fetchSuggestions = async () => {
|
|
283242
|
+
if (input.startsWith("/")) {
|
|
283243
|
+
const suggs = await cliService.getSuggestions(input);
|
|
283244
|
+
setSuggestions(suggs);
|
|
283245
|
+
} else {
|
|
283246
|
+
setSuggestions([]);
|
|
283247
|
+
}
|
|
283248
|
+
};
|
|
283249
|
+
fetchSuggestions();
|
|
283250
|
+
}, [input]);
|
|
283182
283251
|
use_input_default((inputChar, key) => {
|
|
283183
283252
|
if (key.ctrl && inputChar === "c") {
|
|
283184
283253
|
process.exit(0);
|
|
@@ -283534,13 +283603,7 @@ function App2() {
|
|
|
283534
283603
|
isLoading && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box_default, { marginBottom: 1, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box_default, { marginRight: 1, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: "blue", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Spinner_default, { type: "mcpuse" }) }) }) })
|
|
283535
283604
|
] }),
|
|
283536
283605
|
showInput && !initializationError && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
283537
|
-
input.startsWith("/") && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
283538
|
-
CommandSuggestions,
|
|
283539
|
-
{
|
|
283540
|
-
suggestions: commandSuggestions,
|
|
283541
|
-
query: input
|
|
283542
|
-
}
|
|
283543
|
-
),
|
|
283606
|
+
input.startsWith("/") && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CommandSuggestions, { suggestions, query: input }),
|
|
283544
283607
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
283545
283608
|
Box_default,
|
|
283546
283609
|
{
|