@mcpspend/proxy 0.2.2 → 0.3.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/cli.js +1 -1
- package/dist/clients.d.ts +2 -0
- package/dist/clients.js +33 -0
- package/dist/clients.test.d.ts +1 -0
- package/dist/clients.test.js +133 -0
- package/dist/init.d.ts +1 -0
- package/dist/init.js +26 -3
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const config_js_1 = require("./config.js");
|
|
5
5
|
const proxy_js_1 = require("./proxy.js");
|
|
6
6
|
const init_js_1 = require("./init.js");
|
|
7
|
-
const VERSION = '0.
|
|
7
|
+
const VERSION = '0.3.0';
|
|
8
8
|
const HELP = `mcpspend — observability proxy for MCP servers (v${VERSION})
|
|
9
9
|
|
|
10
10
|
USAGE
|
package/dist/clients.d.ts
CHANGED
|
@@ -12,12 +12,14 @@ export interface ClientDefinition {
|
|
|
12
12
|
id: 'claude-desktop' | 'cursor' | 'windsurf' | 'vscode' | 'vscode-workspace' | 'claude-code';
|
|
13
13
|
name: string;
|
|
14
14
|
configPaths: () => string[];
|
|
15
|
+
installMarkers?: () => string[];
|
|
15
16
|
serversKey?: string;
|
|
16
17
|
}
|
|
17
18
|
export declare const CLIENTS: ClientDefinition[];
|
|
18
19
|
export interface DiscoveredClient {
|
|
19
20
|
client: ClientDefinition;
|
|
20
21
|
path: string;
|
|
22
|
+
bootstrapped?: boolean;
|
|
21
23
|
}
|
|
22
24
|
export declare function discoverClients(): DiscoveredClient[];
|
|
23
25
|
export declare function readClientConfig(path: string): ClientConfig;
|
package/dist/clients.js
CHANGED
|
@@ -40,6 +40,22 @@ exports.CLIENTS = [
|
|
|
40
40
|
(0, node_path_1.join)(home, '.codeium', 'windsurf', 'mcp_config.json'),
|
|
41
41
|
(0, node_path_1.join)(home, '.codeium', 'windsurf-next', 'mcp_config.json'),
|
|
42
42
|
],
|
|
43
|
+
// Windsurf only creates mcp_config.json after the user adds a server via
|
|
44
|
+
// the UI. The .codeium/windsurf dir exists from the moment Windsurf runs
|
|
45
|
+
// once, and the AppData install dir exists from the install itself.
|
|
46
|
+
installMarkers: () => {
|
|
47
|
+
const markers = [
|
|
48
|
+
(0, node_path_1.join)(home, '.codeium', 'windsurf'),
|
|
49
|
+
(0, node_path_1.join)(home, '.codeium', 'windsurf-next'),
|
|
50
|
+
];
|
|
51
|
+
if (isWin) {
|
|
52
|
+
markers.push((0, node_path_1.join)(process.env.LOCALAPPDATA || (0, node_path_1.join)(home, 'AppData', 'Local'), 'Windsurf'));
|
|
53
|
+
}
|
|
54
|
+
else if (isMac) {
|
|
55
|
+
markers.push('/Applications/Windsurf.app');
|
|
56
|
+
}
|
|
57
|
+
return markers;
|
|
58
|
+
},
|
|
43
59
|
},
|
|
44
60
|
{
|
|
45
61
|
id: 'vscode',
|
|
@@ -68,12 +84,29 @@ exports.CLIENTS = [
|
|
|
68
84
|
function discoverClients() {
|
|
69
85
|
const found = [];
|
|
70
86
|
for (const c of exports.CLIENTS) {
|
|
87
|
+
let matched = false;
|
|
88
|
+
// First try existing config files (the common case).
|
|
71
89
|
for (const p of c.configPaths()) {
|
|
72
90
|
if ((0, node_fs_1.existsSync)(p)) {
|
|
73
91
|
found.push({ client: c, path: p });
|
|
92
|
+
matched = true;
|
|
74
93
|
break;
|
|
75
94
|
}
|
|
76
95
|
}
|
|
96
|
+
if (matched)
|
|
97
|
+
continue;
|
|
98
|
+
// Fall back to install markers. If the client is installed but has never
|
|
99
|
+
// had a config written, take the first configPath as the destination and
|
|
100
|
+
// mark the discovery as bootstrapped.
|
|
101
|
+
if (c.installMarkers) {
|
|
102
|
+
const installed = c.installMarkers().some(p => (0, node_fs_1.existsSync)(p));
|
|
103
|
+
if (installed) {
|
|
104
|
+
const paths = c.configPaths();
|
|
105
|
+
if (paths.length > 0) {
|
|
106
|
+
found.push({ client: c, path: paths[0], bootstrapped: true });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
77
110
|
}
|
|
78
111
|
return found;
|
|
79
112
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Unit tests for the wrap/unwrap logic in clients.ts.
|
|
3
|
+
//
|
|
4
|
+
// History: we shipped 0.2.0 with isAlreadyWrapped() failing to recognise
|
|
5
|
+
// `npx -y @mcpspend/proxy@latest wrap …`, which caused init to double-wrap
|
|
6
|
+
// configs that users had previously set up manually. These tests pin down
|
|
7
|
+
// every wrap shape we ever generate or accept.
|
|
8
|
+
//
|
|
9
|
+
// Run with: node --test --import tsx src/clients.test.ts
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const node_test_1 = require("node:test");
|
|
15
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
16
|
+
const clients_js_1 = require("./clients.js");
|
|
17
|
+
(0, node_test_1.describe)('isAlreadyWrapped', () => {
|
|
18
|
+
(0, node_test_1.test)('recognises npx -y @mcpspend/proxy wrap', () => {
|
|
19
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({
|
|
20
|
+
command: 'npx',
|
|
21
|
+
args: ['-y', '@mcpspend/proxy', 'wrap', '--', 'node', 'server.js'],
|
|
22
|
+
}), true);
|
|
23
|
+
});
|
|
24
|
+
(0, node_test_1.test)('recognises npx -y @mcpspend/proxy@latest wrap', () => {
|
|
25
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({
|
|
26
|
+
command: 'npx',
|
|
27
|
+
args: ['-y', '@mcpspend/proxy@latest', 'wrap', '--', 'node', 'server.js'],
|
|
28
|
+
}), true);
|
|
29
|
+
});
|
|
30
|
+
(0, node_test_1.test)('recognises npx -y @mcpspend/proxy@0.2.2 wrap', () => {
|
|
31
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({
|
|
32
|
+
command: 'npx',
|
|
33
|
+
args: ['-y', '@mcpspend/proxy@0.2.2', 'wrap', '--', 'node', 'server.js'],
|
|
34
|
+
}), true);
|
|
35
|
+
});
|
|
36
|
+
(0, node_test_1.test)('recognises npx without -y flag', () => {
|
|
37
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({
|
|
38
|
+
command: 'npx',
|
|
39
|
+
args: ['@mcpspend/proxy', 'wrap', '--', 'node', 'server.js'],
|
|
40
|
+
}), true);
|
|
41
|
+
});
|
|
42
|
+
(0, node_test_1.test)('recognises bin-direct mcpspend wrap', () => {
|
|
43
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({
|
|
44
|
+
command: 'mcpspend',
|
|
45
|
+
args: ['wrap', '--', 'node', 'server.js'],
|
|
46
|
+
}), true);
|
|
47
|
+
});
|
|
48
|
+
(0, node_test_1.test)('recognises absolute Windows path to mcpspend.cmd', () => {
|
|
49
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({
|
|
50
|
+
command: 'C:\\Users\\me\\AppData\\Roaming\\npm\\mcpspend.cmd',
|
|
51
|
+
args: ['wrap', '--', 'node', 'server.js'],
|
|
52
|
+
}), true);
|
|
53
|
+
});
|
|
54
|
+
(0, node_test_1.test)('rejects unrelated npx invocations', () => {
|
|
55
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({
|
|
56
|
+
command: 'npx',
|
|
57
|
+
args: ['-y', '@modelcontextprotocol/server-filesystem', '/data'],
|
|
58
|
+
}), false);
|
|
59
|
+
});
|
|
60
|
+
(0, node_test_1.test)('rejects raw mcpspend without wrap subcommand', () => {
|
|
61
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({
|
|
62
|
+
command: 'mcpspend',
|
|
63
|
+
args: ['init', '--key', 'mcps_live_xxx'],
|
|
64
|
+
}), false);
|
|
65
|
+
});
|
|
66
|
+
(0, node_test_1.test)('rejects empty args', () => {
|
|
67
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({ command: 'npx', args: [] }), false);
|
|
68
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({ command: 'mcpspend', args: [] }), false);
|
|
69
|
+
});
|
|
70
|
+
(0, node_test_1.test)('rejects an npx invoking some other package called proxy', () => {
|
|
71
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)({
|
|
72
|
+
command: 'npx',
|
|
73
|
+
args: ['-y', '@otherorg/proxy', 'wrap', '--', 'node', 'server.js'],
|
|
74
|
+
}), false);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
(0, node_test_1.describe)('wrap → unwrap roundtrip', () => {
|
|
78
|
+
(0, node_test_1.test)('npx-style preserves command + args + env', () => {
|
|
79
|
+
const original = {
|
|
80
|
+
command: 'npx',
|
|
81
|
+
args: ['-y', '@modelcontextprotocol/server-filesystem', '/data'],
|
|
82
|
+
env: { FOO: 'bar' },
|
|
83
|
+
};
|
|
84
|
+
const wrapped = (0, clients_js_1.wrapEntry)(original);
|
|
85
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)(wrapped), true, 'wrapped should be recognised');
|
|
86
|
+
const restored = (0, clients_js_1.unwrapEntry)(wrapped);
|
|
87
|
+
strict_1.default.deepEqual(restored, original);
|
|
88
|
+
});
|
|
89
|
+
(0, node_test_1.test)('bin-style preserves command + args + env', () => {
|
|
90
|
+
const original = {
|
|
91
|
+
command: 'node',
|
|
92
|
+
args: ['./my-server.js'],
|
|
93
|
+
env: { GITHUB_TOKEN: 'xxx' },
|
|
94
|
+
};
|
|
95
|
+
const wrapped = (0, clients_js_1.wrapEntry)(original, { style: 'bin' });
|
|
96
|
+
strict_1.default.equal(wrapped.command, 'mcpspend');
|
|
97
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)(wrapped), true);
|
|
98
|
+
const restored = (0, clients_js_1.unwrapEntry)(wrapped);
|
|
99
|
+
strict_1.default.deepEqual(restored, original);
|
|
100
|
+
});
|
|
101
|
+
(0, node_test_1.test)('does NOT bake the API key into wrapped args (prevents git leak)', () => {
|
|
102
|
+
const wrapped = (0, clients_js_1.wrapEntry)({ command: 'node', args: ['server.js'] }, { apiKey: 'mcps_live_SECRET' });
|
|
103
|
+
const flat = JSON.stringify(wrapped);
|
|
104
|
+
strict_1.default.equal(flat.includes('mcps_live_SECRET'), false);
|
|
105
|
+
strict_1.default.equal(flat.includes('--key'), false);
|
|
106
|
+
});
|
|
107
|
+
(0, node_test_1.test)('projectId and agentName are baked in (they are not secrets)', () => {
|
|
108
|
+
const wrapped = (0, clients_js_1.wrapEntry)({ command: 'node', args: ['server.js'] }, { projectId: 'prj_xyz', agentName: 'demo-agent' });
|
|
109
|
+
strict_1.default.ok(wrapped.args.includes('--project'));
|
|
110
|
+
strict_1.default.ok(wrapped.args.includes('prj_xyz'));
|
|
111
|
+
strict_1.default.ok(wrapped.args.includes('--agent'));
|
|
112
|
+
strict_1.default.ok(wrapped.args.includes('demo-agent'));
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
(0, node_test_1.describe)('unwrapEntry edge cases', () => {
|
|
116
|
+
(0, node_test_1.test)('returns null for non-wrapped entries (no-op safety)', () => {
|
|
117
|
+
strict_1.default.equal((0, clients_js_1.unwrapEntry)({ command: 'npx', args: ['some', 'thing'] }), null);
|
|
118
|
+
});
|
|
119
|
+
(0, node_test_1.test)('handles wrapped entry with no -- separator gracefully', () => {
|
|
120
|
+
strict_1.default.equal((0, clients_js_1.unwrapEntry)({ command: 'mcpspend', args: ['wrap'] }), null);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
(0, node_test_1.describe)('idempotency', () => {
|
|
124
|
+
(0, node_test_1.test)('wrapping a wrapped entry should not double-wrap (guarded at wrapAllServers level)', () => {
|
|
125
|
+
// wrapEntry itself does not check — it's wrapAllServers that gates on
|
|
126
|
+
// isAlreadyWrapped. Confirm that the gate works as documented.
|
|
127
|
+
const original = { command: 'npx', args: ['@modelcontextprotocol/server-filesystem', '/data'] };
|
|
128
|
+
const once = (0, clients_js_1.wrapEntry)(original);
|
|
129
|
+
strict_1.default.equal((0, clients_js_1.isAlreadyWrapped)(once), true);
|
|
130
|
+
// If wrapAllServers correctly skips, the entry passed to wrapEntry would
|
|
131
|
+
// already be wrapped — but defensive callers should rely on isAlreadyWrapped.
|
|
132
|
+
});
|
|
133
|
+
});
|
package/dist/init.d.ts
CHANGED
package/dist/init.js
CHANGED
|
@@ -27,10 +27,24 @@ function runInit(opts = {}) {
|
|
|
27
27
|
discovered = discovered.filter((d) => set.has(d.client.id));
|
|
28
28
|
}
|
|
29
29
|
const clientReports = [];
|
|
30
|
-
for (const { client, path } of discovered) {
|
|
30
|
+
for (const { client, path, bootstrapped } of discovered) {
|
|
31
31
|
const serversKey = client.serversKey || 'mcpServers';
|
|
32
32
|
try {
|
|
33
33
|
const current = (0, clients_js_1.readClientConfig)(path);
|
|
34
|
+
// Bootstrap-mode: client is installed but has no MCP config yet. We still
|
|
35
|
+
// want to create the file with an empty mcpServers object so the user
|
|
36
|
+
// can add their first server via the UI and have it auto-wrapped on the
|
|
37
|
+
// next `init` run. Unwrap is a no-op here.
|
|
38
|
+
if (bootstrapped && opts.unwrap) {
|
|
39
|
+
clientReports.push({
|
|
40
|
+
client: client.id,
|
|
41
|
+
name: client.name,
|
|
42
|
+
path,
|
|
43
|
+
status: 'no-changes',
|
|
44
|
+
servers: [],
|
|
45
|
+
});
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
34
48
|
const { config: next, results } = opts.unwrap
|
|
35
49
|
? (0, clients_js_1.unwrapAllServers)(current, serversKey)
|
|
36
50
|
: (0, clients_js_1.wrapAllServers)(current, serversKey, {
|
|
@@ -38,7 +52,12 @@ function runInit(opts = {}) {
|
|
|
38
52
|
endpoint: opts.endpoint,
|
|
39
53
|
agentName: opts.agentName,
|
|
40
54
|
});
|
|
41
|
-
const changed = JSON.stringify(current) !== JSON.stringify(next);
|
|
55
|
+
const changed = bootstrapped || JSON.stringify(current) !== JSON.stringify(next);
|
|
56
|
+
if (bootstrapped && !(next[serversKey] && Object.keys(next[serversKey]).length > 0)) {
|
|
57
|
+
// Ensure the key exists in the new file even when empty.
|
|
58
|
+
;
|
|
59
|
+
next[serversKey] = {};
|
|
60
|
+
}
|
|
42
61
|
if (opts.dryRun) {
|
|
43
62
|
clientReports.push({
|
|
44
63
|
client: client.id,
|
|
@@ -67,6 +86,7 @@ function runInit(opts = {}) {
|
|
|
67
86
|
status: 'patched',
|
|
68
87
|
backupPath: backupPath || undefined,
|
|
69
88
|
servers: results,
|
|
89
|
+
bootstrapped,
|
|
70
90
|
});
|
|
71
91
|
}
|
|
72
92
|
catch (err) {
|
|
@@ -102,7 +122,7 @@ function formatReport(report, unwrap = false) {
|
|
|
102
122
|
}
|
|
103
123
|
lines.push(`Found ${report.clientsFound} MCP client(s):`);
|
|
104
124
|
for (const r of report.clients) {
|
|
105
|
-
const tag = r.status === 'patched' ? '✓ patched'
|
|
125
|
+
const tag = r.status === 'patched' ? (r.bootstrapped ? '✓ bootstrapped (empty config created)' : '✓ patched')
|
|
106
126
|
: r.status === 'no-changes' ? '· no changes'
|
|
107
127
|
: r.status === 'dry-run' ? '∼ dry-run'
|
|
108
128
|
: `✗ error: ${r.error}`;
|
|
@@ -111,6 +131,9 @@ function formatReport(report, unwrap = false) {
|
|
|
111
131
|
if (r.backupPath) {
|
|
112
132
|
lines.push(` backup: ${r.backupPath}`);
|
|
113
133
|
}
|
|
134
|
+
if (r.bootstrapped && r.servers.length === 0) {
|
|
135
|
+
lines.push(` (add MCP servers in the client UI — they'll be auto-wrapped next time you run init)`);
|
|
136
|
+
}
|
|
114
137
|
for (const s of r.servers) {
|
|
115
138
|
const sym = s.status === 'wrapped' ? '+'
|
|
116
139
|
: s.status === 'already-wrapped' ? '='
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcpspend/proxy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Transparent proxy CLI for MCP servers — tracks tool calls, latency, and cost via MCPSpend.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://mcpspend.com",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsc",
|
|
38
38
|
"dev": "tsx src/cli.ts",
|
|
39
|
+
"test": "node --test --import tsx src/clients.test.ts",
|
|
39
40
|
"typecheck": "tsc --noEmit",
|
|
40
41
|
"prepublishOnly": "npm run build"
|
|
41
42
|
},
|