mcponce 0.1.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/README.md +1013 -0
- package/dist/cli/analytics.d.ts +5 -0
- package/dist/cli/analytics.d.ts.map +1 -0
- package/dist/cli/analytics.js +93 -0
- package/dist/cli/analytics.js.map +1 -0
- package/dist/cli/bin.d.ts +20 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +510 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +196 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/info.d.ts +3 -0
- package/dist/cli/info.d.ts.map +1 -0
- package/dist/cli/info.js +42 -0
- package/dist/cli/info.js.map +1 -0
- package/dist/cli/installer.d.ts +64 -0
- package/dist/cli/installer.d.ts.map +1 -0
- package/dist/cli/installer.js +183 -0
- package/dist/cli/installer.js.map +1 -0
- package/dist/cli/logs.d.ts +3 -0
- package/dist/cli/logs.d.ts.map +1 -0
- package/dist/cli/logs.js +19 -0
- package/dist/cli/logs.js.map +1 -0
- package/dist/cli/tool-caller.d.ts +70 -0
- package/dist/cli/tool-caller.d.ts.map +1 -0
- package/dist/cli/tool-caller.js +404 -0
- package/dist/cli/tool-caller.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/file-logger.d.ts +21 -0
- package/dist/logging/file-logger.d.ts.map +1 -0
- package/dist/logging/file-logger.js +96 -0
- package/dist/logging/file-logger.js.map +1 -0
- package/dist/logging/logger.d.ts +22 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +57 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/logging/rotation.d.ts +6 -0
- package/dist/logging/rotation.d.ts.map +1 -0
- package/dist/logging/rotation.js +32 -0
- package/dist/logging/rotation.js.map +1 -0
- package/dist/registry/central.d.ts +54 -0
- package/dist/registry/central.d.ts.map +1 -0
- package/dist/registry/central.js +205 -0
- package/dist/registry/central.js.map +1 -0
- package/dist/registry/prompts.d.ts +9 -0
- package/dist/registry/prompts.d.ts.map +1 -0
- package/dist/registry/prompts.js +18 -0
- package/dist/registry/prompts.js.map +1 -0
- package/dist/registry/resources.d.ts +52 -0
- package/dist/registry/resources.d.ts.map +1 -0
- package/dist/registry/resources.js +102 -0
- package/dist/registry/resources.js.map +1 -0
- package/dist/registry/subscriptions.d.ts +44 -0
- package/dist/registry/subscriptions.d.ts.map +1 -0
- package/dist/registry/subscriptions.js +96 -0
- package/dist/registry/subscriptions.js.map +1 -0
- package/dist/registry/tools.d.ts +24 -0
- package/dist/registry/tools.d.ts.map +1 -0
- package/dist/registry/tools.js +120 -0
- package/dist/registry/tools.js.map +1 -0
- package/dist/runtime/config.d.ts +30 -0
- package/dist/runtime/config.d.ts.map +1 -0
- package/dist/runtime/config.js +79 -0
- package/dist/runtime/config.js.map +1 -0
- package/dist/runtime/health.d.ts +15 -0
- package/dist/runtime/health.d.ts.map +1 -0
- package/dist/runtime/health.js +63 -0
- package/dist/runtime/health.js.map +1 -0
- package/dist/runtime/instance.d.ts +33 -0
- package/dist/runtime/instance.d.ts.map +1 -0
- package/dist/runtime/instance.js +148 -0
- package/dist/runtime/instance.js.map +1 -0
- package/dist/runtime/lock.d.ts +33 -0
- package/dist/runtime/lock.d.ts.map +1 -0
- package/dist/runtime/lock.js +105 -0
- package/dist/runtime/lock.js.map +1 -0
- package/dist/runtime/paths.d.ts +16 -0
- package/dist/runtime/paths.d.ts.map +1 -0
- package/dist/runtime/paths.js +54 -0
- package/dist/runtime/paths.js.map +1 -0
- package/dist/runtime/state.d.ts +24 -0
- package/dist/runtime/state.d.ts.map +1 -0
- package/dist/runtime/state.js +71 -0
- package/dist/runtime/state.js.map +1 -0
- package/dist/runtime/unitup.d.ts +44 -0
- package/dist/runtime/unitup.d.ts.map +1 -0
- package/dist/runtime/unitup.js +134 -0
- package/dist/runtime/unitup.js.map +1 -0
- package/dist/server/analytics.d.ts +47 -0
- package/dist/server/analytics.d.ts.map +1 -0
- package/dist/server/analytics.js +327 -0
- package/dist/server/analytics.js.map +1 -0
- package/dist/server/app.d.ts +249 -0
- package/dist/server/app.d.ts.map +1 -0
- package/dist/server/app.js +1332 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/context.d.ts +12 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +52 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/hono.d.ts +54 -0
- package/dist/server/hono.d.ts.map +1 -0
- package/dist/server/hono.js +423 -0
- package/dist/server/hono.js.map +1 -0
- package/dist/server/inspector.d.ts +21 -0
- package/dist/server/inspector.d.ts.map +1 -0
- package/dist/server/inspector.js +834 -0
- package/dist/server/inspector.js.map +1 -0
- package/dist/server/mcp.d.ts +41 -0
- package/dist/server/mcp.d.ts.map +1 -0
- package/dist/server/mcp.js +425 -0
- package/dist/server/mcp.js.map +1 -0
- package/dist/transport/http.d.ts +14 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +48 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/proxy.d.ts +12 -0
- package/dist/transport/proxy.d.ts.map +1 -0
- package/dist/transport/proxy.js +115 -0
- package/dist/transport/proxy.js.map +1 -0
- package/dist/types.d.ts +602 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/browser.d.ts +6 -0
- package/dist/utils/browser.d.ts.map +1 -0
- package/dist/utils/browser.js +39 -0
- package/dist/utils/browser.js.map +1 -0
- package/dist/utils/cache.d.ts +43 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +126 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/coercion.d.ts +38 -0
- package/dist/utils/coercion.d.ts.map +1 -0
- package/dist/utils/coercion.js +175 -0
- package/dist/utils/coercion.js.map +1 -0
- package/dist/utils/completion.d.ts +30 -0
- package/dist/utils/completion.d.ts.map +1 -0
- package/dist/utils/completion.js +79 -0
- package/dist/utils/completion.js.map +1 -0
- package/dist/utils/media.d.ts +65 -0
- package/dist/utils/media.d.ts.map +1 -0
- package/dist/utils/media.js +305 -0
- package/dist/utils/media.js.map +1 -0
- package/dist/utils/middleware.d.ts +48 -0
- package/dist/utils/middleware.d.ts.map +1 -0
- package/dist/utils/middleware.js +133 -0
- package/dist/utils/middleware.js.map +1 -0
- package/dist/utils/openapi.d.ts +102 -0
- package/dist/utils/openapi.d.ts.map +1 -0
- package/dist/utils/openapi.js +368 -0
- package/dist/utils/openapi.js.map +1 -0
- package/dist/utils/progress.d.ts +26 -0
- package/dist/utils/progress.d.ts.map +1 -0
- package/dist/utils/progress.js +91 -0
- package/dist/utils/progress.js.map +1 -0
- package/dist/utils/queue.d.ts +51 -0
- package/dist/utils/queue.d.ts.map +1 -0
- package/dist/utils/queue.js +136 -0
- package/dist/utils/queue.js.map +1 -0
- package/dist/utils/retry.d.ts +26 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +125 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/roots.d.ts +21 -0
- package/dist/utils/roots.d.ts.map +1 -0
- package/dist/utils/roots.js +74 -0
- package/dist/utils/roots.js.map +1 -0
- package/dist/utils/sampling.d.ts +129 -0
- package/dist/utils/sampling.d.ts.map +1 -0
- package/dist/utils/sampling.js +177 -0
- package/dist/utils/sampling.js.map +1 -0
- package/dist/utils/security.d.ts +35 -0
- package/dist/utils/security.d.ts.map +1 -0
- package/dist/utils/security.js +113 -0
- package/dist/utils/security.js.map +1 -0
- package/dist/utils/validation.d.ts +52 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +176 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ResolvedConfig } from '../runtime/config.js';
|
|
2
|
+
import type { ServerAnalytics } from '../types.js';
|
|
3
|
+
export declare function fetchAnalytics(host: string, port: number, timeoutMs?: number): Promise<ServerAnalytics | null>;
|
|
4
|
+
export declare function printAnalytics(config: ResolvedConfig<any>): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=analytics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../src/cli/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,SAAO,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAclH;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAuF/E"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { StateManager } from '../runtime/state.js';
|
|
2
|
+
import { checkHealth } from '../runtime/health.js';
|
|
3
|
+
export async function fetchAnalytics(host, port, timeoutMs = 1500) {
|
|
4
|
+
const controller = new AbortController();
|
|
5
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
6
|
+
try {
|
|
7
|
+
const res = await fetch(`http://${host}:${port}/analytics`, {
|
|
8
|
+
signal: controller.signal
|
|
9
|
+
});
|
|
10
|
+
if (!res.ok)
|
|
11
|
+
return null;
|
|
12
|
+
return (await res.json());
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export async function printAnalytics(config) {
|
|
22
|
+
const stateManager = new StateManager(config.dataDir);
|
|
23
|
+
const state = stateManager.read();
|
|
24
|
+
if (!state) {
|
|
25
|
+
console.log(`Server "${config.name}" is stopped.`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const health = await checkHealth(state.host, state.port, config.name, 1500);
|
|
29
|
+
if (!health) {
|
|
30
|
+
console.log(`Server "${config.name}" is stopped (stale state found for PID ${state.pid}).`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const analytics = await fetchAnalytics(state.host, state.port, 2000);
|
|
34
|
+
if (!analytics) {
|
|
35
|
+
console.log(`Failed to retrieve analytics from http://${state.host}:${state.port}/analytics`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const { summary, tools, interToolCalls, recentInvocations } = analytics;
|
|
39
|
+
const toolList = Object.values(tools);
|
|
40
|
+
console.log(`\n======================================================`);
|
|
41
|
+
console.log(` mcponce Analytics: ${config.name} (PID: ${state.pid})`);
|
|
42
|
+
console.log(` Server: http://${state.host}:${state.port} | Started: ${analytics.startedAt}`);
|
|
43
|
+
console.log(`======================================================\n`);
|
|
44
|
+
// 1. Summary Box
|
|
45
|
+
const successRate = summary.totalInvocations > 0
|
|
46
|
+
? Math.round((summary.successfulInvocations / summary.totalInvocations) * 1000) / 10
|
|
47
|
+
: 100;
|
|
48
|
+
console.log(`Summary:`);
|
|
49
|
+
console.log(` Total Invocations: ${summary.totalInvocations}`);
|
|
50
|
+
console.log(` Success Rate: ${successRate}% (${summary.successfulInvocations} succeeded, ${summary.failedInvocations} failed)`);
|
|
51
|
+
if (summary.timeoutInvocations > 0 || summary.cancelledInvocations > 0) {
|
|
52
|
+
console.log(` Timeouts / Cancels: ${summary.timeoutInvocations} timed out, ${summary.cancelledInvocations} cancelled`);
|
|
53
|
+
}
|
|
54
|
+
console.log(` Avg Execution Time: ${summary.averageExecutionTimeMs}ms (Total: ${summary.totalExecutionTimeMs}ms)`);
|
|
55
|
+
console.log(` Inter-Tool Calls: ${summary.totalInterToolCalls}`);
|
|
56
|
+
console.log('');
|
|
57
|
+
// 2. Per-Tool Metrics Table
|
|
58
|
+
if (toolList.length === 0) {
|
|
59
|
+
console.log(`No tool invocations recorded yet.\n`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.log(`Tool Performance:`);
|
|
63
|
+
console.log(` ${'Tool Name'.padEnd(24)} ${'Calls'.padStart(6)} ${'Success'.padStart(8)} ${'Errors'.padStart(7)} ${'Avg (ms)'.padStart(10)} ${'Min / Max (ms)'.padStart(16)}`);
|
|
64
|
+
console.log(` ${'-'.repeat(75)}`);
|
|
65
|
+
for (const t of toolList) {
|
|
66
|
+
const minMax = `${t.minDurationMs} / ${t.maxDurationMs}`;
|
|
67
|
+
console.log(` ${t.name.padEnd(24)} ${String(t.calls).padStart(6)} ${String(t.success).padStart(8)} ${String(t.errors).padStart(7)} ${String(t.avgDurationMs).padStart(10)} ${minMax.padStart(16)}`);
|
|
68
|
+
}
|
|
69
|
+
console.log('');
|
|
70
|
+
}
|
|
71
|
+
// 3. Inter-Tool Invocations (Call Graph)
|
|
72
|
+
if (interToolCalls.length > 0) {
|
|
73
|
+
console.log(`Inter-Tool Invocations (Call Graph):`);
|
|
74
|
+
for (const rel of interToolCalls) {
|
|
75
|
+
console.log(` ${rel.caller} ──(${rel.count}x)──> ${rel.target}`);
|
|
76
|
+
}
|
|
77
|
+
console.log('');
|
|
78
|
+
}
|
|
79
|
+
// 4. Recent Invocations
|
|
80
|
+
if (recentInvocations.length > 0) {
|
|
81
|
+
const recentToShow = recentInvocations.slice(-10);
|
|
82
|
+
console.log(`Recent Invocations (Last ${recentToShow.length}):`);
|
|
83
|
+
for (const item of recentToShow) {
|
|
84
|
+
const time = item.timestamp.split('T')[1]?.slice(0, 8) || item.timestamp;
|
|
85
|
+
const callerTag = item.caller ? ` [from ${item.caller}]` : '';
|
|
86
|
+
const statusIcon = item.status === 'success' ? '✓ OK' : item.status === 'timeout' ? '⏱ TIMEOUT' : item.status === 'cancelled' ? '🛑 CANCEL' : '✗ ERROR';
|
|
87
|
+
const errMsg = item.errorMessage ? ` - ${item.errorMessage}` : '';
|
|
88
|
+
console.log(` [${time}] ${item.tool}${callerTag} (${item.durationMs}ms) [${statusIcon}]${errMsg}`);
|
|
89
|
+
}
|
|
90
|
+
console.log('');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../src/cli/analytics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY,EAAE,IAAY,EAAE,SAAS,GAAG,IAAI;IAC/E,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,IAAI,IAAI,IAAI,YAAY,EAAE;YAC1D,MAAM,EAAE,UAAU,CAAC,MAAM;SAC1B,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QACzB,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAoB,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAA2B;IAC9D,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,C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usr/bin/env node
|
|
2
|
+
import { CentralRegistry } from '../registry/central.js';
|
|
3
|
+
export declare let registry: CentralRegistry;
|
|
4
|
+
export declare function setRegistry(newReg: CentralRegistry): void;
|
|
5
|
+
export declare function formatStatus(status: 'running' | 'stopped'): string;
|
|
6
|
+
export declare function pad(str: string | number, width: number): string;
|
|
7
|
+
export declare function listServers(): Promise<void>;
|
|
8
|
+
export declare function showStatus(name?: string): Promise<void>;
|
|
9
|
+
export declare function stopServer(target?: string): Promise<void>;
|
|
10
|
+
export declare function showLogs(name?: string, limitStr?: string): Promise<void>;
|
|
11
|
+
export declare function cleanRegistry(): Promise<void>;
|
|
12
|
+
export declare function callServerTool(serverName?: string, toolName?: string, rawArgs?: string[]): Promise<void>;
|
|
13
|
+
export declare function listServerTools(serverName?: string, rawArgs?: string[]): Promise<void>;
|
|
14
|
+
export declare function installServer(target?: string, clientArg?: string, flags?: string[]): Promise<void>;
|
|
15
|
+
export declare function uninstallServer(target?: string, clientArg?: string, flags?: string[]): Promise<void>;
|
|
16
|
+
export declare function inspectServer(name?: string): Promise<void>;
|
|
17
|
+
export declare function runOpenApiServer(specPathOrUrl: string, flags: string[]): Promise<void>;
|
|
18
|
+
export declare function printHelp(): void;
|
|
19
|
+
export declare function main(customArgs?: string[]): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=bin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../src/cli/bin.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAKzD,eAAO,IAAI,QAAQ,iBAAwB,CAAC;AAC5C,wBAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,QAElD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAKlE;AAED,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED,wBAAsB,WAAW,kBA4BhC;AAED,wBAAsB,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,iBAsC7C;AAED,wBAAsB,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,iBA4C/C;AAED,wBAAsB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,SAAO,iBA6B5D;AAED,wBAAsB,aAAa,kBAGlC;AAED,wBAAsB,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,EAAO,iBAoFlG;AAED,wBAAsB,eAAe,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,EAAO,iBAiFhF;AAED,wBAAsB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,SAAQ,EAAE,KAAK,GAAE,MAAM,EAAO,iBAiD3F;AAED,wBAAsB,eAAe,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,SAAQ,EAAE,KAAK,GAAE,MAAM,EAAO,iBA4B7F;AAED,wBAAsB,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,iBAwBhD;AAED,wBAAsB,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,iBAkC5E;AAED,wBAAgB,SAAS,SAkBxB;AAED,wBAAsB,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,iBAgE/C"}
|
package/dist/cli/bin.js
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { CentralRegistry } from '../registry/central.js';
|
|
5
|
+
import { fetchInfo } from '../runtime/health.js';
|
|
6
|
+
import { parseParametricArgs } from './tool-caller.js';
|
|
7
|
+
import { installClientConfig, uninstallClientConfig } from './installer.js';
|
|
8
|
+
export let registry = new CentralRegistry();
|
|
9
|
+
export function setRegistry(newReg) {
|
|
10
|
+
registry = newReg;
|
|
11
|
+
}
|
|
12
|
+
export function formatStatus(status) {
|
|
13
|
+
if (status === 'running') {
|
|
14
|
+
return '\x1b[32m● running\x1b[0m';
|
|
15
|
+
}
|
|
16
|
+
return '\x1b[90m○ stopped\x1b[0m';
|
|
17
|
+
}
|
|
18
|
+
export function pad(str, width) {
|
|
19
|
+
const s = String(str);
|
|
20
|
+
return s + ' '.repeat(Math.max(0, width - s.length));
|
|
21
|
+
}
|
|
22
|
+
export async function listServers() {
|
|
23
|
+
const servers = await registry.getAll(true);
|
|
24
|
+
console.log(`\x1b[1mmcponce servers\x1b[0m (registry: ${registry.path})\n`);
|
|
25
|
+
if (servers.length === 0) {
|
|
26
|
+
console.log('No MCP servers registered yet.');
|
|
27
|
+
console.log('Servers created with createMcpServer() register here automatically when started.\n');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Table header
|
|
31
|
+
console.log(`${pad('NAME', 20)} ${pad('STATUS', 15)} ${pad('PID', 8)} ${pad('PORT', 8)} ${pad('HOST', 12)} DATA DIRECTORY`);
|
|
32
|
+
console.log('-'.repeat(80));
|
|
33
|
+
for (const s of servers) {
|
|
34
|
+
const statusText = formatStatus(s.status);
|
|
35
|
+
const pidStr = s.pid ? String(s.pid) : '-';
|
|
36
|
+
const portStr = s.port ? String(s.port) : '-';
|
|
37
|
+
const hostStr = s.host || '-';
|
|
38
|
+
console.log(`${pad(s.name, 20)} ${pad(statusText, 24)} ${pad(pidStr, 8)} ${pad(portStr, 8)} ${pad(hostStr, 12)} ${s.dataDir}`);
|
|
39
|
+
}
|
|
40
|
+
console.log('');
|
|
41
|
+
}
|
|
42
|
+
export async function showStatus(name) {
|
|
43
|
+
if (!name) {
|
|
44
|
+
await listServers();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const server = await registry.get(name);
|
|
48
|
+
if (!server) {
|
|
49
|
+
console.error(`Server "${name}" not found in registry.`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
console.log(`Name: ${server.name}`);
|
|
53
|
+
console.log(`Version: ${server.version}`);
|
|
54
|
+
console.log(`Status: ${server.status}`);
|
|
55
|
+
console.log(`Data directory: ${server.dataDir}`);
|
|
56
|
+
console.log(`Log directory: ${server.logDir}`);
|
|
57
|
+
if (server.status === 'running' && server.port && server.host) {
|
|
58
|
+
console.log(`PID: ${server.pid}`);
|
|
59
|
+
console.log(`Host: ${server.host}`);
|
|
60
|
+
console.log(`Port: ${server.port}`);
|
|
61
|
+
console.log(`Started: ${server.startedAt || 'unknown'}`);
|
|
62
|
+
const info = await fetchInfo(server.host, server.port, 1000);
|
|
63
|
+
if (info) {
|
|
64
|
+
console.log(`Active sessions: ${info.activeSessions}`);
|
|
65
|
+
console.log(`Total sessions: ${info.totalSessions}`);
|
|
66
|
+
if (info.lastClientConnection) {
|
|
67
|
+
console.log(`Last connection: ${info.lastClientConnection}`);
|
|
68
|
+
}
|
|
69
|
+
if (info.lastToolInvocation) {
|
|
70
|
+
console.log(`Last tool invocation: ${info.lastToolInvocation.name} at ${info.lastToolInvocation.timestamp}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export async function stopServer(target) {
|
|
76
|
+
if (!target) {
|
|
77
|
+
console.error('Usage: mcponce stop <server-name | --all>');
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
if (target === '--all') {
|
|
81
|
+
const servers = await registry.getAll(true);
|
|
82
|
+
const running = servers.filter((s) => s.status === 'running');
|
|
83
|
+
if (running.length === 0) {
|
|
84
|
+
console.log('No running servers found.');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const s of running) {
|
|
88
|
+
process.stdout.write(`Stopping "${s.name}" (PID ${s.pid})... `);
|
|
89
|
+
const stopped = await registry.stop(s.name);
|
|
90
|
+
if (stopped) {
|
|
91
|
+
console.log('\x1b[32mdone\x1b[0m');
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.log('\x1b[31mfailed\x1b[0m');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const server = await registry.get(target);
|
|
100
|
+
if (!server) {
|
|
101
|
+
console.error(`Server "${target}" is not registered.`);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
if (server.status !== 'running') {
|
|
105
|
+
console.log(`Server "${target}" is already stopped.`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
process.stdout.write(`Stopping "${target}" (PID ${server.pid})... `);
|
|
109
|
+
const ok = await registry.stop(target);
|
|
110
|
+
if (ok) {
|
|
111
|
+
console.log('\x1b[32mdone\x1b[0m');
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
console.log('\x1b[31mfailed to stop\x1b[0m');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export async function showLogs(name, limitStr = '50') {
|
|
118
|
+
if (!name) {
|
|
119
|
+
console.error('Usage: mcponce logs <server-name> [lines]');
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
const server = await registry.get(name);
|
|
123
|
+
if (!server) {
|
|
124
|
+
console.error(`Server "${name}" is not registered.`);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
const currentLog = path.join(server.logDir, 'current.log');
|
|
128
|
+
console.log(`Log file: ${currentLog}`);
|
|
129
|
+
if (!fs.existsSync(currentLog)) {
|
|
130
|
+
console.log('No logs found for this server.');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const limit = parseInt(limitStr, 10) || 50;
|
|
134
|
+
const content = fs.readFileSync(currentLog, 'utf-8');
|
|
135
|
+
const lines = content.trim().split('\n').filter((l) => l.length > 0);
|
|
136
|
+
const recent = lines.slice(-limit);
|
|
137
|
+
console.log(`--- Recent ${recent.length} lines ---`);
|
|
138
|
+
for (const line of recent) {
|
|
139
|
+
console.log(line);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export async function cleanRegistry() {
|
|
143
|
+
const removed = await registry.clean();
|
|
144
|
+
console.log(`Removed ${removed} stopped server(s) from registry.`);
|
|
145
|
+
}
|
|
146
|
+
export async function callServerTool(serverName, toolName, rawArgs = []) {
|
|
147
|
+
if (!serverName || !toolName || serverName === '--help' || serverName === '-h') {
|
|
148
|
+
console.log('Usage: mcponce call <server> <tool> [params...] [--json]');
|
|
149
|
+
console.log('Example: mcponce call hello-mcp calculate --operation add -a 10 -b 20\n');
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
const server = await registry.get(serverName);
|
|
153
|
+
if (!server) {
|
|
154
|
+
console.error(`Error: Server "${serverName}" not found in registry.`);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
if (server.status !== 'running' || !server.port || !server.host) {
|
|
158
|
+
console.error(`Error: Server "${serverName}" is not running.`);
|
|
159
|
+
console.error(`Start the server before calling its tools.\n`);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
const parsed = parseParametricArgs(rawArgs);
|
|
163
|
+
const token = parsed.token || process.env.MCP_TOKEN || process.env.MCP_API_KEY;
|
|
164
|
+
try {
|
|
165
|
+
const url = `http://${server.host}:${server.port}/mcp`;
|
|
166
|
+
const headers = {
|
|
167
|
+
'Content-Type': 'application/json',
|
|
168
|
+
'Accept': 'application/json'
|
|
169
|
+
};
|
|
170
|
+
if (token) {
|
|
171
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
172
|
+
headers['X-API-Key'] = token;
|
|
173
|
+
}
|
|
174
|
+
const res = await fetch(url, {
|
|
175
|
+
method: 'POST',
|
|
176
|
+
headers,
|
|
177
|
+
body: JSON.stringify({
|
|
178
|
+
jsonrpc: '2.0',
|
|
179
|
+
id: Date.now(),
|
|
180
|
+
method: 'tools/call',
|
|
181
|
+
params: {
|
|
182
|
+
name: toolName,
|
|
183
|
+
arguments: parsed.params
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
if (!res.ok) {
|
|
188
|
+
const text = await res.text();
|
|
189
|
+
console.error(`HTTP Error ${res.status}: ${text}`);
|
|
190
|
+
process.exit(1);
|
|
191
|
+
}
|
|
192
|
+
const data = await res.json();
|
|
193
|
+
if (data.error) {
|
|
194
|
+
console.error(`\x1b[31mError [${data.error.code}]:\x1b[0m ${data.error.message}`);
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
197
|
+
const result = data.result;
|
|
198
|
+
if (result?.isError) {
|
|
199
|
+
if (parsed.isJsonOutput) {
|
|
200
|
+
console.log(JSON.stringify(result, null, 2));
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
const msg = result.content?.[0]?.text || result.text || 'Tool execution failed';
|
|
204
|
+
console.error(`\x1b[31mTool Error [${toolName}]:\x1b[0m ${msg}`);
|
|
205
|
+
}
|
|
206
|
+
process.exit(1);
|
|
207
|
+
}
|
|
208
|
+
if (parsed.isJsonOutput) {
|
|
209
|
+
console.log(JSON.stringify(result, null, 2));
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const text = result?.content?.[0]?.text || result?.text;
|
|
213
|
+
if (text) {
|
|
214
|
+
console.log(text);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
console.log(JSON.stringify(result, null, 2));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
console.error(`Failed to invoke tool on server "${serverName}":`, err.message || err);
|
|
223
|
+
process.exit(1);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export async function listServerTools(serverName, rawArgs = []) {
|
|
227
|
+
if (!serverName || serverName === '--help' || serverName === '-h') {
|
|
228
|
+
console.log('Usage: mcponce tools <server> [--token <token>]');
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
const server = await registry.get(serverName);
|
|
232
|
+
if (!server) {
|
|
233
|
+
console.error(`Error: Server "${serverName}" not found in registry.`);
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
if (server.status !== 'running' || !server.port || !server.host) {
|
|
237
|
+
console.error(`Error: Server "${serverName}" is not running.`);
|
|
238
|
+
process.exit(1);
|
|
239
|
+
}
|
|
240
|
+
const parsed = parseParametricArgs(rawArgs);
|
|
241
|
+
const token = parsed.token || process.env.MCP_TOKEN || process.env.MCP_API_KEY;
|
|
242
|
+
try {
|
|
243
|
+
const url = `http://${server.host}:${server.port}/mcp`;
|
|
244
|
+
const headers = {
|
|
245
|
+
'Content-Type': 'application/json',
|
|
246
|
+
'Accept': 'application/json'
|
|
247
|
+
};
|
|
248
|
+
if (token) {
|
|
249
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
250
|
+
headers['X-API-Key'] = token;
|
|
251
|
+
}
|
|
252
|
+
const res = await fetch(url, {
|
|
253
|
+
method: 'POST',
|
|
254
|
+
headers,
|
|
255
|
+
body: JSON.stringify({
|
|
256
|
+
jsonrpc: '2.0',
|
|
257
|
+
id: Date.now(),
|
|
258
|
+
method: 'tools/list',
|
|
259
|
+
params: {}
|
|
260
|
+
})
|
|
261
|
+
});
|
|
262
|
+
if (!res.ok) {
|
|
263
|
+
const text = await res.text();
|
|
264
|
+
console.error(`HTTP Error ${res.status}: ${text}`);
|
|
265
|
+
process.exit(1);
|
|
266
|
+
}
|
|
267
|
+
const data = await res.json();
|
|
268
|
+
if (data.error) {
|
|
269
|
+
console.error(`Error: ${data.error.message}`);
|
|
270
|
+
process.exit(1);
|
|
271
|
+
}
|
|
272
|
+
const tools = data.result?.tools || [];
|
|
273
|
+
console.log(`\n\x1b[1mTools available on server "${serverName}" (${tools.length}):\x1b[0m\n`);
|
|
274
|
+
if (tools.length === 0) {
|
|
275
|
+
console.log(' No tools registered on this server.\n');
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
for (const t of tools) {
|
|
279
|
+
console.log(` \x1b[1m\x1b[36m${t.name}\x1b[0m`);
|
|
280
|
+
if (t.description) {
|
|
281
|
+
console.log(` ${t.description}`);
|
|
282
|
+
}
|
|
283
|
+
const properties = t.inputSchema?.properties || {};
|
|
284
|
+
const propKeys = Object.keys(properties);
|
|
285
|
+
if (propKeys.length > 0) {
|
|
286
|
+
const sig = propKeys.map((k) => `--${k} <${properties[k].type || 'any'}>`).join(' ');
|
|
287
|
+
console.log(` \x1b[90mUsage: mcponce call ${serverName} ${t.name} ${sig}\x1b[0m`);
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
console.log(` \x1b[90mUsage: mcponce call ${serverName} ${t.name}\x1b[0m`);
|
|
291
|
+
}
|
|
292
|
+
console.log('');
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
console.error(`Failed to list tools from server "${serverName}":`, err.message || err);
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
export async function installServer(target, clientArg = 'all', flags = []) {
|
|
301
|
+
if (!target) {
|
|
302
|
+
console.error('Usage: mcponce install <path-to-script | registered-server-name> [client] [--dry-run] [--project]');
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
let serverName = target;
|
|
306
|
+
let entrypoint = target;
|
|
307
|
+
if (fs.existsSync(target)) {
|
|
308
|
+
entrypoint = path.resolve(target);
|
|
309
|
+
const base = path.basename(target, path.extname(target));
|
|
310
|
+
serverName =
|
|
311
|
+
base === 'index' || base === 'server' || base === 'main'
|
|
312
|
+
? path.basename(path.dirname(entrypoint))
|
|
313
|
+
: base;
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
const regServer = await registry.get(target);
|
|
317
|
+
if (regServer) {
|
|
318
|
+
serverName = regServer.name;
|
|
319
|
+
entrypoint = regServer.entrypoint || regServer.scriptPath || target;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const dryRun = flags.includes('--dry-run');
|
|
323
|
+
const project = flags.includes('--project');
|
|
324
|
+
const background = !flags.includes('--no-background');
|
|
325
|
+
try {
|
|
326
|
+
const results = installClientConfig({
|
|
327
|
+
serverName,
|
|
328
|
+
entrypoint,
|
|
329
|
+
client: clientArg,
|
|
330
|
+
background,
|
|
331
|
+
project,
|
|
332
|
+
dryRun
|
|
333
|
+
});
|
|
334
|
+
console.log(`\n\x1b[1m\x1b[32m✔\x1b[0m ${dryRun ? '[Dry-run] Would configure' : 'Configured'} "${serverName}" in MCP client(s):\n`);
|
|
335
|
+
for (const r of results) {
|
|
336
|
+
console.log(` \x1b[1m${r.client}\x1b[0m: ${r.configPath}`);
|
|
337
|
+
console.log(` Command: ${r.serverEntry.command} ${r.serverEntry.args.join(' ')}\n`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
catch (err) {
|
|
341
|
+
console.error(`Failed to install client config:`, err.message || err);
|
|
342
|
+
process.exit(1);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
export async function uninstallServer(target, clientArg = 'all', flags = []) {
|
|
346
|
+
if (!target) {
|
|
347
|
+
console.error('Usage: mcponce uninstall <server-name> [client] [--dry-run] [--project]');
|
|
348
|
+
process.exit(1);
|
|
349
|
+
}
|
|
350
|
+
const dryRun = flags.includes('--dry-run');
|
|
351
|
+
const project = flags.includes('--project');
|
|
352
|
+
try {
|
|
353
|
+
const results = uninstallClientConfig({
|
|
354
|
+
serverName: target,
|
|
355
|
+
client: clientArg,
|
|
356
|
+
project,
|
|
357
|
+
dryRun
|
|
358
|
+
});
|
|
359
|
+
for (const r of results) {
|
|
360
|
+
if (r.removed) {
|
|
361
|
+
console.log(`\x1b[32m✔\x1b[0m Removed "${target}" from ${r.client} (${r.configPath})`);
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
console.log(`\x1b[90m○\x1b[0m "${target}" was not found in ${r.client} (${r.configPath})`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
console.error(`Failed to uninstall client config:`, err.message || err);
|
|
370
|
+
process.exit(1);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
export async function inspectServer(name) {
|
|
374
|
+
let target = name;
|
|
375
|
+
if (!target) {
|
|
376
|
+
const servers = await registry.getAll(true);
|
|
377
|
+
const running = servers.filter((s) => s.status === 'running');
|
|
378
|
+
if (running.length === 0) {
|
|
379
|
+
console.error('No running MCP servers found in central registry.');
|
|
380
|
+
console.error('Start a server first, or run inspect on a script: node server.js inspect');
|
|
381
|
+
process.exit(1);
|
|
382
|
+
}
|
|
383
|
+
target = running[0].name;
|
|
384
|
+
}
|
|
385
|
+
const server = await registry.get(target);
|
|
386
|
+
if (!server || server.status !== 'running' || !server.port) {
|
|
387
|
+
console.error(`Server "${target}" is not running.`);
|
|
388
|
+
process.exit(1);
|
|
389
|
+
}
|
|
390
|
+
const host = server.host || 'localhost';
|
|
391
|
+
const url = `http://${host}:${server.port}/inspect`;
|
|
392
|
+
console.log(`\n\x1b[1m\x1b[32m✔\x1b[0m Opening Web Inspector for "${target}" at: \x1b[4m\x1b[36m${url}\x1b[0m\n`);
|
|
393
|
+
const { openBrowser } = await import('../utils/browser.js');
|
|
394
|
+
await openBrowser(url);
|
|
395
|
+
}
|
|
396
|
+
export async function runOpenApiServer(specPathOrUrl, flags) {
|
|
397
|
+
if (!specPathOrUrl) {
|
|
398
|
+
console.error('Usage: mcponce openapi <url-or-file> [--port 3000] [--prefix prefix] [--name name] [--no-inspect]');
|
|
399
|
+
process.exit(1);
|
|
400
|
+
}
|
|
401
|
+
const portIdx = flags.indexOf('--port');
|
|
402
|
+
const port = portIdx !== -1 ? parseInt(flags[portIdx + 1], 10) : 3000;
|
|
403
|
+
const prefixIdx = flags.indexOf('--prefix');
|
|
404
|
+
const prefix = prefixIdx !== -1 ? flags[prefixIdx + 1] : undefined;
|
|
405
|
+
const nameIdx = flags.indexOf('--name');
|
|
406
|
+
const name = nameIdx !== -1 ? flags[nameIdx + 1] : 'openapi-mcp';
|
|
407
|
+
console.log(`\x1b[1mLoading OpenAPI specification:\x1b[0m ${specPathOrUrl}`);
|
|
408
|
+
const { createMcpServer } = await import('../index.js');
|
|
409
|
+
const app = createMcpServer({
|
|
410
|
+
name,
|
|
411
|
+
port: isNaN(port) ? 3000 : port
|
|
412
|
+
});
|
|
413
|
+
const count = await app.fromOpenApi(specPathOrUrl, { prefix });
|
|
414
|
+
console.log(`\x1b[32m✔\x1b[0m Loaded and registered \x1b[1m${count}\x1b[0m tools from OpenAPI specification.`);
|
|
415
|
+
const res = await app.start({ background: false });
|
|
416
|
+
const url = app.getInspectorUrl(res.host);
|
|
417
|
+
console.log(`\n\x1b[1m\x1b[32m✔\x1b[0m MCP server "${name}" running on http://${res.host}:${res.port}`);
|
|
418
|
+
console.log(`\x1b[1m\x1b[36m✔\x1b[0m Web Inspector available at: \x1b[4m\x1b[36m${url}\x1b[0m\n`);
|
|
419
|
+
if (!flags.includes('--no-inspect')) {
|
|
420
|
+
const { openBrowser } = await import('../utils/browser.js');
|
|
421
|
+
await openBrowser(url);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
export function printHelp() {
|
|
425
|
+
console.log(`\x1b[1mmcponce\x1b[0m - Central management CLI for local MCP servers\n`);
|
|
426
|
+
console.log('Usage:');
|
|
427
|
+
console.log(' mcponce <command> [options]\n');
|
|
428
|
+
console.log('Commands:');
|
|
429
|
+
console.log(' list, ls List all registered MCP servers and their statuses');
|
|
430
|
+
console.log(' status [name] Show status and runtime metrics for a server (or all)');
|
|
431
|
+
console.log(' inspect [name] Open interactive Web Inspector for running server');
|
|
432
|
+
console.log(' openapi <url-or-file> [options] Run instant MCP server from OpenAPI/Swagger spec');
|
|
433
|
+
console.log(' install <target> [client] Install server into Claude Desktop or Cursor configs');
|
|
434
|
+
console.log(' uninstall <server> [client] Remove server from Claude Desktop or Cursor configs');
|
|
435
|
+
console.log(' call <server> <tool> [params...] Execute a tool on a running server with parameters');
|
|
436
|
+
console.log(' tools <server> List available tools and schemas on a running server');
|
|
437
|
+
console.log(' stop <name | --all> Stop a running server instance');
|
|
438
|
+
console.log(' logs <name> [lines] View recent logs of a specific server');
|
|
439
|
+
console.log(' clean Remove stopped/inactive servers from registry');
|
|
440
|
+
console.log(' help, --help, -h Show this help message');
|
|
441
|
+
console.log(' version, --version, -v Show mcponce version\n');
|
|
442
|
+
}
|
|
443
|
+
export async function main(customArgs) {
|
|
444
|
+
const args = customArgs ?? process.argv.slice(2);
|
|
445
|
+
const cmd = args[0]?.toLowerCase();
|
|
446
|
+
switch (cmd) {
|
|
447
|
+
case undefined:
|
|
448
|
+
case 'list':
|
|
449
|
+
case 'ls':
|
|
450
|
+
await listServers();
|
|
451
|
+
break;
|
|
452
|
+
case 'status':
|
|
453
|
+
await showStatus(args[1]);
|
|
454
|
+
break;
|
|
455
|
+
case 'install':
|
|
456
|
+
await installServer(args[1], args[2] && !args[2].startsWith('--') ? args[2] : 'all', args.slice(args[2] && !args[2].startsWith('--') ? 3 : 2));
|
|
457
|
+
break;
|
|
458
|
+
case 'uninstall':
|
|
459
|
+
await uninstallServer(args[1], args[2] && !args[2].startsWith('--') ? args[2] : 'all', args.slice(args[2] && !args[2].startsWith('--') ? 3 : 2));
|
|
460
|
+
break;
|
|
461
|
+
case 'call':
|
|
462
|
+
await callServerTool(args[1], args[2], args.slice(3));
|
|
463
|
+
break;
|
|
464
|
+
case 'tools':
|
|
465
|
+
await listServerTools(args[1], args.slice(2));
|
|
466
|
+
break;
|
|
467
|
+
case 'stop':
|
|
468
|
+
await stopServer(args[1]);
|
|
469
|
+
break;
|
|
470
|
+
case 'logs':
|
|
471
|
+
await showLogs(args[1], args[2]);
|
|
472
|
+
break;
|
|
473
|
+
case 'inspect':
|
|
474
|
+
await inspectServer(args[1]);
|
|
475
|
+
break;
|
|
476
|
+
case 'openapi':
|
|
477
|
+
case 'from-openapi':
|
|
478
|
+
await runOpenApiServer(args[1], args.slice(2));
|
|
479
|
+
break;
|
|
480
|
+
case 'clean':
|
|
481
|
+
await cleanRegistry();
|
|
482
|
+
break;
|
|
483
|
+
case 'help':
|
|
484
|
+
case '--help':
|
|
485
|
+
case '-h':
|
|
486
|
+
printHelp();
|
|
487
|
+
break;
|
|
488
|
+
case 'version':
|
|
489
|
+
case '--version':
|
|
490
|
+
case '-v':
|
|
491
|
+
console.log('mcponce v1.0.0');
|
|
492
|
+
break;
|
|
493
|
+
default:
|
|
494
|
+
console.error(`Unknown command: ${args[0]}\n`);
|
|
495
|
+
printHelp();
|
|
496
|
+
process.exit(1);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const isDirectCli = typeof process !== 'undefined' &&
|
|
500
|
+
process.argv[1] &&
|
|
501
|
+
(process.argv[1].endsWith('bin.js') ||
|
|
502
|
+
process.argv[1].endsWith('bin.ts') ||
|
|
503
|
+
process.argv[1].endsWith('mcponce'));
|
|
504
|
+
if (isDirectCli) {
|
|
505
|
+
main().catch((err) => {
|
|
506
|
+
console.error('Error:', err.message || err);
|
|
507
|
+
process.exit(1);
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
//# sourceMappingURL=bin.js.map
|