@elisym/mcp 0.4.0 → 0.5.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/index.js +59 -17
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { LIMITS, DEFAULT_KIND_OFFSET, SolanaPaymentStrategy, validateAgentName, RELAYS, toDTag, ElisymIdentity, ElisymClient, getProtocolProgramId, getProtocolConfig } from '@elisym/sdk';
|
|
2
|
+
import { LIMITS, DEFAULT_KIND_OFFSET, SolanaPaymentStrategy, makeCensor, DEFAULT_REDACT_PATHS, validateAgentName, RELAYS, toDTag, ElisymIdentity, ElisymClient, getProtocolProgramId, getProtocolConfig } from '@elisym/sdk';
|
|
3
3
|
import { generateKeyPairSigner, address, createSolanaRpcSubscriptions, sendAndConfirmTransactionFactory, getSignatureFromTransaction, pipe, createTransactionMessage, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstructions, signTransactionMessageWithSigners, createKeyPairSignerFromBytes, createSolanaRpc, isAddress } from '@solana/kit';
|
|
4
4
|
import bs58 from 'bs58';
|
|
5
5
|
import { Command } from 'commander';
|
|
@@ -15,6 +15,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
15
15
|
import { ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
16
16
|
import { z, ZodError } from 'zod';
|
|
17
17
|
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
18
|
+
import pino from 'pino';
|
|
18
19
|
import { randomBytes } from 'node:crypto';
|
|
19
20
|
import { getTransferSolInstruction } from '@solana-program/system';
|
|
20
21
|
|
|
@@ -535,6 +536,18 @@ async function installToConfig(path, entry) {
|
|
|
535
536
|
await safeRewriteJson(path, raw, config);
|
|
536
537
|
return true;
|
|
537
538
|
}
|
|
539
|
+
function createLogger(destination) {
|
|
540
|
+
const opts = {
|
|
541
|
+
name: "elisym-mcp",
|
|
542
|
+
level: process.env.LOG_LEVEL ?? "info",
|
|
543
|
+
redact: {
|
|
544
|
+
paths: DEFAULT_REDACT_PATHS,
|
|
545
|
+
censor: makeCensor()
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
return pino(opts, pino.destination(2));
|
|
549
|
+
}
|
|
550
|
+
var logger = createLogger();
|
|
538
551
|
|
|
539
552
|
// src/tools/types.ts
|
|
540
553
|
function defineTool(def) {
|
|
@@ -604,7 +617,10 @@ async function buildAgentInstance(name, config) {
|
|
|
604
617
|
secretKey: decoded
|
|
605
618
|
};
|
|
606
619
|
} catch {
|
|
607
|
-
|
|
620
|
+
logger.warn(
|
|
621
|
+
{ event: "invalid_solana_key", agent: name },
|
|
622
|
+
"invalid Solana key - payments disabled"
|
|
623
|
+
);
|
|
608
624
|
}
|
|
609
625
|
}
|
|
610
626
|
return {
|
|
@@ -637,8 +653,9 @@ var agentTools = [
|
|
|
637
653
|
if (input.activate) {
|
|
638
654
|
const envOverride = process.env.ELISYM_ALLOW_AGENT_SWITCH === "1";
|
|
639
655
|
if (envOverride) {
|
|
640
|
-
|
|
641
|
-
|
|
656
|
+
logger.warn(
|
|
657
|
+
{ event: "agent_switch_gate_bypassed", context: "create_agent" },
|
|
658
|
+
"ELISYM_ALLOW_AGENT_SWITCH override active - agent switch gate bypassed"
|
|
642
659
|
);
|
|
643
660
|
}
|
|
644
661
|
try {
|
|
@@ -689,8 +706,9 @@ Solana: ${solanaSigner.address}
|
|
|
689
706
|
async handler(ctx, input) {
|
|
690
707
|
const envOverride = process.env.ELISYM_ALLOW_AGENT_SWITCH === "1";
|
|
691
708
|
if (envOverride) {
|
|
692
|
-
|
|
693
|
-
|
|
709
|
+
logger.warn(
|
|
710
|
+
{ event: "agent_switch_gate_bypassed", context: "switch_agent" },
|
|
711
|
+
"ELISYM_ALLOW_AGENT_SWITCH override active - agent switch gate bypassed"
|
|
694
712
|
);
|
|
695
713
|
}
|
|
696
714
|
try {
|
|
@@ -1106,7 +1124,11 @@ async function executePaymentFlow(agent, paymentRequest, jobId, providerPubkey,
|
|
|
1106
1124
|
signature
|
|
1107
1125
|
);
|
|
1108
1126
|
} catch (e) {
|
|
1109
|
-
|
|
1127
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
1128
|
+
logger.error(
|
|
1129
|
+
{ event: "nostr_confirmation_failed", jobId, providerPubkey, err: message },
|
|
1130
|
+
"on-chain payment confirmed but Nostr confirmation failed"
|
|
1131
|
+
);
|
|
1110
1132
|
}
|
|
1111
1133
|
return signature;
|
|
1112
1134
|
}
|
|
@@ -1127,8 +1149,13 @@ function makePaymentFeedbackHandler(opts) {
|
|
|
1127
1149
|
return;
|
|
1128
1150
|
}
|
|
1129
1151
|
if (paying || paid) {
|
|
1130
|
-
|
|
1131
|
-
|
|
1152
|
+
logger.info(
|
|
1153
|
+
{
|
|
1154
|
+
event: "duplicate_payment_required",
|
|
1155
|
+
jobId: opts.jobId,
|
|
1156
|
+
state: paying ? "in-flight" : "paid"
|
|
1157
|
+
},
|
|
1158
|
+
"ignoring duplicate payment-required"
|
|
1132
1159
|
);
|
|
1133
1160
|
return;
|
|
1134
1161
|
}
|
|
@@ -1350,7 +1377,11 @@ var customerTools = [
|
|
|
1350
1377
|
])
|
|
1351
1378
|
);
|
|
1352
1379
|
} catch (e) {
|
|
1353
|
-
|
|
1380
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
1381
|
+
logger.error(
|
|
1382
|
+
{ event: "list_my_jobs_query_failed", err: message },
|
|
1383
|
+
"queryJobResults failed"
|
|
1384
|
+
);
|
|
1354
1385
|
}
|
|
1355
1386
|
}
|
|
1356
1387
|
let freetextSuspicious = false;
|
|
@@ -2037,8 +2068,9 @@ Balance: ${formatSol(BigInt(balance))} (${balance} lamports)`
|
|
|
2037
2068
|
}
|
|
2038
2069
|
const envOverride = process.env.ELISYM_ALLOW_WITHDRAWAL === "1";
|
|
2039
2070
|
if (envOverride) {
|
|
2040
|
-
|
|
2041
|
-
|
|
2071
|
+
logger.warn(
|
|
2072
|
+
{ event: "withdrawal_gate_bypassed", agent: agent.name },
|
|
2073
|
+
"ELISYM_ALLOW_WITHDRAWAL override active - withdrawal gate bypassed"
|
|
2042
2074
|
);
|
|
2043
2075
|
}
|
|
2044
2076
|
if (!envOverride && !agent.security.withdrawals_enabled) {
|
|
@@ -2166,7 +2198,9 @@ if (toolMap.size !== allTools.length) {
|
|
|
2166
2198
|
);
|
|
2167
2199
|
}
|
|
2168
2200
|
function safeError(context, e) {
|
|
2169
|
-
|
|
2201
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
2202
|
+
const stack = e instanceof Error ? e.stack : void 0;
|
|
2203
|
+
logger.error({ event: "tool_error", context, err: message, stack }, "tool call failed");
|
|
2170
2204
|
let msg;
|
|
2171
2205
|
if (e instanceof ZodError) {
|
|
2172
2206
|
const parts = e.issues.map((i) => {
|
|
@@ -2302,12 +2336,16 @@ async function startServer(ctx) {
|
|
|
2302
2336
|
return;
|
|
2303
2337
|
}
|
|
2304
2338
|
shuttingDown = true;
|
|
2305
|
-
|
|
2339
|
+
logger.info({ event: "shutdown", reason }, "shutting down");
|
|
2306
2340
|
for (const agent of ctx.registry.values()) {
|
|
2307
2341
|
try {
|
|
2308
2342
|
agent.client.close();
|
|
2309
2343
|
} catch (e) {
|
|
2310
|
-
|
|
2344
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
2345
|
+
logger.warn(
|
|
2346
|
+
{ event: "close_failed", agent: agent.name, err: message },
|
|
2347
|
+
"agent client close failed"
|
|
2348
|
+
);
|
|
2311
2349
|
}
|
|
2312
2350
|
if (agent.solanaKeypair) {
|
|
2313
2351
|
agent.solanaKeypair.secretKey.fill(0);
|
|
@@ -2319,10 +2357,14 @@ async function startServer(ctx) {
|
|
|
2319
2357
|
process.on("SIGINT", () => void shutdown("SIGINT", 0));
|
|
2320
2358
|
process.on("SIGTERM", () => void shutdown("SIGTERM", 0));
|
|
2321
2359
|
process.on("unhandledRejection", (r) => {
|
|
2322
|
-
|
|
2360
|
+
const message = r instanceof Error ? r.message : String(r);
|
|
2361
|
+
logger.error({ event: "unhandled_rejection", err: message }, "unhandled rejection");
|
|
2323
2362
|
});
|
|
2324
2363
|
process.on("uncaughtException", (e) => {
|
|
2325
|
-
|
|
2364
|
+
logger.error(
|
|
2365
|
+
{ event: "uncaught_exception", err: e.message, stack: e.stack },
|
|
2366
|
+
"uncaught exception"
|
|
2367
|
+
);
|
|
2326
2368
|
void shutdown("uncaughtException", 1);
|
|
2327
2369
|
});
|
|
2328
2370
|
const transport = new StdioServerTransport();
|