langchain-mcp 1.0.0 → 1.0.2
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/bin/cli.js +73 -14
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -2,13 +2,44 @@
|
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import http from 'http';
|
|
4
4
|
import open from 'open';
|
|
5
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
6
|
import { loadConfig, saveConfig, deleteConfig, getConfigPath, DEFAULT_API_URL } from '../src/config.js';
|
|
6
7
|
import { APIClient } from '../src/api-client.js';
|
|
8
|
+
import { createServer } from '../src/server.js';
|
|
9
|
+
// ASCII Art Banner
|
|
10
|
+
const BANNER = `
|
|
11
|
+
_ _ _ __ __ ____ ____
|
|
12
|
+
| | __ _ _ __ __ _ ___| |__ __ _(_)_ __ | \\/ |/ ___| _ \\
|
|
13
|
+
| | / _\` | '_ \\ / _\` |/ __| '_ \\ / _\` | | '_ \\ _____| |\\/| | | | |_) |
|
|
14
|
+
| |__| (_| | | | | (_| | (__| | | | (_| | | | | |_____| | | | |___| __/
|
|
15
|
+
|_____\\__,_|_| |_|\\__, |\\___|_| |_|\\__,_|_|_| |_| |_| |_|\\____|_|
|
|
16
|
+
|___/
|
|
17
|
+
`;
|
|
18
|
+
function printBanner() {
|
|
19
|
+
console.log('\x1b[36m' + BANNER + '\x1b[0m'); // Cyan color
|
|
20
|
+
}
|
|
21
|
+
function printDivider(char = '─', length = 70) {
|
|
22
|
+
console.log('\x1b[90m' + char.repeat(length) + '\x1b[0m');
|
|
23
|
+
}
|
|
24
|
+
function printSection(title) {
|
|
25
|
+
console.log(`\n\x1b[1m\x1b[33m${title}\x1b[0m`); // Bold yellow
|
|
26
|
+
}
|
|
7
27
|
const program = new Command();
|
|
8
28
|
program
|
|
9
29
|
.name('langchain-mcp')
|
|
10
30
|
.description('CLI for LangChain MCP server')
|
|
11
31
|
.version('1.0.0');
|
|
32
|
+
/**
|
|
33
|
+
* Default action - start MCP server (when no command given)
|
|
34
|
+
*/
|
|
35
|
+
program
|
|
36
|
+
.command('serve', { isDefault: true, hidden: true })
|
|
37
|
+
.description('Start MCP server')
|
|
38
|
+
.action(async () => {
|
|
39
|
+
const server = createServer();
|
|
40
|
+
const transport = new StdioServerTransport();
|
|
41
|
+
await server.connect(transport);
|
|
42
|
+
});
|
|
12
43
|
/**
|
|
13
44
|
* Login command - supports Google and GitHub OAuth
|
|
14
45
|
*/
|
|
@@ -69,9 +100,20 @@ async function loginWithWebFlow(apiUrl, provider, openBrowser) {
|
|
|
69
100
|
api_url: apiUrl,
|
|
70
101
|
user,
|
|
71
102
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
console.log(
|
|
103
|
+
printBanner();
|
|
104
|
+
printDivider();
|
|
105
|
+
console.log('\n \x1b[32m✓ Login Successful!\x1b[0m\n');
|
|
106
|
+
printSection('👤 User');
|
|
107
|
+
console.log(` Name: ${user.name || 'N/A'}`);
|
|
108
|
+
console.log(` Email: ${user.email}`);
|
|
109
|
+
printSection('💰 Credits');
|
|
110
|
+
const creditColor = user.credits > 5 ? '\x1b[32m' : user.credits > 1 ? '\x1b[33m' : '\x1b[31m';
|
|
111
|
+
console.log(` Remaining: ${creditColor}$${user.credits.toFixed(2)}\x1b[0m`);
|
|
112
|
+
printSection('⚙️ Config');
|
|
113
|
+
console.log(` Saved to: ${getConfigPath()}`);
|
|
114
|
+
console.log('');
|
|
115
|
+
printDivider();
|
|
116
|
+
console.log('');
|
|
75
117
|
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
76
118
|
res.end(`
|
|
77
119
|
<!DOCTYPE html>
|
|
@@ -147,26 +189,43 @@ program
|
|
|
147
189
|
.description('Show current login status and usage')
|
|
148
190
|
.action(async () => {
|
|
149
191
|
const config = loadConfig();
|
|
192
|
+
printBanner();
|
|
193
|
+
printDivider();
|
|
150
194
|
if (!config) {
|
|
151
|
-
console.log('
|
|
152
|
-
console.log('Run
|
|
195
|
+
console.log('\n \x1b[31m✗ Not logged in\x1b[0m');
|
|
196
|
+
console.log(' Run \x1b[36mlangchain-mcp login\x1b[0m to get started.\n');
|
|
153
197
|
return;
|
|
154
198
|
}
|
|
155
|
-
|
|
156
|
-
|
|
199
|
+
// User Info Section
|
|
200
|
+
printSection('👤 User');
|
|
201
|
+
console.log(` Name: ${config.user?.name || 'N/A'}`);
|
|
202
|
+
console.log(` Email: ${config.user?.email || 'Unknown'}`);
|
|
203
|
+
console.log(` ID: ${config.user?.id || 'N/A'}`);
|
|
157
204
|
try {
|
|
158
205
|
const client = new APIClient(config.api_url, config.api_key);
|
|
159
206
|
const usage = await client.getUsage();
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
console.log(`
|
|
207
|
+
// Credits Section
|
|
208
|
+
printSection('💰 Credits');
|
|
209
|
+
const remaining = usage.credits.remaining;
|
|
210
|
+
const creditColor = remaining > 5 ? '\x1b[32m' : remaining > 1 ? '\x1b[33m' : '\x1b[31m';
|
|
211
|
+
console.log(` Remaining: ${creditColor}$${remaining.toFixed(2)}\x1b[0m`);
|
|
212
|
+
// Token Usage Section
|
|
213
|
+
printSection('📊 Token Usage');
|
|
214
|
+
console.log(` Today: ${usage.usage.today.tokens.toLocaleString().padStart(12)} tokens (${usage.usage.today.requests} requests)`);
|
|
215
|
+
console.log(` This Month: ${usage.usage.this_month.tokens.toLocaleString().padStart(12)} tokens (${usage.usage.this_month.requests} requests)`);
|
|
216
|
+
console.log(` All Time: ${usage.usage.all_time.tokens.toLocaleString().padStart(12)} tokens (${usage.usage.all_time.requests} requests)`);
|
|
217
|
+
// Config Section
|
|
218
|
+
printSection('⚙️ Config');
|
|
219
|
+
console.log(` Path: ${getConfigPath()}`);
|
|
220
|
+
console.log(` API: ${config.api_url}`);
|
|
165
221
|
}
|
|
166
222
|
catch (error) {
|
|
167
|
-
console.log(`\n⚠️ Could not fetch usage: ${error.message}`);
|
|
168
|
-
console.log('Your API key may be invalid. Run
|
|
223
|
+
console.log(`\n \x1b[33m⚠️ Could not fetch usage: ${error.message}\x1b[0m`);
|
|
224
|
+
console.log(' Your API key may be invalid. Run \x1b[36mlangchain-mcp login\x1b[0m again.');
|
|
169
225
|
}
|
|
226
|
+
console.log('');
|
|
227
|
+
printDivider();
|
|
228
|
+
console.log('');
|
|
170
229
|
});
|
|
171
230
|
/**
|
|
172
231
|
* Logout command - remove local credentials
|