invoke-mcp 0.0.0-stage → 0.1.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 +39 -2
- package/dist/chain.js +143 -0
- package/dist/idl.json +1107 -0
- package/dist/server.js +266 -0
- package/package.json +40 -3
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# invoke-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MCP server for iNVoke: callable GPU compute on Solana. An AI agent connected to it can
|
|
4
|
+
read the on-chain job queue and, with a wallet, post GPU jobs, pay in SOL and read the
|
|
5
|
+
results.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Claude Code:
|
|
10
|
+
|
|
11
|
+
claude mcp add invoke -- npx -y invoke-mcp
|
|
12
|
+
|
|
13
|
+
Codex:
|
|
14
|
+
|
|
15
|
+
codex mcp add invoke -- npx -y invoke-mcp
|
|
16
|
+
|
|
17
|
+
With no configuration it reads Solana mainnet in read-only mode.
|
|
18
|
+
|
|
19
|
+
## Let the agent run jobs
|
|
20
|
+
|
|
21
|
+
Pass a Solana keypair file that holds only what the agent may spend:
|
|
22
|
+
|
|
23
|
+
claude mcp add invoke -e REQUESTER_KEYPAIR=$HOME/gpu-wallet.json -e ALLOW_MAINNET=1 -- npx -y invoke-mcp
|
|
24
|
+
|
|
25
|
+
Spending is capped per job (`MAX_REWARD_LAMPORTS`, default 5000000) and per server
|
|
26
|
+
run (`MAX_SESSION_SPEND_LAMPORTS`, default 50000000). Each job also locks a small
|
|
27
|
+
rent deposit, returned by the `close_job` tool.
|
|
28
|
+
|
|
29
|
+
## Tools
|
|
30
|
+
|
|
31
|
+
`get_network_info`, `list_jobs`, `get_job`, `submit_job`, `cancel_job`, `close_job`.
|
|
32
|
+
|
|
33
|
+
## Settings (environment variables)
|
|
34
|
+
|
|
35
|
+
`SOLANA_RPC_URL` (default: the public mainnet RPC, which is rate-limited),
|
|
36
|
+
`SOLANA_NETWORK`, `REQUESTER_KEYPAIR`, `ALLOW_MAINNET`, `DEFAULT_MODEL`,
|
|
37
|
+
`DEFAULT_REWARD_LAMPORTS`, `MAX_REWARD_LAMPORTS`, `MAX_SESSION_SPEND_LAMPORTS`.
|
|
38
|
+
|
|
39
|
+
Results are written by third-party workers and are not verified on-chain. The program
|
|
40
|
+
is unaudited. Prompts and results are public.
|
package/dist/chain.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { 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
|
+
export const MAX_INPUT_BYTES = 512;
|
|
12
|
+
export const MAX_MODEL_BYTES = 64;
|
|
13
|
+
/** Program-enforced ceiling on a single reward (0.1 SOL). */
|
|
14
|
+
export const PROGRAM_MAX_REWARD = 100000000n;
|
|
15
|
+
/**
|
|
16
|
+
* Allocated size of a Job account: 8 discriminator + 106 fixed fields +
|
|
17
|
+
* three length-prefixed strings at their maximums (64 + 512 + 512 bytes).
|
|
18
|
+
*/
|
|
19
|
+
export const JOB_ACCOUNT_BYTES = 8 + 106 + (4 + 64) + (4 + 512) + (4 + 512);
|
|
20
|
+
const expandHome = (p) => p.startsWith("~/") ? resolve(homedir(), p.slice(2)) : resolve(p);
|
|
21
|
+
const iso = (unix) => new Date(unix * 1000).toISOString();
|
|
22
|
+
export async function connect() {
|
|
23
|
+
// With no configuration the server reads mainnet through the public RPC.
|
|
24
|
+
const network = process.env.SOLANA_NETWORK || "mainnet-beta";
|
|
25
|
+
const rpcUrl = process.env.SOLANA_RPC_URL ||
|
|
26
|
+
(network === "mainnet-beta" ? "https://api.mainnet-beta.solana.com" : "");
|
|
27
|
+
if (!rpcUrl)
|
|
28
|
+
throw new Error("Set SOLANA_RPC_URL");
|
|
29
|
+
const keypairPath = process.env.REQUESTER_KEYPAIR;
|
|
30
|
+
// Reading mainnet is harmless. Spending on it must be switched on explicitly.
|
|
31
|
+
if (network === "mainnet-beta" && keypairPath && process.env.ALLOW_MAINNET !== "1") {
|
|
32
|
+
throw new Error("A wallet is configured for mainnet-beta: set ALLOW_MAINNET=1 to allow spending real SOL");
|
|
33
|
+
}
|
|
34
|
+
const connection = new Connection(rpcUrl, "confirmed");
|
|
35
|
+
const expected = process.env.SOLANA_GENESIS_HASH || GENESIS[network];
|
|
36
|
+
if (expected) {
|
|
37
|
+
const actual = await connection.getGenesisHash();
|
|
38
|
+
if (actual !== expected) {
|
|
39
|
+
throw new Error(`Wrong network: RPC genesis ${actual} does not match ${network}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (network === "localnet") {
|
|
43
|
+
const host = new URL(rpcUrl).hostname;
|
|
44
|
+
if (host !== "127.0.0.1" && host !== "localhost") {
|
|
45
|
+
throw new Error("SOLANA_NETWORK=localnet but SOLANA_RPC_URL is not a local address");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
throw new Error(`Unknown SOLANA_NETWORK "${network}"`);
|
|
50
|
+
}
|
|
51
|
+
// Without a keypair the server is read-only; a throwaway key satisfies the provider.
|
|
52
|
+
const keypair = keypairPath
|
|
53
|
+
? Keypair.fromSecretKey(Uint8Array.from(JSON.parse(readFileSync(expandHome(keypairPath), "utf8"))))
|
|
54
|
+
: null;
|
|
55
|
+
const provider = new AnchorProvider(connection, new Wallet(keypair ?? Keypair.generate()), {
|
|
56
|
+
commitment: "confirmed",
|
|
57
|
+
});
|
|
58
|
+
const idl = JSON.parse(readFileSync(new URL("./idl.json", import.meta.url), "utf8"));
|
|
59
|
+
const program = new Program(idl, provider);
|
|
60
|
+
const programId = program.programId;
|
|
61
|
+
const pda = (...seeds) => PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
62
|
+
const configPda = pda(Buffer.from("config"));
|
|
63
|
+
const jobPda = (id) => {
|
|
64
|
+
const b = Buffer.alloc(8);
|
|
65
|
+
b.writeBigUInt64LE(id);
|
|
66
|
+
return pda(Buffer.from("job"), b);
|
|
67
|
+
};
|
|
68
|
+
const toView = (address, j) => {
|
|
69
|
+
const status = Object.keys(j.status)[0];
|
|
70
|
+
const worker = j.worker.equals(PublicKey.default) ? null : j.worker.toBase58();
|
|
71
|
+
return {
|
|
72
|
+
id: j.id.toString(),
|
|
73
|
+
status,
|
|
74
|
+
model: j.model,
|
|
75
|
+
input: j.input,
|
|
76
|
+
result: status === "fulfilled" ? j.result : null,
|
|
77
|
+
reward_lamports: j.reward.toString(),
|
|
78
|
+
requester: j.requester.toBase58(),
|
|
79
|
+
worker,
|
|
80
|
+
created_at: iso(j.createdAt.toNumber()),
|
|
81
|
+
fulfilled_at: status === "fulfilled" ? iso(j.fulfilledAt.toNumber()) : null,
|
|
82
|
+
account: address.toBase58(),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
network,
|
|
87
|
+
connection,
|
|
88
|
+
programId,
|
|
89
|
+
wallet: keypair?.publicKey ?? null,
|
|
90
|
+
async jobCount() {
|
|
91
|
+
const config = await program.account.config.fetchNullable(configPda);
|
|
92
|
+
if (!config)
|
|
93
|
+
throw new Error("The program is not initialised on this network.");
|
|
94
|
+
return BigInt(config.jobCount.toString());
|
|
95
|
+
},
|
|
96
|
+
async getJob(id) {
|
|
97
|
+
const address = jobPda(id);
|
|
98
|
+
const j = await program.account.job.fetchNullable(address);
|
|
99
|
+
return j ? toView(address, j) : null;
|
|
100
|
+
},
|
|
101
|
+
async listJobs() {
|
|
102
|
+
const all = await program.account.job.all();
|
|
103
|
+
return all
|
|
104
|
+
.map((a) => toView(a.publicKey, a.account))
|
|
105
|
+
.sort((a, b) => (BigInt(a.id) < BigInt(b.id) ? 1 : -1));
|
|
106
|
+
},
|
|
107
|
+
async listWorkers() {
|
|
108
|
+
const all = await program.account.worker.all();
|
|
109
|
+
return all.map(({ account: w }) => ({
|
|
110
|
+
authority: w.authority.toBase58(),
|
|
111
|
+
active: w.active,
|
|
112
|
+
hardware_self_reported: w.hardware || null,
|
|
113
|
+
jobs_fulfilled: w.jobsFulfilled.toString(),
|
|
114
|
+
}));
|
|
115
|
+
},
|
|
116
|
+
/** Rent the requester deposits for one job account (returned by close_job or cancel_job). */
|
|
117
|
+
async jobRentLamports() {
|
|
118
|
+
return BigInt(await connection.getMinimumBalanceForRentExemption(JOB_ACCOUNT_BYTES));
|
|
119
|
+
},
|
|
120
|
+
async submitJob(model, input, rewardLamports) {
|
|
121
|
+
if (!keypair)
|
|
122
|
+
throw new Error("This server is read-only: no REQUESTER_KEYPAIR is configured.");
|
|
123
|
+
const id = BigInt((await program.account.config.fetch(configPda)).jobCount.toString());
|
|
124
|
+
const signature = await program.methods
|
|
125
|
+
.requestJob(model, input, new BN(rewardLamports.toString()))
|
|
126
|
+
.accountsPartial({
|
|
127
|
+
config: configPda,
|
|
128
|
+
job: jobPda(id),
|
|
129
|
+
requester: keypair.publicKey,
|
|
130
|
+
systemProgram: SystemProgram.programId,
|
|
131
|
+
})
|
|
132
|
+
.rpc();
|
|
133
|
+
return { id, signature };
|
|
134
|
+
},
|
|
135
|
+
async cancelOrClose(kind, id) {
|
|
136
|
+
if (!keypair)
|
|
137
|
+
throw new Error("This server is read-only: no REQUESTER_KEYPAIR is configured.");
|
|
138
|
+
const accounts = { job: jobPda(id), requester: keypair.publicKey };
|
|
139
|
+
const method = kind === "cancel" ? program.methods.cancelJob() : program.methods.closeJob();
|
|
140
|
+
return method.accountsPartial(accounts).rpc();
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|