@aifinpay/mcp 0.1.0-alpha.4 → 0.1.0-alpha.6
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/server.d.ts.map +1 -1
- package/dist/server.js +4 -0
- package/dist/server.js.map +1 -1
- package/dist/tools/agent-claim-self.d.ts +58 -0
- package/dist/tools/agent-claim-self.d.ts.map +1 -0
- package/dist/tools/agent-claim-self.js +189 -0
- package/dist/tools/agent-claim-self.js.map +1 -0
- package/package.json +2 -2
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAKnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAKnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAa7C;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAAC,MAAM,GAAE,SAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFxD;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,SAAS,CAAC;IAClB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9D"}
|
package/dist/server.js
CHANGED
|
@@ -5,6 +5,7 @@ import { payableFetchTool, runPayableFetch } from "./tools/payable-fetch.js";
|
|
|
5
5
|
import { agentAddressTool, runAgentAddress } from "./tools/agent-address.js";
|
|
6
6
|
import { agentQuoteTool, runAgentQuote } from "./tools/agent-quote.js";
|
|
7
7
|
import { agentCallTool, runAgentCall } from "./tools/agent-call.js";
|
|
8
|
+
import { agentClaimSelfTool, runAgentClaimSelf } from "./tools/agent-claim-self.js";
|
|
8
9
|
import { payWithSplitTool, runPayWithSplit, quoteSplitTool, runQuoteSplit, } from "./tools/pay-with-split.js";
|
|
9
10
|
/**
|
|
10
11
|
* Build an MCP server that wraps the AiFinPay agent SDK as MCP tools.
|
|
@@ -52,6 +53,7 @@ export async function createServer(config = {}) {
|
|
|
52
53
|
tools: [
|
|
53
54
|
agentAddressTool(),
|
|
54
55
|
agentCallTool(),
|
|
56
|
+
agentClaimSelfTool(),
|
|
55
57
|
payableFetchTool(),
|
|
56
58
|
agentQuoteTool(),
|
|
57
59
|
payWithSplitTool(),
|
|
@@ -67,6 +69,8 @@ export async function createServer(config = {}) {
|
|
|
67
69
|
return runAgentAddress(ctx, args ?? {});
|
|
68
70
|
case "agent_call":
|
|
69
71
|
return runAgentCall(ctx, args ?? {});
|
|
72
|
+
case "agent_claim_self":
|
|
73
|
+
return runAgentClaimSelf(ctx, args ?? {});
|
|
70
74
|
case "payable_fetch":
|
|
71
75
|
return runPayableFetch(ctx, args ?? {});
|
|
72
76
|
case "agent_quote":
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,gBAAgB,E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
* `agent_claim_self` — agent attaches itself to a user's AiFinPay account
|
|
4
|
+
* autonomously by signing a claim challenge with its own key.
|
|
5
|
+
*
|
|
6
|
+
* Flow (executed inside the tool, no copy-paste between UIs):
|
|
7
|
+
* 1. User signs in to /login on aifinpay.company → gets a magic-link
|
|
8
|
+
* email with URL like `https://aifinpay.company/api/auth/verify?token=…`
|
|
9
|
+
* 2. User pastes that URL to the agent: "claim yourself on my account
|
|
10
|
+
* using this magic link"
|
|
11
|
+
* 3. Agent calls this tool with the magic_link_url
|
|
12
|
+
* 4. Tool hits the magic link → server issues session cookie
|
|
13
|
+
* 5. Tool POSTs to /api/me/agents/challenge with the agent's EVM address
|
|
14
|
+
* 6. Tool signs the returned message with the agent's EVM key (EIP-191)
|
|
15
|
+
* 7. Tool POSTs to /api/me/agents/claim → server verifies signature →
|
|
16
|
+
* agent attached to user's watchlist
|
|
17
|
+
*
|
|
18
|
+
* Optional `label` field gives the agent a friendly name in the user's UI.
|
|
19
|
+
*
|
|
20
|
+
* Security model:
|
|
21
|
+
* - Magic-link URL is one-shot, 15-min TTL, identifies the user
|
|
22
|
+
* - Signature proves the agent holds the EVM private key
|
|
23
|
+
* - Combination: "this user OWNS this agent". Either alone is
|
|
24
|
+
* insufficient (signature alone can't pick an account; magic link
|
|
25
|
+
* alone can't prove key control).
|
|
26
|
+
*/
|
|
27
|
+
export declare function agentClaimSelfTool(): {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
inputSchema: {
|
|
31
|
+
type: string;
|
|
32
|
+
properties: {
|
|
33
|
+
magic_link_url: {
|
|
34
|
+
type: string;
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
37
|
+
label: {
|
|
38
|
+
type: string;
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
required: string[];
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export declare function runAgentClaimSelf(ctx: ToolContext, args: Record<string, unknown>): Promise<{
|
|
46
|
+
isError: boolean;
|
|
47
|
+
content: {
|
|
48
|
+
type: string;
|
|
49
|
+
text: string;
|
|
50
|
+
}[];
|
|
51
|
+
} | {
|
|
52
|
+
content: {
|
|
53
|
+
type: string;
|
|
54
|
+
text: string;
|
|
55
|
+
}[];
|
|
56
|
+
isError?: undefined;
|
|
57
|
+
}>;
|
|
58
|
+
//# sourceMappingURL=agent-claim-self.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-claim-self.d.ts","sourceRoot":"","sources":["../../src/tools/agent-claim-self.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB;;;;;;;;;;;;;;;;;EA6BjC;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;;GA0I9B"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agent_claim_self` — agent attaches itself to a user's AiFinPay account
|
|
3
|
+
* autonomously by signing a claim challenge with its own key.
|
|
4
|
+
*
|
|
5
|
+
* Flow (executed inside the tool, no copy-paste between UIs):
|
|
6
|
+
* 1. User signs in to /login on aifinpay.company → gets a magic-link
|
|
7
|
+
* email with URL like `https://aifinpay.company/api/auth/verify?token=…`
|
|
8
|
+
* 2. User pastes that URL to the agent: "claim yourself on my account
|
|
9
|
+
* using this magic link"
|
|
10
|
+
* 3. Agent calls this tool with the magic_link_url
|
|
11
|
+
* 4. Tool hits the magic link → server issues session cookie
|
|
12
|
+
* 5. Tool POSTs to /api/me/agents/challenge with the agent's EVM address
|
|
13
|
+
* 6. Tool signs the returned message with the agent's EVM key (EIP-191)
|
|
14
|
+
* 7. Tool POSTs to /api/me/agents/claim → server verifies signature →
|
|
15
|
+
* agent attached to user's watchlist
|
|
16
|
+
*
|
|
17
|
+
* Optional `label` field gives the agent a friendly name in the user's UI.
|
|
18
|
+
*
|
|
19
|
+
* Security model:
|
|
20
|
+
* - Magic-link URL is one-shot, 15-min TTL, identifies the user
|
|
21
|
+
* - Signature proves the agent holds the EVM private key
|
|
22
|
+
* - Combination: "this user OWNS this agent". Either alone is
|
|
23
|
+
* insufficient (signature alone can't pick an account; magic link
|
|
24
|
+
* alone can't prove key control).
|
|
25
|
+
*/
|
|
26
|
+
export function agentClaimSelfTool() {
|
|
27
|
+
return {
|
|
28
|
+
name: "agent_claim_self",
|
|
29
|
+
description: "Attach this agent to a user's AiFinPay account autonomously. " +
|
|
30
|
+
"Requires a magic-link URL the user got after signing in at " +
|
|
31
|
+
"https://aifinpay.company/login. The tool will use the link to " +
|
|
32
|
+
"establish a session, request a claim challenge for this agent's " +
|
|
33
|
+
"EVM address, sign it with the agent's key, and submit the proof. " +
|
|
34
|
+
"After this completes, the user's /me page lists this agent and " +
|
|
35
|
+
"they can view its activity at /agents/<evm-address>.",
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
magic_link_url: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "The URL the user received in the sign-in email. Looks like " +
|
|
42
|
+
"https://aifinpay.company/api/auth/verify?token=… — one-shot, " +
|
|
43
|
+
"expires 15 minutes after the user requested it.",
|
|
44
|
+
},
|
|
45
|
+
label: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "Optional human-friendly label (e.g. 'claude-research-bot').",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ["magic_link_url"],
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export async function runAgentClaimSelf(ctx, args) {
|
|
55
|
+
const magicLinkUrl = typeof args.magic_link_url === "string" ? args.magic_link_url : "";
|
|
56
|
+
const label = typeof args.label === "string" ? args.label : null;
|
|
57
|
+
if (!magicLinkUrl || !magicLinkUrl.includes("/api/auth/verify?token=")) {
|
|
58
|
+
return {
|
|
59
|
+
isError: true,
|
|
60
|
+
content: [{ type: "text", text: "magic_link_url required — should look like https://aifinpay.company/api/auth/verify?token=…" }],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// Derive API base from the magic link itself so demo can run against
|
|
64
|
+
// staging / localhost without extra config.
|
|
65
|
+
let apiBase;
|
|
66
|
+
try {
|
|
67
|
+
const u = new URL(magicLinkUrl);
|
|
68
|
+
apiBase = `${u.protocol}//${u.host}`;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return {
|
|
72
|
+
isError: true,
|
|
73
|
+
content: [{ type: "text", text: "magic_link_url is not a valid URL" }],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// ── 1. Establish session by hitting the magic link ─────────────────
|
|
77
|
+
let setCookie = null;
|
|
78
|
+
try {
|
|
79
|
+
const res = await fetch(magicLinkUrl, { redirect: "manual" });
|
|
80
|
+
setCookie = res.headers.get("set-cookie");
|
|
81
|
+
if (!setCookie) {
|
|
82
|
+
return {
|
|
83
|
+
isError: true,
|
|
84
|
+
content: [{ type: "text", text: `Magic link did not return a session cookie (HTTP ${res.status}). Link may be expired or already used.` }],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
return {
|
|
90
|
+
isError: true,
|
|
91
|
+
content: [{ type: "text", text: `Failed to fetch magic link: ${e.message}` }],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// Some setups split multiple cookies; grab the session one we care about.
|
|
95
|
+
const cookieHeader = setCookie.split(",").map((c) => c.trim().split(";")[0]).join("; ");
|
|
96
|
+
// Claim both chains (EVM + Solana). Each is its own challenge + sig.
|
|
97
|
+
// We try Polygon first because that's where live bridges settle today;
|
|
98
|
+
// Solana side is best-effort — if anything fails we still consider the
|
|
99
|
+
// overall claim successful as long as Polygon went through.
|
|
100
|
+
const evmAddr = ctx.agent.evmAddress;
|
|
101
|
+
const solAddr = ctx.agent.solanaAddress;
|
|
102
|
+
const innerAny = ctx.agent.inner;
|
|
103
|
+
const solSecret = innerAny.secretKey; // tweetnacl 64-byte secretKey
|
|
104
|
+
async function claimOne(address, sigFn) {
|
|
105
|
+
// 1) challenge
|
|
106
|
+
const cr = await fetch(`${apiBase}/api/me/agents/challenge`, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: { "content-type": "application/json", cookie: cookieHeader },
|
|
109
|
+
body: JSON.stringify({ address }),
|
|
110
|
+
});
|
|
111
|
+
const cj = (await cr.json());
|
|
112
|
+
if (!cr.ok || !cj.challenge_id || !cj.message) {
|
|
113
|
+
return { ok: false, reason: cj.error || `challenge HTTP ${cr.status}` };
|
|
114
|
+
}
|
|
115
|
+
// 2) sign
|
|
116
|
+
let sigPayload;
|
|
117
|
+
try {
|
|
118
|
+
sigPayload = await sigFn(cj.message);
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
return { ok: false, reason: `sign: ${e.message}` };
|
|
122
|
+
}
|
|
123
|
+
// 3) submit
|
|
124
|
+
const sr = await fetch(`${apiBase}/api/me/agents/claim`, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: { "content-type": "application/json", cookie: cookieHeader },
|
|
127
|
+
body: JSON.stringify({ challenge_id: cj.challenge_id, label, ...sigPayload }),
|
|
128
|
+
});
|
|
129
|
+
const sj = (await sr.json());
|
|
130
|
+
if (!sr.ok) {
|
|
131
|
+
return { ok: false, reason: sj.error + (sj.reason ? ` (${sj.reason})` : "") };
|
|
132
|
+
}
|
|
133
|
+
return { ok: true };
|
|
134
|
+
}
|
|
135
|
+
// ── 2. Claim Polygon EVM ───────────────────────────────────────────
|
|
136
|
+
const polRes = await claimOne(evmAddr, async (msg) => ({
|
|
137
|
+
signature: await ctx.agent.evmAccount.signMessage({ message: msg }),
|
|
138
|
+
}));
|
|
139
|
+
if (!polRes.ok) {
|
|
140
|
+
return {
|
|
141
|
+
isError: true,
|
|
142
|
+
content: [{ type: "text", text: `Polygon claim failed: ${polRes.reason}` }],
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
// ── 3. Claim Solana (best-effort) ──────────────────────────────────
|
|
146
|
+
let solRes;
|
|
147
|
+
try {
|
|
148
|
+
const nacl = (await import("tweetnacl")).default;
|
|
149
|
+
const bs58 = (await import("bs58")).default;
|
|
150
|
+
solRes = await claimOne(solAddr, async (msg) => {
|
|
151
|
+
const sig = nacl.sign.detached(Buffer.from(msg, "utf8"), solSecret);
|
|
152
|
+
return { signature_base58: bs58.encode(sig) };
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
solRes = { ok: false, reason: `solana_signer_unavailable: ${e.message}` };
|
|
157
|
+
}
|
|
158
|
+
// ── 4. Report ──────────────────────────────────────────────────────
|
|
159
|
+
try {
|
|
160
|
+
return {
|
|
161
|
+
content: [
|
|
162
|
+
{
|
|
163
|
+
type: "text",
|
|
164
|
+
text: JSON.stringify({
|
|
165
|
+
ok: true,
|
|
166
|
+
polygon_address: evmAddr,
|
|
167
|
+
polygon_claim: "ok",
|
|
168
|
+
solana_address: solAddr,
|
|
169
|
+
solana_claim: solRes.ok ? "ok" : `skipped (${solRes.reason})`,
|
|
170
|
+
label: label || null,
|
|
171
|
+
// Live bridges (io.net, Exa, Venice) settle on Polygon — fund
|
|
172
|
+
// the Polygon address with USDC for autonomous calls today.
|
|
173
|
+
// Solana is claimed for visibility; SOL-native settlement is
|
|
174
|
+
// available on bridges that advertise pay_solana in their 402.
|
|
175
|
+
funding_recommendation: `Send USDC on Polygon to ${evmAddr} (~0.5 USDC ≈ 20 calls). Optionally fund the Solana address with SOL to use Solana-native bridges.`,
|
|
176
|
+
next: `Visit ${apiBase}/agents/${evmAddr} (Polygon view) or ${apiBase}/agents/${solAddr} (Solana view). Watchlist: ${apiBase}/me.`,
|
|
177
|
+
}, null, 2),
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
return {
|
|
184
|
+
isError: true,
|
|
185
|
+
content: [{ type: "text", text: `Claim POST failed: ${e.message}` }],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=agent-claim-self.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-claim-self.js","sourceRoot":"","sources":["../../src/tools/agent-claim-self.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,IAAI,EAAE,kBAAkB;QACxB,WAAW,EACT,+DAA+D;YAC/D,6DAA6D;YAC7D,gEAAgE;YAChE,kEAAkE;YAClE,mEAAmE;YACnE,iEAAiE;YACjE,sDAAsD;QACxD,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,cAAc,EAAE;oBACd,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,6DAA6D;wBAC7D,+DAA+D;wBAC/D,iDAAiD;iBACpD;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6DAA6D;iBAC3E;aACF;YACD,QAAQ,EAAE,CAAC,gBAAgB,CAAC;SAC7B;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAgB,EAChB,IAA6B;IAE7B,MAAM,YAAY,GAAG,OAAO,IAAI,CAAC,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACxF,MAAM,KAAK,GAAG,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAEjE,IAAI,CAAC,YAAY,IAAI,CAAC,Y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DAA8D;wBAC9D,4DAA4D;wBAC5D,6DAA6D;wBAC7D,+DAA+D;wBAC/D,sBAAsB,EAAE,2BAA2B,OAAO,oGAAoG;wBAC9J,IAAI,EAAE,SAAS,OAAO,WAAW,OAAO,sBAAsB,OAAO,WAAW,OAAO,8BAA8B,OAAO,MAAM;qBACnI,EAAE,IAAI,EAAE,CAAC,CAAC;iBACZ;aACF;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,sBAAuB,CAAW,CAAC,OAAO,EAAE,EAAE,CAAC;SAChF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aifinpay/mcp",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
4
4
|
"description": "Pay-per-call MCP server for autonomous AI agents \u2014 installs in Claude Desktop / Cursor / Continue with one config block; on-chain settlement on Polygon and Solana via x402.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"bugs": "https://github.com/AiFinPay/sdk/issues",
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@aifinpay/agent": "^0.3.0-alpha.
|
|
60
|
+
"@aifinpay/agent": "^0.3.0-alpha.4",
|
|
61
61
|
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|