@openconductor/mcp-sdk 1.3.1 → 1.4.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 +57 -11
- package/dist/config/index.d.mts +70 -0
- package/dist/config/index.d.ts +70 -0
- package/dist/config/index.js +80 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/index.mjs +74 -0
- package/dist/config/index.mjs.map +1 -0
- package/dist/demo/index.d.mts +27 -0
- package/dist/demo/index.d.ts +27 -0
- package/dist/demo/index.js +136 -0
- package/dist/demo/index.js.map +1 -0
- package/dist/demo/index.mjs +129 -0
- package/dist/demo/index.mjs.map +1 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +288 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +278 -1
- package/dist/index.mjs.map +1 -1
- package/dist/payment/index.d.mts +66 -2
- package/dist/payment/index.d.ts +66 -2
- package/dist/payment/index.js +278 -0
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +277 -1
- package/dist/payment/index.mjs.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs.map +1 -1
- package/dist/telemetry/index.d.mts +34 -6
- package/dist/telemetry/index.d.ts +34 -6
- package/dist/telemetry/index.js +143 -0
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/index.mjs +143 -1
- package/dist/telemetry/index.mjs.map +1 -1
- package/package.json +12 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,194 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export { ZodError, z } from 'zod';
|
|
3
3
|
|
|
4
|
+
// src/config/index.ts
|
|
5
|
+
var globalConfig = {
|
|
6
|
+
apiKey: null,
|
|
7
|
+
demoMode: false,
|
|
8
|
+
serverName: "mcp-server",
|
|
9
|
+
serverVersion: "0.0.0",
|
|
10
|
+
initialized: false
|
|
11
|
+
};
|
|
12
|
+
var DEMO_BANNER = `
|
|
13
|
+
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
14
|
+
\u2502 \u2502
|
|
15
|
+
\u2502 \u{1F3AE} DEMO MODE ACTIVE \u2502
|
|
16
|
+
\u2502 \u2502
|
|
17
|
+
\u2502 The SDK is running without an API key. \u2502
|
|
18
|
+
\u2502 \u2022 Payment: Mock billing (always allowed, 9999 credits) \u2502
|
|
19
|
+
\u2502 \u2022 Telemetry: Logging to console only \u2502
|
|
20
|
+
\u2502 \u2022 All features work - no data sent to OpenConductor \u2502
|
|
21
|
+
\u2502 \u2502
|
|
22
|
+
\u2502 To enable production mode: \u2502
|
|
23
|
+
\u2502 1. Get a free API key at https://openconductor.ai \u2502
|
|
24
|
+
\u2502 2. Set OPENCONDUCTOR_API_KEY environment variable \u2502
|
|
25
|
+
\u2502 or pass apiKey to initOpenConductor() \u2502
|
|
26
|
+
\u2502 \u2502
|
|
27
|
+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
28
|
+
`;
|
|
29
|
+
var PRODUCTION_BANNER = `
|
|
30
|
+
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
31
|
+
\u2502 \u2705 OpenConductor SDK initialized (production mode) \u2502
|
|
32
|
+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
33
|
+
`;
|
|
34
|
+
function initOpenConductor(config = {}) {
|
|
35
|
+
const apiKey = config.apiKey ?? process.env.OPENCONDUCTOR_API_KEY ?? null;
|
|
36
|
+
const demoMode = config.demoMode === true || !apiKey;
|
|
37
|
+
globalConfig = {
|
|
38
|
+
apiKey: demoMode ? null : apiKey,
|
|
39
|
+
demoMode,
|
|
40
|
+
serverName: config.serverName ?? process.env.OPENCONDUCTOR_SERVER_NAME ?? "mcp-server",
|
|
41
|
+
serverVersion: config.serverVersion ?? process.env.npm_package_version ?? "0.0.0",
|
|
42
|
+
initialized: true
|
|
43
|
+
};
|
|
44
|
+
if (!config.quiet) {
|
|
45
|
+
if (demoMode) {
|
|
46
|
+
console.log(DEMO_BANNER);
|
|
47
|
+
} else {
|
|
48
|
+
console.log(PRODUCTION_BANNER);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return globalConfig;
|
|
52
|
+
}
|
|
53
|
+
function getConfig() {
|
|
54
|
+
if (!globalConfig.initialized) {
|
|
55
|
+
return initOpenConductor({ quiet: true });
|
|
56
|
+
}
|
|
57
|
+
return globalConfig;
|
|
58
|
+
}
|
|
59
|
+
function isDemoMode() {
|
|
60
|
+
return getConfig().demoMode;
|
|
61
|
+
}
|
|
62
|
+
function isInitialized() {
|
|
63
|
+
return globalConfig.initialized;
|
|
64
|
+
}
|
|
65
|
+
function resetConfig() {
|
|
66
|
+
globalConfig = {
|
|
67
|
+
apiKey: null,
|
|
68
|
+
demoMode: false,
|
|
69
|
+
serverName: "mcp-server",
|
|
70
|
+
serverVersion: "0.0.0",
|
|
71
|
+
initialized: false
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/demo/index.ts
|
|
76
|
+
var MOCK_BILLING_STATUS = {
|
|
77
|
+
allowed: true,
|
|
78
|
+
credits: 9999,
|
|
79
|
+
tier: "demo",
|
|
80
|
+
reason: void 0,
|
|
81
|
+
actionUrl: "https://openconductor.ai/pricing"
|
|
82
|
+
};
|
|
83
|
+
var MOCK_USER_BILLING = {
|
|
84
|
+
credits: 9999,
|
|
85
|
+
tier: "demo",
|
|
86
|
+
active: true
|
|
87
|
+
};
|
|
88
|
+
var MOCK_CREDIT_PACKS = {
|
|
89
|
+
starter: {
|
|
90
|
+
name: "Starter Pack",
|
|
91
|
+
credits: 100,
|
|
92
|
+
price: 9.99,
|
|
93
|
+
perCredit: 0.0999,
|
|
94
|
+
savings: 0,
|
|
95
|
+
bestFor: "Testing and small projects"
|
|
96
|
+
},
|
|
97
|
+
pro: {
|
|
98
|
+
name: "Pro Pack",
|
|
99
|
+
credits: 500,
|
|
100
|
+
price: 39.99,
|
|
101
|
+
perCredit: 0.0799,
|
|
102
|
+
savings: 20,
|
|
103
|
+
bestFor: "Growing projects",
|
|
104
|
+
popular: true
|
|
105
|
+
},
|
|
106
|
+
business: {
|
|
107
|
+
name: "Business Pack",
|
|
108
|
+
credits: 2e3,
|
|
109
|
+
price: 119.99,
|
|
110
|
+
perCredit: 0.0599,
|
|
111
|
+
savings: 40,
|
|
112
|
+
bestFor: "Production workloads"
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
function generateMockTimeline(days) {
|
|
116
|
+
const timeline = [];
|
|
117
|
+
const now = /* @__PURE__ */ new Date();
|
|
118
|
+
for (let i = days - 1; i >= 0; i--) {
|
|
119
|
+
const date = new Date(now);
|
|
120
|
+
date.setDate(date.getDate() - i);
|
|
121
|
+
timeline.push({
|
|
122
|
+
date: date.toISOString().split("T")[0],
|
|
123
|
+
used: Math.floor(Math.random() * 50) + 10,
|
|
124
|
+
purchased: i % 7 === 0 ? 500 : 0
|
|
125
|
+
// Weekly purchases
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return timeline;
|
|
129
|
+
}
|
|
130
|
+
function generateMockTransactions(count) {
|
|
131
|
+
const tools = ["analyze-data", "generate-report", "search-docs", "summarize", "translate"];
|
|
132
|
+
const transactions = [];
|
|
133
|
+
const now = /* @__PURE__ */ new Date();
|
|
134
|
+
for (let i = 0; i < count; i++) {
|
|
135
|
+
const isDebit = Math.random() > 0.2;
|
|
136
|
+
const date = new Date(now);
|
|
137
|
+
date.setHours(date.getHours() - i * 2);
|
|
138
|
+
transactions.push({
|
|
139
|
+
id: `txn_demo_${i}`,
|
|
140
|
+
amount: isDebit ? -(Math.floor(Math.random() * 20) + 1) : 500,
|
|
141
|
+
type: isDebit ? "usage" : "purchase",
|
|
142
|
+
tool: isDebit ? tools[Math.floor(Math.random() * tools.length)] : null,
|
|
143
|
+
createdAt: date.toISOString()
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return transactions;
|
|
147
|
+
}
|
|
148
|
+
function getMockAnalytics(period) {
|
|
149
|
+
const days = period === "24h" ? 1 : period === "7d" ? 7 : period === "30d" ? 30 : 90;
|
|
150
|
+
const timeline = generateMockTimeline(days);
|
|
151
|
+
const totalUsed = timeline.reduce((sum, d) => sum + d.used, 0);
|
|
152
|
+
const totalPurchased = timeline.reduce((sum, d) => sum + d.purchased, 0);
|
|
153
|
+
return {
|
|
154
|
+
period,
|
|
155
|
+
balance: 9999,
|
|
156
|
+
summary: {
|
|
157
|
+
totalUsed,
|
|
158
|
+
totalPurchased,
|
|
159
|
+
netChange: totalPurchased - totalUsed,
|
|
160
|
+
burnRate: totalUsed / days,
|
|
161
|
+
daysRemaining: Math.floor(9999 / (totalUsed / days)),
|
|
162
|
+
toolCount: 5,
|
|
163
|
+
transactionCount: days * 3
|
|
164
|
+
},
|
|
165
|
+
topTools: [
|
|
166
|
+
{ tool: "analyze-data", calls: 156, credits: 780 },
|
|
167
|
+
{ tool: "generate-report", calls: 89, credits: 445 },
|
|
168
|
+
{ tool: "search-docs", calls: 234, credits: 234 },
|
|
169
|
+
{ tool: "summarize", calls: 67, credits: 335 },
|
|
170
|
+
{ tool: "translate", calls: 45, credits: 90 }
|
|
171
|
+
],
|
|
172
|
+
usageTimeline: timeline,
|
|
173
|
+
recentTransactions: generateMockTransactions(10)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
var DEMO_PREFIX = "[\u{1F3AE} DEMO]";
|
|
177
|
+
var demoLogger = {
|
|
178
|
+
telemetry: (action, data) => {
|
|
179
|
+
console.log(`${DEMO_PREFIX} Telemetry ${action}:`, JSON.stringify(data, null, 2));
|
|
180
|
+
},
|
|
181
|
+
payment: (action, data) => {
|
|
182
|
+
console.log(`${DEMO_PREFIX} Payment ${action}:`, JSON.stringify(data, null, 2));
|
|
183
|
+
},
|
|
184
|
+
billing: (userId, result) => {
|
|
185
|
+
console.log(`${DEMO_PREFIX} Billing check for ${userId}: ALLOWED (demo mode)`);
|
|
186
|
+
},
|
|
187
|
+
deduct: (userId, credits, tool) => {
|
|
188
|
+
console.log(`${DEMO_PREFIX} Would deduct ${credits} credits from ${userId} for ${tool} (skipped in demo)`);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
4
192
|
// src/errors/codes.ts
|
|
5
193
|
var ErrorCodes = {
|
|
6
194
|
// JSON-RPC 2.0 Standard Errors
|
|
@@ -309,6 +497,17 @@ var SDK_VERSION = "1.0.0";
|
|
|
309
497
|
var DEFAULT_ENDPOINT = "https://api.openconductor.ai/functions/v1/telemetry";
|
|
310
498
|
var globalTelemetry = null;
|
|
311
499
|
function initTelemetry(config) {
|
|
500
|
+
const sdkConfig = getConfig();
|
|
501
|
+
if (isDemoMode()) {
|
|
502
|
+
globalTelemetry = new DemoTelemetry(
|
|
503
|
+
config?.serverName ?? sdkConfig.serverName,
|
|
504
|
+
config?.serverVersion ?? sdkConfig.serverVersion
|
|
505
|
+
);
|
|
506
|
+
return globalTelemetry;
|
|
507
|
+
}
|
|
508
|
+
if (!config?.apiKey) {
|
|
509
|
+
throw new Error("Telemetry requires apiKey in production mode. Set OPENCONDUCTOR_API_KEY or pass apiKey to initTelemetry().");
|
|
510
|
+
}
|
|
312
511
|
globalTelemetry = new Telemetry(config);
|
|
313
512
|
return globalTelemetry;
|
|
314
513
|
}
|
|
@@ -425,6 +624,61 @@ var Telemetry = class {
|
|
|
425
624
|
}
|
|
426
625
|
}
|
|
427
626
|
};
|
|
627
|
+
var DEMO_PREFIX2 = "[\u{1F3AE} DEMO]";
|
|
628
|
+
var DemoTelemetry = class {
|
|
629
|
+
serverName;
|
|
630
|
+
serverVersion;
|
|
631
|
+
buffer = [];
|
|
632
|
+
constructor(serverName, serverVersion) {
|
|
633
|
+
this.serverName = serverName;
|
|
634
|
+
this.serverVersion = serverVersion ?? "0.0.0";
|
|
635
|
+
console.log(`${DEMO_PREFIX2} Telemetry initialized (console mode) for ${serverName}`);
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Track a tool invocation - logs to console in demo mode
|
|
639
|
+
*/
|
|
640
|
+
trackToolCall(tool, duration, success, error) {
|
|
641
|
+
const metric = {
|
|
642
|
+
tool,
|
|
643
|
+
duration,
|
|
644
|
+
success,
|
|
645
|
+
...error && { error },
|
|
646
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
647
|
+
};
|
|
648
|
+
this.buffer.push(metric);
|
|
649
|
+
demoLogger.telemetry("track", {
|
|
650
|
+
tool,
|
|
651
|
+
duration: `${duration}ms`,
|
|
652
|
+
success,
|
|
653
|
+
...error && { error }
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Flush - in demo mode, just logs a summary
|
|
658
|
+
*/
|
|
659
|
+
async flush() {
|
|
660
|
+
if (this.buffer.length === 0) return;
|
|
661
|
+
const count = this.buffer.length;
|
|
662
|
+
demoLogger.telemetry("flush", {
|
|
663
|
+
message: `Would send ${count} metrics to OpenConductor`,
|
|
664
|
+
metrics: this.buffer.slice(0, 3),
|
|
665
|
+
...count > 3 && { more: `...and ${count - 3} more` }
|
|
666
|
+
});
|
|
667
|
+
this.buffer = [];
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Shutdown - no-op in demo mode
|
|
671
|
+
*/
|
|
672
|
+
shutdown() {
|
|
673
|
+
console.log(`${DEMO_PREFIX2} Telemetry shutdown`);
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Get buffered metrics (useful for testing/inspection)
|
|
677
|
+
*/
|
|
678
|
+
getBuffer() {
|
|
679
|
+
return [...this.buffer];
|
|
680
|
+
}
|
|
681
|
+
};
|
|
428
682
|
|
|
429
683
|
// src/server/index.ts
|
|
430
684
|
function createHealthCheck(info) {
|
|
@@ -527,6 +781,18 @@ function sanitizeInput(input) {
|
|
|
527
781
|
// src/payment/index.ts
|
|
528
782
|
var paymentConfig = null;
|
|
529
783
|
function initPayment(config) {
|
|
784
|
+
if (isDemoMode()) {
|
|
785
|
+
paymentConfig = {
|
|
786
|
+
apiKey: "demo_key",
|
|
787
|
+
apiUrl: "https://api.openconductor.ai",
|
|
788
|
+
testMode: true,
|
|
789
|
+
upgradeUrl: "https://openconductor.ai/pricing"
|
|
790
|
+
};
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
if (!config?.apiKey) {
|
|
794
|
+
throw new ConfigurationError("payment", "Payment requires apiKey in production mode. Set OPENCONDUCTOR_API_KEY or pass apiKey to initPayment().");
|
|
795
|
+
}
|
|
530
796
|
paymentConfig = {
|
|
531
797
|
apiUrl: "https://api.openconductor.ai",
|
|
532
798
|
testMode: false,
|
|
@@ -537,6 +803,10 @@ function getPaymentConfig() {
|
|
|
537
803
|
return paymentConfig;
|
|
538
804
|
}
|
|
539
805
|
async function checkBilling(params) {
|
|
806
|
+
if (isDemoMode()) {
|
|
807
|
+
demoLogger.billing(params.userId, MOCK_BILLING_STATUS);
|
|
808
|
+
return MOCK_BILLING_STATUS;
|
|
809
|
+
}
|
|
540
810
|
const config = paymentConfig;
|
|
541
811
|
if (!config) {
|
|
542
812
|
throw new ConfigurationError("payment", "Payment not initialized. Call initPayment() first.");
|
|
@@ -577,6 +847,10 @@ async function checkBilling(params) {
|
|
|
577
847
|
}
|
|
578
848
|
}
|
|
579
849
|
async function deductCredits(params) {
|
|
850
|
+
if (isDemoMode()) {
|
|
851
|
+
demoLogger.deduct(params.userId, params.credits, params.toolName);
|
|
852
|
+
return true;
|
|
853
|
+
}
|
|
580
854
|
const config = paymentConfig;
|
|
581
855
|
if (!config) return false;
|
|
582
856
|
if (config.testMode) return true;
|
|
@@ -666,6 +940,9 @@ async function canUserAccess(userId, requirement, toolName = "check") {
|
|
|
666
940
|
return checkBilling({ userId, requirement, toolName });
|
|
667
941
|
}
|
|
668
942
|
async function getUserBillingStatus(userId) {
|
|
943
|
+
if (isDemoMode()) {
|
|
944
|
+
return MOCK_USER_BILLING;
|
|
945
|
+
}
|
|
669
946
|
const config = paymentConfig;
|
|
670
947
|
if (!config) return null;
|
|
671
948
|
if (config.testMode) {
|
|
@@ -684,6 +961,6 @@ async function getUserBillingStatus(userId) {
|
|
|
684
961
|
}
|
|
685
962
|
}
|
|
686
963
|
|
|
687
|
-
export { AuthenticationError, AuthorizationError, ConfigurationError, DependencyError, ErrorCodes, InsufficientCreditsError, MCPError, PaymentRequiredError, RateLimitError, ResourceNotFoundError, SubscriptionRequiredError, Telemetry, TimeoutError, ToolExecutionError, ToolNotFoundError, ValidationError, canUserAccess, createHealthCheck, createLogger, createPaidTool, getPaymentConfig, getTelemetry, getUserBillingStatus, initPayment, initTelemetry, requirePayment, schemas, validate, validateInput, wrapTool };
|
|
964
|
+
export { AuthenticationError, AuthorizationError, ConfigurationError, DemoTelemetry, DependencyError, ErrorCodes, InsufficientCreditsError, MCPError, MOCK_BILLING_STATUS, MOCK_CREDIT_PACKS, MOCK_USER_BILLING, PaymentRequiredError, RateLimitError, ResourceNotFoundError, SubscriptionRequiredError, Telemetry, TimeoutError, ToolExecutionError, ToolNotFoundError, ValidationError, canUserAccess, createHealthCheck, createLogger, createPaidTool, demoLogger, getConfig, getMockAnalytics, getPaymentConfig, getTelemetry, getUserBillingStatus, initOpenConductor, initPayment, initTelemetry, isDemoMode, isInitialized, requirePayment, resetConfig, schemas, validate, validateInput, wrapTool };
|
|
688
965
|
//# sourceMappingURL=index.mjs.map
|
|
689
966
|
//# sourceMappingURL=index.mjs.map
|