invoke-mcp 0.0.0-stage → 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 CHANGED
@@ -1,3 +1,50 @@
1
- # Temporary Holding Version
1
+ # invoke-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ MCP connector for iNVoke: NVIDIA GPU compute your AI agent can call, paid per job in SOL.
4
+
5
+ ## Install
6
+
7
+ Claude Code:
8
+
9
+ claude mcp add invoke -- npx -y invoke-mcp
10
+
11
+ Codex:
12
+
13
+ codex mcp add invoke -- npx -y invoke-mcp
14
+
15
+ Start a new session, then:
16
+
17
+ 1. Ask your agent for its iNVoke wallet address and send it some SOL. About 0.02 SOL
18
+ covers a few jobs.
19
+ 2. Ask it to run a job, for example: "Use invoke to run this on the GPU: explain a
20
+ Solana PDA in two sentences."
21
+
22
+ ## The wallet
23
+
24
+ On first run the connector creates its own Solana wallet at `~/.invoke/wallet.json`.
25
+ It starts empty, so nothing can be spent until you fund it. Treat it like cash: only
26
+ send what you are happy for your agent to spend. The file is a standard Solana keypair,
27
+ so you can import it elsewhere or move funds out.
28
+
29
+ - A job costs the reward (0.001 SOL by default) plus a rent deposit of about 0.007 SOL.
30
+ The `close_job` tool returns the deposit once you have read the result.
31
+ - Spending is capped at 0.005 SOL reward per job and 0.05 SOL per session.
32
+
33
+ ## Tools
34
+
35
+ `get_network_info`, `list_jobs`, `get_job`, `submit_job`, `cancel_job`, `close_job`.
36
+
37
+ ## Settings (environment variables, all optional)
38
+
39
+ | Variable | Default | What it does |
40
+ | --- | --- | --- |
41
+ | `REQUESTER_KEYPAIR` | `~/.invoke/wallet.json` | Use a different Solana keypair file |
42
+ | `INVOKE_READ_ONLY` | off | `1` runs with no wallet: reading only |
43
+ | `SOLANA_RPC_URL` | public mainnet RPC | The public RPC is rate-limited; use your own for heavy use |
44
+ | `DEFAULT_MODEL` | `nvidia/nemotron-3.5-bolt-e4b` | Model used when the agent does not name one |
45
+ | `DEFAULT_REWARD_LAMPORTS` | `1000000` | Reward per job |
46
+ | `MAX_REWARD_LAMPORTS` | `5000000` | Highest reward the agent may set |
47
+ | `MAX_SESSION_SPEND_LAMPORTS` | `50000000` | Total the agent may commit per session |
48
+
49
+ Prompts and results are public, permanent and capped at 512 bytes each. Results are
50
+ written by third-party workers and are not verified on-chain. The program is unaudited.
package/dist/chain.js ADDED
@@ -0,0 +1,151 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import { homedir } from "node:os";
4
+ import anchor from "@anchor-lang/core";
5
+ import { Connection, Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
6
+ const { AnchorProvider, Program, Wallet, BN } = anchor;
7
+ const GENESIS = {
8
+ devnet: "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG",
9
+ "mainnet-beta": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d",
10
+ };
11
+ const DEFAULT_WALLET = "~/.invoke/wallet.json";
12
+ export const MAX_INPUT_BYTES = 512;
13
+ export const MAX_MODEL_BYTES = 64;
14
+ /** Program-enforced ceiling on a single reward (0.1 SOL). */
15
+ export const PROGRAM_MAX_REWARD = 100000000n;
16
+ /**
17
+ * Allocated size of a Job account: 8 discriminator + 106 fixed fields +
18
+ * three length-prefixed strings at their maximums (64 + 512 + 512 bytes).
19
+ */
20
+ export const JOB_ACCOUNT_BYTES = 8 + 106 + (4 + 64) + (4 + 512) + (4 + 512);
21
+ const expandHome = (p) => p.startsWith("~/") ? resolve(homedir(), p.slice(2)) : resolve(p);
22
+ const iso = (unix) => new Date(unix * 1000).toISOString();
23
+ export async function connect() {
24
+ // With no configuration the server reads mainnet through the public RPC.
25
+ const network = process.env.SOLANA_NETWORK || "mainnet-beta";
26
+ const rpcUrl = process.env.SOLANA_RPC_URL ||
27
+ (network === "mainnet-beta" ? "https://api.mainnet-beta.solana.com" : "");
28
+ if (!rpcUrl)
29
+ throw new Error("Set SOLANA_RPC_URL");
30
+ // The wallet jobs are paid from. By default the server keeps its own at
31
+ // ~/.invoke/wallet.json and creates it on first run; it starts empty, so nothing
32
+ // can be spent until the user funds it. REQUESTER_KEYPAIR points at another file,
33
+ // and INVOKE_READ_ONLY=1 runs with no wallet at all.
34
+ const readOnly = process.env.INVOKE_READ_ONLY === "1";
35
+ const keypairPath = readOnly ? null : expandHome(process.env.REQUESTER_KEYPAIR || DEFAULT_WALLET);
36
+ if (keypairPath && !existsSync(keypairPath)) {
37
+ if (process.env.REQUESTER_KEYPAIR)
38
+ throw new Error(`REQUESTER_KEYPAIR file not found: ${keypairPath}`);
39
+ mkdirSync(dirname(keypairPath), { recursive: true, mode: 0o700 });
40
+ writeFileSync(keypairPath, JSON.stringify(Array.from(Keypair.generate().secretKey)), { mode: 0o600 });
41
+ }
42
+ const connection = new Connection(rpcUrl, "confirmed");
43
+ const expected = process.env.SOLANA_GENESIS_HASH || GENESIS[network];
44
+ if (expected) {
45
+ const actual = await connection.getGenesisHash();
46
+ if (actual !== expected) {
47
+ throw new Error(`Wrong network: RPC genesis ${actual} does not match ${network}`);
48
+ }
49
+ }
50
+ else if (network === "localnet") {
51
+ const host = new URL(rpcUrl).hostname;
52
+ if (host !== "127.0.0.1" && host !== "localhost") {
53
+ throw new Error("SOLANA_NETWORK=localnet but SOLANA_RPC_URL is not a local address");
54
+ }
55
+ }
56
+ else {
57
+ throw new Error(`Unknown SOLANA_NETWORK "${network}"`);
58
+ }
59
+ const keypair = keypairPath
60
+ ? Keypair.fromSecretKey(Uint8Array.from(JSON.parse(readFileSync(keypairPath, "utf8"))))
61
+ : null;
62
+ const provider = new AnchorProvider(connection, new Wallet(keypair ?? Keypair.generate()), {
63
+ commitment: "confirmed",
64
+ });
65
+ const idl = JSON.parse(readFileSync(new URL("./idl.json", import.meta.url), "utf8"));
66
+ const program = new Program(idl, provider);
67
+ const programId = program.programId;
68
+ const pda = (...seeds) => PublicKey.findProgramAddressSync(seeds, programId)[0];
69
+ const configPda = pda(Buffer.from("config"));
70
+ const jobPda = (id) => {
71
+ const b = Buffer.alloc(8);
72
+ b.writeBigUInt64LE(id);
73
+ return pda(Buffer.from("job"), b);
74
+ };
75
+ const toView = (address, j) => {
76
+ const status = Object.keys(j.status)[0];
77
+ const worker = j.worker.equals(PublicKey.default) ? null : j.worker.toBase58();
78
+ return {
79
+ id: j.id.toString(),
80
+ status,
81
+ model: j.model,
82
+ input: j.input,
83
+ result: status === "fulfilled" ? j.result : null,
84
+ reward_lamports: j.reward.toString(),
85
+ requester: j.requester.toBase58(),
86
+ worker,
87
+ created_at: iso(j.createdAt.toNumber()),
88
+ fulfilled_at: status === "fulfilled" ? iso(j.fulfilledAt.toNumber()) : null,
89
+ account: address.toBase58(),
90
+ };
91
+ };
92
+ return {
93
+ network,
94
+ connection,
95
+ programId,
96
+ wallet: keypair?.publicKey ?? null,
97
+ walletPath: keypairPath,
98
+ async jobCount() {
99
+ const config = await program.account.config.fetchNullable(configPda);
100
+ if (!config)
101
+ throw new Error("The program is not initialised on this network.");
102
+ return BigInt(config.jobCount.toString());
103
+ },
104
+ async getJob(id) {
105
+ const address = jobPda(id);
106
+ const j = await program.account.job.fetchNullable(address);
107
+ return j ? toView(address, j) : null;
108
+ },
109
+ async listJobs() {
110
+ const all = await program.account.job.all();
111
+ return all
112
+ .map((a) => toView(a.publicKey, a.account))
113
+ .sort((a, b) => (BigInt(a.id) < BigInt(b.id) ? 1 : -1));
114
+ },
115
+ async listWorkers() {
116
+ const all = await program.account.worker.all();
117
+ return all.map(({ account: w }) => ({
118
+ authority: w.authority.toBase58(),
119
+ active: w.active,
120
+ hardware_self_reported: w.hardware || null,
121
+ jobs_fulfilled: w.jobsFulfilled.toString(),
122
+ }));
123
+ },
124
+ /** Rent the requester deposits for one job account (returned by close_job or cancel_job). */
125
+ async jobRentLamports() {
126
+ return BigInt(await connection.getMinimumBalanceForRentExemption(JOB_ACCOUNT_BYTES));
127
+ },
128
+ async submitJob(model, input, rewardLamports) {
129
+ if (!keypair)
130
+ throw new Error("This server is running read-only (INVOKE_READ_ONLY=1).");
131
+ const id = BigInt((await program.account.config.fetch(configPda)).jobCount.toString());
132
+ const signature = await program.methods
133
+ .requestJob(model, input, new BN(rewardLamports.toString()))
134
+ .accountsPartial({
135
+ config: configPda,
136
+ job: jobPda(id),
137
+ requester: keypair.publicKey,
138
+ systemProgram: SystemProgram.programId,
139
+ })
140
+ .rpc();
141
+ return { id, signature };
142
+ },
143
+ async cancelOrClose(kind, id) {
144
+ if (!keypair)
145
+ throw new Error("This server is running read-only (INVOKE_READ_ONLY=1).");
146
+ const accounts = { job: jobPda(id), requester: keypair.publicKey };
147
+ const method = kind === "cancel" ? program.methods.cancelJob() : program.methods.closeJob();
148
+ return method.accountsPartial(accounts).rpc();
149
+ },
150
+ };
151
+ }