@mcp-use/cli 2.8.1 → 2.8.2-canary.1
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/commands/client.d.ts +0 -3
- package/dist/commands/client.d.ts.map +1 -1
- package/dist/index.cjs +106 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +106 -85
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1787,88 +1787,9 @@ async function whoamiCommand() {
|
|
|
1787
1787
|
|
|
1788
1788
|
// src/commands/client.ts
|
|
1789
1789
|
import { Command } from "commander";
|
|
1790
|
-
import {
|
|
1790
|
+
import { getPackageVersion } from "mcp-use";
|
|
1791
1791
|
import { MCPClient } from "mcp-use/client";
|
|
1792
|
-
|
|
1793
|
-
// src/utils/session-storage.ts
|
|
1794
|
-
import { homedir } from "os";
|
|
1795
|
-
import { join } from "path";
|
|
1796
|
-
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
1797
|
-
import { existsSync } from "fs";
|
|
1798
|
-
var SESSION_FILE_PATH = join(homedir(), ".mcp-use", "cli-sessions.json");
|
|
1799
|
-
async function ensureSessionDir() {
|
|
1800
|
-
const dir = join(homedir(), ".mcp-use");
|
|
1801
|
-
if (!existsSync(dir)) {
|
|
1802
|
-
await mkdir(dir, { recursive: true });
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
async function loadSessions() {
|
|
1806
|
-
try {
|
|
1807
|
-
await ensureSessionDir();
|
|
1808
|
-
if (!existsSync(SESSION_FILE_PATH)) {
|
|
1809
|
-
return { activeSession: null, sessions: {} };
|
|
1810
|
-
}
|
|
1811
|
-
const content = await readFile(SESSION_FILE_PATH, "utf-8");
|
|
1812
|
-
return JSON.parse(content);
|
|
1813
|
-
} catch (error) {
|
|
1814
|
-
return { activeSession: null, sessions: {} };
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
async function saveSessions(storage) {
|
|
1818
|
-
await ensureSessionDir();
|
|
1819
|
-
await writeFile(SESSION_FILE_PATH, JSON.stringify(storage, null, 2), "utf-8");
|
|
1820
|
-
}
|
|
1821
|
-
async function saveSession(name, config) {
|
|
1822
|
-
const storage = await loadSessions();
|
|
1823
|
-
storage.sessions[name] = {
|
|
1824
|
-
...config,
|
|
1825
|
-
lastUsed: (/* @__PURE__ */ new Date()).toISOString()
|
|
1826
|
-
};
|
|
1827
|
-
if (!storage.activeSession) {
|
|
1828
|
-
storage.activeSession = name;
|
|
1829
|
-
}
|
|
1830
|
-
await saveSessions(storage);
|
|
1831
|
-
}
|
|
1832
|
-
async function getActiveSession() {
|
|
1833
|
-
const storage = await loadSessions();
|
|
1834
|
-
if (!storage.activeSession || !storage.sessions[storage.activeSession]) {
|
|
1835
|
-
return null;
|
|
1836
|
-
}
|
|
1837
|
-
return {
|
|
1838
|
-
name: storage.activeSession,
|
|
1839
|
-
config: storage.sessions[storage.activeSession]
|
|
1840
|
-
};
|
|
1841
|
-
}
|
|
1842
|
-
async function getSession(name) {
|
|
1843
|
-
const storage = await loadSessions();
|
|
1844
|
-
return storage.sessions[name] || null;
|
|
1845
|
-
}
|
|
1846
|
-
async function setActiveSession(name) {
|
|
1847
|
-
const storage = await loadSessions();
|
|
1848
|
-
if (!storage.sessions[name]) {
|
|
1849
|
-
throw new Error(`Session '${name}' not found`);
|
|
1850
|
-
}
|
|
1851
|
-
storage.activeSession = name;
|
|
1852
|
-
storage.sessions[name].lastUsed = (/* @__PURE__ */ new Date()).toISOString();
|
|
1853
|
-
await saveSessions(storage);
|
|
1854
|
-
}
|
|
1855
|
-
async function listAllSessions() {
|
|
1856
|
-
const storage = await loadSessions();
|
|
1857
|
-
return Object.entries(storage.sessions).map(([name, config]) => ({
|
|
1858
|
-
name,
|
|
1859
|
-
config,
|
|
1860
|
-
isActive: name === storage.activeSession
|
|
1861
|
-
}));
|
|
1862
|
-
}
|
|
1863
|
-
async function updateSessionInfo(name, serverInfo, capabilities) {
|
|
1864
|
-
const storage = await loadSessions();
|
|
1865
|
-
if (storage.sessions[name]) {
|
|
1866
|
-
storage.sessions[name].serverInfo = serverInfo;
|
|
1867
|
-
storage.sessions[name].capabilities = capabilities;
|
|
1868
|
-
storage.sessions[name].lastUsed = (/* @__PURE__ */ new Date()).toISOString();
|
|
1869
|
-
await saveSessions(storage);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1792
|
+
import { createInterface } from "readline";
|
|
1872
1793
|
|
|
1873
1794
|
// src/utils/format.ts
|
|
1874
1795
|
function formatTable(data, columns) {
|
|
@@ -2106,6 +2027,86 @@ function formatPromptMessages(messages) {
|
|
|
2106
2027
|
return lines.join("\n");
|
|
2107
2028
|
}
|
|
2108
2029
|
|
|
2030
|
+
// src/utils/session-storage.ts
|
|
2031
|
+
import { homedir } from "os";
|
|
2032
|
+
import { join } from "path";
|
|
2033
|
+
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
2034
|
+
import { existsSync } from "fs";
|
|
2035
|
+
var SESSION_FILE_PATH = join(homedir(), ".mcp-use", "cli-sessions.json");
|
|
2036
|
+
async function ensureSessionDir() {
|
|
2037
|
+
const dir = join(homedir(), ".mcp-use");
|
|
2038
|
+
if (!existsSync(dir)) {
|
|
2039
|
+
await mkdir(dir, { recursive: true });
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
async function loadSessions() {
|
|
2043
|
+
try {
|
|
2044
|
+
await ensureSessionDir();
|
|
2045
|
+
if (!existsSync(SESSION_FILE_PATH)) {
|
|
2046
|
+
return { activeSession: null, sessions: {} };
|
|
2047
|
+
}
|
|
2048
|
+
const content = await readFile(SESSION_FILE_PATH, "utf-8");
|
|
2049
|
+
return JSON.parse(content);
|
|
2050
|
+
} catch (error) {
|
|
2051
|
+
return { activeSession: null, sessions: {} };
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
async function saveSessions(storage) {
|
|
2055
|
+
await ensureSessionDir();
|
|
2056
|
+
await writeFile(SESSION_FILE_PATH, JSON.stringify(storage, null, 2), "utf-8");
|
|
2057
|
+
}
|
|
2058
|
+
async function saveSession(name, config) {
|
|
2059
|
+
const storage = await loadSessions();
|
|
2060
|
+
storage.sessions[name] = {
|
|
2061
|
+
...config,
|
|
2062
|
+
lastUsed: (/* @__PURE__ */ new Date()).toISOString()
|
|
2063
|
+
};
|
|
2064
|
+
if (!storage.activeSession) {
|
|
2065
|
+
storage.activeSession = name;
|
|
2066
|
+
}
|
|
2067
|
+
await saveSessions(storage);
|
|
2068
|
+
}
|
|
2069
|
+
async function getActiveSession() {
|
|
2070
|
+
const storage = await loadSessions();
|
|
2071
|
+
if (!storage.activeSession || !storage.sessions[storage.activeSession]) {
|
|
2072
|
+
return null;
|
|
2073
|
+
}
|
|
2074
|
+
return {
|
|
2075
|
+
name: storage.activeSession,
|
|
2076
|
+
config: storage.sessions[storage.activeSession]
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
async function getSession(name) {
|
|
2080
|
+
const storage = await loadSessions();
|
|
2081
|
+
return storage.sessions[name] || null;
|
|
2082
|
+
}
|
|
2083
|
+
async function setActiveSession(name) {
|
|
2084
|
+
const storage = await loadSessions();
|
|
2085
|
+
if (!storage.sessions[name]) {
|
|
2086
|
+
throw new Error(`Session '${name}' not found`);
|
|
2087
|
+
}
|
|
2088
|
+
storage.activeSession = name;
|
|
2089
|
+
storage.sessions[name].lastUsed = (/* @__PURE__ */ new Date()).toISOString();
|
|
2090
|
+
await saveSessions(storage);
|
|
2091
|
+
}
|
|
2092
|
+
async function listAllSessions() {
|
|
2093
|
+
const storage = await loadSessions();
|
|
2094
|
+
return Object.entries(storage.sessions).map(([name, config]) => ({
|
|
2095
|
+
name,
|
|
2096
|
+
config,
|
|
2097
|
+
isActive: name === storage.activeSession
|
|
2098
|
+
}));
|
|
2099
|
+
}
|
|
2100
|
+
async function updateSessionInfo(name, serverInfo, capabilities) {
|
|
2101
|
+
const storage = await loadSessions();
|
|
2102
|
+
if (storage.sessions[name]) {
|
|
2103
|
+
storage.sessions[name].serverInfo = serverInfo;
|
|
2104
|
+
storage.sessions[name].capabilities = capabilities;
|
|
2105
|
+
storage.sessions[name].lastUsed = (/* @__PURE__ */ new Date()).toISOString();
|
|
2106
|
+
await saveSessions(storage);
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2109
2110
|
// src/commands/client.ts
|
|
2110
2111
|
var activeSessions = /* @__PURE__ */ new Map();
|
|
2111
2112
|
async function getOrRestoreSession(sessionName) {
|
|
@@ -2133,16 +2134,19 @@ async function getOrRestoreSession(sessionName) {
|
|
|
2133
2134
|
}
|
|
2134
2135
|
try {
|
|
2135
2136
|
const client = new MCPClient();
|
|
2137
|
+
const cliClientInfo = getCliClientInfo();
|
|
2136
2138
|
if (config.type === "http") {
|
|
2137
2139
|
client.addServer(sessionName, {
|
|
2138
2140
|
url: config.url,
|
|
2139
|
-
headers: config.authToken ? { Authorization: `Bearer ${config.authToken}` } : void 0
|
|
2141
|
+
headers: config.authToken ? { Authorization: `Bearer ${config.authToken}` } : void 0,
|
|
2142
|
+
clientInfo: cliClientInfo
|
|
2140
2143
|
});
|
|
2141
2144
|
} else if (config.type === "stdio") {
|
|
2142
2145
|
client.addServer(sessionName, {
|
|
2143
2146
|
command: config.command,
|
|
2144
2147
|
args: config.args || [],
|
|
2145
|
-
env: config.env
|
|
2148
|
+
env: config.env,
|
|
2149
|
+
clientInfo: cliClientInfo
|
|
2146
2150
|
});
|
|
2147
2151
|
} else {
|
|
2148
2152
|
console.error(formatError(`Unknown session type: ${config.type}`));
|
|
@@ -2157,11 +2161,26 @@ async function getOrRestoreSession(sessionName) {
|
|
|
2157
2161
|
return null;
|
|
2158
2162
|
}
|
|
2159
2163
|
}
|
|
2164
|
+
function getCliClientInfo() {
|
|
2165
|
+
return {
|
|
2166
|
+
name: "mcp-use CLI",
|
|
2167
|
+
title: "mcp-use CLI",
|
|
2168
|
+
version: getPackageVersion(),
|
|
2169
|
+
description: "mcp-use CLI - Command-line interface for MCP servers",
|
|
2170
|
+
icons: [
|
|
2171
|
+
{
|
|
2172
|
+
src: "https://mcp-use.com/logo.png"
|
|
2173
|
+
}
|
|
2174
|
+
],
|
|
2175
|
+
websiteUrl: "https://mcp-use.com"
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2160
2178
|
async function connectCommand(urlOrCommand, options) {
|
|
2161
2179
|
try {
|
|
2162
2180
|
const sessionName = options.name || `session-${Date.now()}`;
|
|
2163
2181
|
const client = new MCPClient();
|
|
2164
2182
|
let session;
|
|
2183
|
+
const cliClientInfo = getCliClientInfo();
|
|
2165
2184
|
if (options.stdio) {
|
|
2166
2185
|
const parts = urlOrCommand.split(" ");
|
|
2167
2186
|
const command = parts[0];
|
|
@@ -2171,7 +2190,8 @@ async function connectCommand(urlOrCommand, options) {
|
|
|
2171
2190
|
);
|
|
2172
2191
|
client.addServer(sessionName, {
|
|
2173
2192
|
command,
|
|
2174
|
-
args
|
|
2193
|
+
args,
|
|
2194
|
+
clientInfo: cliClientInfo
|
|
2175
2195
|
});
|
|
2176
2196
|
session = await client.createSession(sessionName);
|
|
2177
2197
|
await saveSession(sessionName, {
|
|
@@ -2184,7 +2204,8 @@ async function connectCommand(urlOrCommand, options) {
|
|
|
2184
2204
|
console.error(formatInfo(`Connecting to ${urlOrCommand}...`));
|
|
2185
2205
|
client.addServer(sessionName, {
|
|
2186
2206
|
url: urlOrCommand,
|
|
2187
|
-
headers: options.auth ? { Authorization: `Bearer ${options.auth}` } : void 0
|
|
2207
|
+
headers: options.auth ? { Authorization: `Bearer ${options.auth}` } : void 0,
|
|
2208
|
+
clientInfo: cliClientInfo
|
|
2188
2209
|
});
|
|
2189
2210
|
session = await client.createSession(sessionName);
|
|
2190
2211
|
await saveSession(sessionName, {
|