@agent402-dev/bond-seller-mcp 0.1.0 → 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/README.md +6 -5
- package/dist/config.d.ts +2 -0
- package/dist/config.js +12 -6
- package/dist/seller.d.ts +11 -10
- package/dist/seller.js +2 -0
- package/dist/server.js +3 -2
- package/dist/tools.d.ts +2 -1
- package/dist/tools.js +4 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @agent402-dev/bond-seller-mcp
|
|
2
2
|
|
|
3
|
-
MCP server (stdio) that lets an AI agent **sell a job** backed by an [Agent402 Bond](https://github.com/agent402-dev/agent402-toolkit/tree/main/programs) deal on Solana: the seller locks a bond, the buyer locks a deposit, the agent does the work, delivery is marked on chain, and the buyer confirms and pays the balance or not. Amounts are in **USDC
|
|
3
|
+
MCP server (stdio) that lets an AI agent **sell a job** backed by an [Agent402 Bond](https://github.com/agent402-dev/agent402-toolkit/tree/main/programs) deal on Solana: the seller locks a bond, the buyer locks a deposit, the agent does the work, delivery is marked on chain, and the buyer confirms and pays the balance or not. Amounts are in **USDC** (default) or **PREQ** (`BOND_SELL_ASSET=PREQ`), from **your own seller wallet on your machine**. PREQ amounts are decimals of PREQ (6 decimals); buyers must enable PREQ deals in their own rules.
|
|
4
4
|
|
|
5
5
|
Part of the [Agent402 toolkit](https://github.com/agent402-dev/agent402-toolkit) (Solana).
|
|
6
6
|
Not related to `agent402.tools`, `@agents402` or other similarly named sites, accounts or projects, including projects named "a402" on other chains.
|
|
@@ -28,9 +28,10 @@ Not related to `agent402.tools`, `@agents402` or other similarly named sites, ac
|
|
|
28
28
|
|---|---|---|
|
|
29
29
|
| `BOND_SELLER_KEYPAIR_PATH` | Seller wallet key file (Solana CLI JSON). Create one with `init` | required |
|
|
30
30
|
| `BOND_SELLER_RPC_URL` | Solana mainnet RPC | required |
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
31
|
+
| `BOND_SELL_ASSET` | Deal asset: `USDC` or `PREQ` (Token-2022) | `USDC` |
|
|
32
|
+
| `BOND_SELL_PRICE` | Price per job, in the deal asset (`BOND_SELL_PRICE_USD` also works for USDC) | required |
|
|
33
|
+
| `BOND_SELL_BOND` | Your bond per job, in the deal asset (at most 20% of the price) | required |
|
|
34
|
+
| `BOND_SELL_DEPOSIT` | Buyer deposit, in the deal asset (part of the price) | `0` |
|
|
34
35
|
| `BOND_SELL_DELIVER_SECONDS` | Time you promise to deliver in | `3600` |
|
|
35
36
|
| `BOND_SELL_LATE_WINDOW_SECONDS` | Late window (0 to 7 days) | `0` |
|
|
36
37
|
| `BOND_SELL_PAY_WINDOW_SECONDS` | Time the buyer has to pay after confirming (1 to 30 days) | `86400` |
|
|
@@ -50,7 +51,7 @@ npx -y @agent402-dev/bond-seller-mcp init # creates ~/.agent402/seller-wall
|
|
|
50
51
|
claude mcp add bond-seller \
|
|
51
52
|
-e BOND_SELLER_KEYPAIR_PATH="$HOME/.agent402/seller-wallet.json" \
|
|
52
53
|
-e BOND_SELLER_RPC_URL=<your RPC URL> \
|
|
53
|
-
-e
|
|
54
|
+
-e BOND_SELL_PRICE=5 -e BOND_SELL_BOND=0.5 -e BOND_SELL_DEPOSIT=1 \
|
|
54
55
|
-e BOND_SELL_DESCRIPTION="<what you sell>" \
|
|
55
56
|
-- npx -y @agent402-dev/bond-seller-mcp
|
|
56
57
|
```
|
package/dist/config.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface SellerConfig {
|
|
|
5
5
|
rpcUrl: string | null;
|
|
6
6
|
storePath: string;
|
|
7
7
|
terms: BondTermsConfig | null;
|
|
8
|
+
/** Deal asset: USDC (default) or PREQ (Token-2022). Both have 6 decimals */
|
|
9
|
+
asset: 'USDC' | 'PREQ';
|
|
8
10
|
/** Problems that keep the seller tools off (shown by sell_status) */
|
|
9
11
|
problems: string[];
|
|
10
12
|
description?: string;
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Seller settings from environment variables. Amounts are
|
|
1
|
+
// Seller settings from environment variables. Amounts are decimals in the deal asset (USDC by default, or PREQ), kept in smallest units.
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { checkBondTerms } from '@agent402-dev/pay-server/bond';
|
|
@@ -19,12 +19,18 @@ export function sellerConfigFromEnv(env) {
|
|
|
19
19
|
const rpcUrl = env.BOND_SELLER_RPC_URL?.trim() || null;
|
|
20
20
|
if (!rpcUrl)
|
|
21
21
|
problems.push('BOND_SELLER_RPC_URL is not set');
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
22
|
+
const assetRaw = (env.BOND_SELL_ASSET ?? 'USDC').trim().toUpperCase();
|
|
23
|
+
const asset = assetRaw === 'PREQ' ? 'PREQ' : 'USDC';
|
|
24
|
+
if (assetRaw !== 'USDC' && assetRaw !== 'PREQ')
|
|
25
|
+
problems.push('BOND_SELL_ASSET must be USDC or PREQ');
|
|
26
|
+
// BOND_SELL_PRICE / _BOND / _DEPOSIT are in the deal asset; the *_USD names stay as USDC aliases
|
|
27
|
+
const usdOnly = (v) => (asset === 'USDC' ? v : undefined);
|
|
28
|
+
const price = usdcToAtomic(env.BOND_SELL_PRICE ?? usdOnly(env.BOND_SELL_PRICE_USD));
|
|
29
|
+
const bond = usdcToAtomic(env.BOND_SELL_BOND ?? usdOnly(env.BOND_SELL_BOND_USD));
|
|
30
|
+
const deposit = usdcToAtomic(env.BOND_SELL_DEPOSIT ?? usdOnly(env.BOND_SELL_DEPOSIT_USD) ?? '0');
|
|
25
31
|
let terms = null;
|
|
26
32
|
if (price === null || bond === null || deposit === null) {
|
|
27
|
-
problems.push(
|
|
33
|
+
problems.push(`BOND_SELL_PRICE and BOND_SELL_BOND must be set (${asset}, e.g. "5" and "0.5"); BOND_SELL_DEPOSIT is optional${asset === 'USDC' ? ' (the *_USD names also work)' : ''}`);
|
|
28
34
|
}
|
|
29
35
|
else {
|
|
30
36
|
terms = {
|
|
@@ -42,7 +48,7 @@ export function sellerConfigFromEnv(env) {
|
|
|
42
48
|
const port = env.BOND_SELL_PORT?.trim();
|
|
43
49
|
const buyers = env.BOND_SELL_BUYERS?.trim();
|
|
44
50
|
return {
|
|
45
|
-
keypairPath, rpcUrl, terms, problems,
|
|
51
|
+
keypairPath, rpcUrl, terms, problems, asset,
|
|
46
52
|
storePath: env.BOND_SELLER_STORE?.trim() || DEFAULT_STORE,
|
|
47
53
|
description: env.BOND_SELL_DESCRIPTION?.trim() || undefined,
|
|
48
54
|
buyers: buyers ? buyers.split(',').map((x) => x.trim()).filter(Boolean) : null,
|
package/dist/seller.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Keypair } from '@solana/web3.js';
|
|
2
|
+
import * as bond from '@agent402-dev/bond-client';
|
|
2
3
|
import { type BondJobStore } from '@agent402-dev/pay-server/bond';
|
|
3
4
|
import type { SellerConfig } from './config.js';
|
|
4
5
|
export declare function loadKeypair(path: string): Keypair;
|
|
@@ -25,13 +26,13 @@ export declare function buildSeller(cfg: SellerConfig, o: {
|
|
|
25
26
|
prepareOpen(buyer: string, meta?: unknown): Promise<{
|
|
26
27
|
deal: string;
|
|
27
28
|
nonce: string;
|
|
28
|
-
terms: Record<keyof
|
|
29
|
+
terms: Record<keyof bond.Terms, string>;
|
|
29
30
|
transaction: string;
|
|
30
31
|
}>;
|
|
31
|
-
requireOpen: (deal: string) => Promise<
|
|
32
|
-
readDeals: (deals: string[]) => Promise<Map<string,
|
|
32
|
+
requireOpen: (deal: string) => Promise<bond.DealState>;
|
|
33
|
+
readDeals: (deals: string[]) => Promise<Map<string, bond.DealState | null>>;
|
|
33
34
|
chainNow: () => Promise<bigint>;
|
|
34
|
-
matches(deal: string, d:
|
|
35
|
+
matches(deal: string, d: bond.DealState): Promise<boolean>;
|
|
35
36
|
markDelivered(deal: string): Promise<{
|
|
36
37
|
markTx: string | null;
|
|
37
38
|
alreadyMarked: boolean;
|
|
@@ -44,7 +45,7 @@ export declare function buildSeller(cfg: SellerConfig, o: {
|
|
|
44
45
|
} | {
|
|
45
46
|
onChain: true;
|
|
46
47
|
outcome: "open" | "delivered" | "buyer_default" | "disputed" | "seller_default" | "cancelled";
|
|
47
|
-
deal:
|
|
48
|
+
deal: bond.DealState;
|
|
48
49
|
timeline: {
|
|
49
50
|
now: bigint;
|
|
50
51
|
deliverBy: bigint;
|
|
@@ -52,9 +53,9 @@ export declare function buildSeller(cfg: SellerConfig, o: {
|
|
|
52
53
|
buyerDeadline: bigint;
|
|
53
54
|
settleBy: bigint;
|
|
54
55
|
lateDeduction: bigint;
|
|
55
|
-
settleNow:
|
|
56
|
+
settleNow: bond.Payout | null;
|
|
56
57
|
settleableFrom: bigint | null;
|
|
57
|
-
possibleActions:
|
|
58
|
+
possibleActions: bond.Action[];
|
|
58
59
|
} | null;
|
|
59
60
|
}>;
|
|
60
61
|
unmarked(): Promise<{
|
|
@@ -65,7 +66,7 @@ export declare function buildSeller(cfg: SellerConfig, o: {
|
|
|
65
66
|
settle(deal: string): Promise<{
|
|
66
67
|
buyerShareLeftInVault?: boolean | undefined;
|
|
67
68
|
settleTx: string;
|
|
68
|
-
outcome:
|
|
69
|
+
outcome: bond.Outcome;
|
|
69
70
|
toSeller: string;
|
|
70
71
|
toBuyer: string;
|
|
71
72
|
}>;
|
|
@@ -82,11 +83,11 @@ export declare function buildSeller(cfg: SellerConfig, o: {
|
|
|
82
83
|
status: "delivered" | "working" | "not_open" | "expired" | "settled" | "closed" | "error";
|
|
83
84
|
error?: string;
|
|
84
85
|
}[]>;
|
|
85
|
-
submit: (deal: string, result: unknown) => Promise<
|
|
86
|
+
submit: (deal: string, result: unknown) => Promise<bond.JobDelivery | {
|
|
86
87
|
status: number;
|
|
87
88
|
error: string;
|
|
88
89
|
}>;
|
|
89
|
-
decline: (deal: string, message?: string) => Promise<
|
|
90
|
+
decline: (deal: string, message?: string) => Promise<bond.JobDelivery | {
|
|
90
91
|
status: number;
|
|
91
92
|
error: string;
|
|
92
93
|
}>;
|
package/dist/seller.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// deadline and delivers a failure (neutral outcome), so the bond is not lost while this process keeps running.
|
|
4
4
|
import { readFileSync } from 'node:fs';
|
|
5
5
|
import { Keypair } from '@solana/web3.js';
|
|
6
|
+
import * as bond from '@agent402-dev/bond-client';
|
|
6
7
|
import { bondJobService, createBondSeller, JobPending } from '@agent402-dev/pay-server/bond';
|
|
7
8
|
import { fileBondStore } from './file-store.js';
|
|
8
9
|
export function loadKeypair(path) {
|
|
@@ -24,6 +25,7 @@ export function buildSeller(cfg, o) {
|
|
|
24
25
|
rpcUrl: cfg.rpcUrl,
|
|
25
26
|
signer: { publicKey: kp.publicKey, async signTransaction(tx) { tx.partialSign(kp); return tx; } },
|
|
26
27
|
terms: cfg.terms,
|
|
28
|
+
...(cfg.asset === 'PREQ' ? { mint: bond.MINTS.mainnet.PREQ, tokenProgram: bond.TOKEN_2022_PROGRAM_ID } : {}),
|
|
27
29
|
store: o.store ?? fileBondStore(cfg.storePath),
|
|
28
30
|
fetchImpl: o.fetchImpl,
|
|
29
31
|
});
|
package/dist/server.js
CHANGED
|
@@ -86,9 +86,10 @@ else {
|
|
|
86
86
|
const balances = built ? async () => {
|
|
87
87
|
const owner = built.seller.seller;
|
|
88
88
|
const sol = (await rpc('getBalance', [owner])).value;
|
|
89
|
-
const
|
|
89
|
+
const preq = config.asset === 'PREQ';
|
|
90
|
+
const ata = bond.associatedTokenAddress(new PublicKey(owner), preq ? bond.MINTS.mainnet.PREQ : bond.MINTS.mainnet.USDC, preq ? bond.TOKEN_2022_PROGRAM_ID : bond.TOKEN_PROGRAM_ID).toBase58();
|
|
90
91
|
const t = await rpc('getTokenAccountBalance', [ata]).catch(() => ({ value: { amount: '0' } }));
|
|
91
|
-
return { sol: `${sol / 1e9} SOL`,
|
|
92
|
+
return { sol: `${sol / 1e9} SOL`, token: `${Number(t.value.amount) / 1e6} ${config.asset}` };
|
|
92
93
|
} : undefined;
|
|
93
94
|
await createSellerServer({ config, built, balances, endpoint }, run).connect(new StdioServerTransport());
|
|
94
95
|
}
|
package/dist/tools.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export interface SellerServerDeps {
|
|
|
6
6
|
/** null when not configured (see config.problems) */
|
|
7
7
|
built: BuiltSeller | null;
|
|
8
8
|
/** SOL and USDC balance of the seller wallet, if available */
|
|
9
|
+
/** SOL and deal-asset balance (USDC or PREQ) of the seller wallet, if available */
|
|
9
10
|
balances?: () => Promise<{
|
|
10
11
|
sol: string;
|
|
11
|
-
|
|
12
|
+
token: string;
|
|
12
13
|
}>;
|
|
13
14
|
/** HTTP endpoint when the protocol is also served over HTTP */
|
|
14
15
|
endpoint?: string;
|
package/dist/tools.js
CHANGED
|
@@ -4,7 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
5
|
import { t2 } from '@agent402-dev/bond-client/rules';
|
|
6
6
|
const out = (obj, isError = false) => ({ content: [{ type: 'text', text: JSON.stringify(obj, (_k, v) => (typeof v === 'bigint' ? v.toString() : v), 2) }], ...(isError ? { isError } : {}) });
|
|
7
|
-
const
|
|
7
|
+
const units = (sym) => (v) => { const s = v.toString().padStart(7, '0'); const f = s.slice(-6).replace(/0+$/, ''); return `${BigInt(s.slice(0, -6)).toLocaleString('en-US')}${f ? `.${f}` : ''} ${sym}`; };
|
|
8
8
|
const iso = (t) => new Date(Number(t) * 1000).toISOString();
|
|
9
9
|
const GIVE_UP_BEFORE = 1800n;
|
|
10
10
|
/** One processOpenJobs at a time (the timer and tool calls share it). */
|
|
@@ -13,9 +13,10 @@ export function serialRunner(b) {
|
|
|
13
13
|
return () => { const r = tail.then(() => b.service.processOpenJobs()); tail = r.catch(() => undefined); return r; };
|
|
14
14
|
}
|
|
15
15
|
export function createSellerServer(d, run = d.built ? serialRunner(d.built) : null) {
|
|
16
|
-
const
|
|
16
|
+
const usdc = units(d.config.asset ?? 'USDC'); // amounts in the deal asset (USDC or PREQ)
|
|
17
|
+
const server = new McpServer({ name: 'agent402-bond-seller', version: '0.2.0' });
|
|
17
18
|
const off = () => out({ result: 'not_configured', problems: d.config.problems }, true);
|
|
18
|
-
server.tool('sell_status', 'Show this seller: wallet address, the job terms it sells (Agent402 Bond, USDC), how buyers reach it, balances and job counts. Read-only.', {}, async () => {
|
|
19
|
+
server.tool('sell_status', 'Show this seller: wallet address, the job terms it sells (Agent402 Bond, USDC or PREQ), how buyers reach it, balances and job counts. Read-only.', {}, async () => {
|
|
19
20
|
if (!d.built)
|
|
20
21
|
return out({ configured: false, problems: d.config.problems });
|
|
21
22
|
const q = d.built.seller.quote();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent402-dev/bond-seller-mcp",
|
|
3
|
-
"description": "MCP server that lets an AI agent sell jobs backed by Agent402 Bond deals on Solana (USDC), from your own seller wallet on your machine.",
|
|
3
|
+
"description": "MCP server that lets an AI agent sell jobs backed by Agent402 Bond deals on Solana (USDC or PREQ), from your own seller wallet on your machine.",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"mcp",
|
|
6
6
|
"solana",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@solana/web3.js": "^1.98.0",
|
|
27
27
|
"zod": "^4.6.7"
|
|
28
28
|
},
|
|
29
|
-
"version": "0.
|
|
29
|
+
"version": "0.2.0",
|
|
30
30
|
"author": "Agent402",
|
|
31
31
|
"license": "Apache-2.0",
|
|
32
32
|
"type": "module",
|