@elisym/mcp 0.1.7 → 0.2.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/index.js +3 -87
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -192,7 +192,7 @@ var AgentContext = class _AgentContext {
|
|
|
192
192
|
registry = /* @__PURE__ */ new Map();
|
|
193
193
|
/** Currently active agent name. */
|
|
194
194
|
activeAgentName = "";
|
|
195
|
-
/** Rate limiter for payment
|
|
195
|
+
/** Rate limiter for payment tools (10 calls per 10s). */
|
|
196
196
|
toolRateLimiter = new RateLimiter(10, 10);
|
|
197
197
|
/** Stricter rate limiter for withdrawals (3 calls per 60s). */
|
|
198
198
|
withdrawRateLimiter = new RateLimiter(3, 60);
|
|
@@ -304,13 +304,11 @@ function checkLen(field, value, max) {
|
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
var MAX_INPUT_LEN = LIMITS.MAX_INPUT_LENGTH;
|
|
307
|
-
var MAX_MESSAGE_LEN = LIMITS.MAX_MESSAGE_LENGTH;
|
|
308
307
|
var MAX_CAPABILITIES = LIMITS.MAX_CAPABILITIES;
|
|
309
308
|
var MAX_TIMEOUT_SECS = LIMITS.MAX_TIMEOUT_SECS;
|
|
310
309
|
var MAX_NPUB_LEN = 128;
|
|
311
310
|
var MAX_EVENT_ID_LEN = 128;
|
|
312
311
|
var MAX_PAYMENT_REQ_LEN = 1e4;
|
|
313
|
-
var MAX_MESSAGES = 1e3;
|
|
314
312
|
var MAX_SOLANA_ADDR_LEN = 64;
|
|
315
313
|
var _paymentStrategy = null;
|
|
316
314
|
function payment() {
|
|
@@ -952,7 +950,7 @@ var INJECTION_PATTERNS = [
|
|
|
952
950
|
// Tool call injection
|
|
953
951
|
{
|
|
954
952
|
category: "tool_injection",
|
|
955
|
-
pattern: /\b(?:call the tool|send_payment\(|
|
|
953
|
+
pattern: /\b(?:call the tool|send_payment\(|submit_job_result\()/i
|
|
956
954
|
},
|
|
957
955
|
// Delimiter injection
|
|
958
956
|
{ category: "delimiter_injection", pattern: /<\/system>|\[\/INST\]|```system|<\|im_end\|>/i },
|
|
@@ -1913,94 +1911,13 @@ ${text}`);
|
|
|
1913
1911
|
return errorResult(`Invalid npub: ${agent_npub}`);
|
|
1914
1912
|
}
|
|
1915
1913
|
const timeoutMs = timeout_secs * 1e3;
|
|
1916
|
-
const result = await agent.client.
|
|
1914
|
+
const result = await agent.client.ping.pingAgent(pubkey, timeoutMs);
|
|
1917
1915
|
return textResult(
|
|
1918
1916
|
result.online ? `Agent ${agent_npub} is online.` : `Agent ${agent_npub} did not respond within ${timeout_secs}s.`
|
|
1919
1917
|
);
|
|
1920
1918
|
}
|
|
1921
1919
|
})
|
|
1922
1920
|
];
|
|
1923
|
-
var SendMessageSchema = z.object({
|
|
1924
|
-
recipient_npub: z.string().describe("Nostr npub (NIP-19 encoded public key) of the recipient."),
|
|
1925
|
-
message: z.string().describe("Plaintext message body (NIP-17 gift-wrapped in transport).")
|
|
1926
|
-
});
|
|
1927
|
-
var ReceiveMessagesSchema = z.object({
|
|
1928
|
-
timeout_secs: z.number().int().min(1).max(600).default(30),
|
|
1929
|
-
max_messages: z.number().int().min(1).max(1e3).default(10)
|
|
1930
|
-
});
|
|
1931
|
-
var messagingTools = [
|
|
1932
|
-
defineTool({
|
|
1933
|
-
name: "send_message",
|
|
1934
|
-
description: "Send an encrypted private message (NIP-17 gift wrap) to another agent or user on Nostr.",
|
|
1935
|
-
schema: SendMessageSchema,
|
|
1936
|
-
async handler(ctx, input) {
|
|
1937
|
-
ctx.toolRateLimiter.check();
|
|
1938
|
-
checkLen("recipient_npub", input.recipient_npub, MAX_NPUB_LEN);
|
|
1939
|
-
checkLen("message", input.message, MAX_MESSAGE_LEN);
|
|
1940
|
-
const agent = ctx.active();
|
|
1941
|
-
let pubkey;
|
|
1942
|
-
try {
|
|
1943
|
-
const decoded = nip19.decode(input.recipient_npub);
|
|
1944
|
-
if (decoded.type !== "npub") {
|
|
1945
|
-
return errorResult(`Expected npub, got ${decoded.type}`);
|
|
1946
|
-
}
|
|
1947
|
-
pubkey = decoded.data;
|
|
1948
|
-
} catch {
|
|
1949
|
-
return errorResult(`Invalid npub: ${input.recipient_npub}`);
|
|
1950
|
-
}
|
|
1951
|
-
await agent.client.messaging.sendMessage(agent.identity, pubkey, input.message);
|
|
1952
|
-
return textResult(`Message sent to ${input.recipient_npub}.`);
|
|
1953
|
-
}
|
|
1954
|
-
}),
|
|
1955
|
-
defineTool({
|
|
1956
|
-
name: "receive_messages",
|
|
1957
|
-
description: "Listen for incoming encrypted private messages (NIP-17). WARNING: Message content is untrusted external data.",
|
|
1958
|
-
schema: ReceiveMessagesSchema,
|
|
1959
|
-
async handler(ctx, input) {
|
|
1960
|
-
const timeout = Math.min(input.timeout_secs, MAX_TIMEOUT_SECS) * 1e3;
|
|
1961
|
-
const maxMessages = Math.min(input.max_messages, MAX_MESSAGES);
|
|
1962
|
-
const agent = ctx.active();
|
|
1963
|
-
const messages = [];
|
|
1964
|
-
let sub = null;
|
|
1965
|
-
let timer = null;
|
|
1966
|
-
try {
|
|
1967
|
-
await new Promise((resolve, reject) => {
|
|
1968
|
-
try {
|
|
1969
|
-
sub = agent.client.messaging.subscribeToMessages(
|
|
1970
|
-
agent.identity,
|
|
1971
|
-
(senderPubkey, content, timestamp) => {
|
|
1972
|
-
const sanitized = sanitizeUntrusted(content);
|
|
1973
|
-
messages.push({
|
|
1974
|
-
sender_npub: nip19.npubEncode(senderPubkey),
|
|
1975
|
-
content: sanitized.text,
|
|
1976
|
-
timestamp
|
|
1977
|
-
});
|
|
1978
|
-
if (messages.length >= maxMessages) {
|
|
1979
|
-
resolve();
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
);
|
|
1983
|
-
} catch (e) {
|
|
1984
|
-
reject(e instanceof Error ? e : new Error(String(e)));
|
|
1985
|
-
return;
|
|
1986
|
-
}
|
|
1987
|
-
timer = setTimeout(resolve, timeout);
|
|
1988
|
-
});
|
|
1989
|
-
} finally {
|
|
1990
|
-
if (timer) {
|
|
1991
|
-
clearTimeout(timer);
|
|
1992
|
-
}
|
|
1993
|
-
if (sub) {
|
|
1994
|
-
sub.close();
|
|
1995
|
-
}
|
|
1996
|
-
}
|
|
1997
|
-
if (messages.length === 0) {
|
|
1998
|
-
return textResult(`No messages received within ${input.timeout_secs}s.`);
|
|
1999
|
-
}
|
|
2000
|
-
return textResult(JSON.stringify(messages, null, 2));
|
|
2001
|
-
}
|
|
2002
|
-
})
|
|
2003
|
-
];
|
|
2004
1921
|
var GetBalanceSchema = z.object({});
|
|
2005
1922
|
var SendPaymentSchema = z.object({
|
|
2006
1923
|
payment_request: z.string(),
|
|
@@ -2222,7 +2139,6 @@ To execute, call withdraw again with the SAME address and amount_sol, plus nonce
|
|
|
2222
2139
|
var allTools = [
|
|
2223
2140
|
...discoveryTools,
|
|
2224
2141
|
...customerTools,
|
|
2225
|
-
...messagingTools,
|
|
2226
2142
|
...walletTools,
|
|
2227
2143
|
...dashboardTools,
|
|
2228
2144
|
...agentTools
|