invoke-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 +26 -16
- package/dist/chain.js +18 -10
- package/dist/server.js +17 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# invoke-mcp
|
|
2
2
|
|
|
3
|
-
MCP
|
|
4
|
-
read the on-chain job queue and, with a wallet, post GPU jobs, pay in SOL and read the
|
|
5
|
-
results.
|
|
3
|
+
MCP connector for iNVoke: NVIDIA GPU compute your AI agent can call, paid per job in SOL.
|
|
6
4
|
|
|
7
5
|
## Install
|
|
8
6
|
|
|
@@ -14,27 +12,39 @@ Codex:
|
|
|
14
12
|
|
|
15
13
|
codex mcp add invoke -- npx -y invoke-mcp
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
Start a new session, then:
|
|
18
16
|
|
|
19
|
-
|
|
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."
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
## The wallet
|
|
22
23
|
|
|
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.
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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.
|
|
28
32
|
|
|
29
33
|
## Tools
|
|
30
34
|
|
|
31
35
|
`get_network_info`, `list_jobs`, `get_job`, `submit_job`, `cancel_job`, `close_job`.
|
|
32
36
|
|
|
33
|
-
## Settings (environment variables)
|
|
37
|
+
## Settings (environment variables, all optional)
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
`
|
|
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 |
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
|
|
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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import anchor from "@anchor-lang/core";
|
|
5
5
|
import { Connection, Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
|
|
@@ -8,6 +8,7 @@ const GENESIS = {
|
|
|
8
8
|
devnet: "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG",
|
|
9
9
|
"mainnet-beta": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d",
|
|
10
10
|
};
|
|
11
|
+
const DEFAULT_WALLET = "~/.invoke/wallet.json";
|
|
11
12
|
export const MAX_INPUT_BYTES = 512;
|
|
12
13
|
export const MAX_MODEL_BYTES = 64;
|
|
13
14
|
/** Program-enforced ceiling on a single reward (0.1 SOL). */
|
|
@@ -26,10 +27,17 @@ export async function connect() {
|
|
|
26
27
|
(network === "mainnet-beta" ? "https://api.mainnet-beta.solana.com" : "");
|
|
27
28
|
if (!rpcUrl)
|
|
28
29
|
throw new Error("Set SOLANA_RPC_URL");
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
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 });
|
|
33
41
|
}
|
|
34
42
|
const connection = new Connection(rpcUrl, "confirmed");
|
|
35
43
|
const expected = process.env.SOLANA_GENESIS_HASH || GENESIS[network];
|
|
@@ -48,9 +56,8 @@ export async function connect() {
|
|
|
48
56
|
else {
|
|
49
57
|
throw new Error(`Unknown SOLANA_NETWORK "${network}"`);
|
|
50
58
|
}
|
|
51
|
-
// Without a keypair the server is read-only; a throwaway key satisfies the provider.
|
|
52
59
|
const keypair = keypairPath
|
|
53
|
-
? Keypair.fromSecretKey(Uint8Array.from(JSON.parse(readFileSync(
|
|
60
|
+
? Keypair.fromSecretKey(Uint8Array.from(JSON.parse(readFileSync(keypairPath, "utf8"))))
|
|
54
61
|
: null;
|
|
55
62
|
const provider = new AnchorProvider(connection, new Wallet(keypair ?? Keypair.generate()), {
|
|
56
63
|
commitment: "confirmed",
|
|
@@ -87,6 +94,7 @@ export async function connect() {
|
|
|
87
94
|
connection,
|
|
88
95
|
programId,
|
|
89
96
|
wallet: keypair?.publicKey ?? null,
|
|
97
|
+
walletPath: keypairPath,
|
|
90
98
|
async jobCount() {
|
|
91
99
|
const config = await program.account.config.fetchNullable(configPda);
|
|
92
100
|
if (!config)
|
|
@@ -119,7 +127,7 @@ export async function connect() {
|
|
|
119
127
|
},
|
|
120
128
|
async submitJob(model, input, rewardLamports) {
|
|
121
129
|
if (!keypair)
|
|
122
|
-
throw new Error("This server is read-only
|
|
130
|
+
throw new Error("This server is running read-only (INVOKE_READ_ONLY=1).");
|
|
123
131
|
const id = BigInt((await program.account.config.fetch(configPda)).jobCount.toString());
|
|
124
132
|
const signature = await program.methods
|
|
125
133
|
.requestJob(model, input, new BN(rewardLamports.toString()))
|
|
@@ -134,7 +142,7 @@ export async function connect() {
|
|
|
134
142
|
},
|
|
135
143
|
async cancelOrClose(kind, id) {
|
|
136
144
|
if (!keypair)
|
|
137
|
-
throw new Error("This server is read-only
|
|
145
|
+
throw new Error("This server is running read-only (INVOKE_READ_ONLY=1).");
|
|
138
146
|
const accounts = { job: jobPda(id), requester: keypair.publicKey };
|
|
139
147
|
const method = kind === "cancel" ? program.methods.cancelJob() : program.methods.closeJob();
|
|
140
148
|
return method.accountsPartial(accounts).rpc();
|
package/dist/server.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* Lets an AI agent post a GPU job to the on-chain queue, pay for it in SOL,
|
|
6
6
|
* and read the result. Runs over stdio.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* and are bounded by MAX_REWARD_LAMPORTS (per job) and MAX_SESSION_SPEND_LAMPORTS
|
|
8
|
+
* The server keeps its own wallet (~/.invoke/wallet.json, created empty on first
|
|
9
|
+
* run). Tools that spend SOL draw on it and are bounded by MAX_REWARD_LAMPORTS (per job) and MAX_SESSION_SPEND_LAMPORTS
|
|
10
10
|
* (total for the life of this process).
|
|
11
11
|
*
|
|
12
12
|
* stdout carries the protocol, so all logging goes to stderr.
|
|
@@ -46,14 +46,14 @@ async function main() {
|
|
|
46
46
|
// Rewards plus rent deposits this process has committed. Refunds are not subtracted,
|
|
47
47
|
// so the cap is conservative.
|
|
48
48
|
let sessionSpend = 0n;
|
|
49
|
-
const server = new McpServer({ name: "invoke", version: "0.
|
|
49
|
+
const server = new McpServer({ name: "invoke", version: "0.2.0" });
|
|
50
50
|
const jobId = z
|
|
51
51
|
.string()
|
|
52
52
|
.regex(/^\d{1,18}$/)
|
|
53
53
|
.describe("Job id, a whole number as a string");
|
|
54
54
|
server.registerTool("get_network_info", {
|
|
55
55
|
title: "Network info",
|
|
56
|
-
description: "Shows which Solana network and program this server talks to, the GPU workers and the hardware they report,
|
|
56
|
+
description: "Shows which Solana network and program this server talks to, the GPU workers and the hardware they report, this server's wallet address and balance (the address the user funds to run jobs), and the spending limits. Call this first.",
|
|
57
57
|
inputSchema: {},
|
|
58
58
|
annotations: { readOnlyHint: true },
|
|
59
59
|
}, async () => {
|
|
@@ -71,7 +71,14 @@ async function main() {
|
|
|
71
71
|
jobs_posted: jobCount.toString(),
|
|
72
72
|
workers,
|
|
73
73
|
wallet: chain.wallet
|
|
74
|
-
? {
|
|
74
|
+
? {
|
|
75
|
+
address: chain.wallet.toBase58(),
|
|
76
|
+
balance_sol: sol(balance),
|
|
77
|
+
key_file: chain.walletPath,
|
|
78
|
+
how_to_fund: balance < rent + defaultReward
|
|
79
|
+
? `Send SOL to ${chain.wallet.toBase58()} to run jobs. One job needs about ${sol(rent + defaultReward)} SOL, most of it a deposit that close_job returns.`
|
|
80
|
+
: "Funded. Top up by sending SOL to the address.",
|
|
81
|
+
}
|
|
75
82
|
: null,
|
|
76
83
|
can_submit: !!chain.wallet,
|
|
77
84
|
default_model: defaultModel || null,
|
|
@@ -165,7 +172,7 @@ async function main() {
|
|
|
165
172
|
}, async ({ prompt, model, reward_lamports, wait_seconds }) => {
|
|
166
173
|
try {
|
|
167
174
|
if (!chain.wallet) {
|
|
168
|
-
return fail("This server is read-only
|
|
175
|
+
return fail("This server is running read-only (INVOKE_READ_ONLY=1). Nothing was sent.");
|
|
169
176
|
}
|
|
170
177
|
const input = prompt.trim();
|
|
171
178
|
const inputBytes = Buffer.byteLength(input, "utf8");
|
|
@@ -188,8 +195,9 @@ async function main() {
|
|
|
188
195
|
}
|
|
189
196
|
const balance = BigInt(await chain.connection.getBalance(chain.wallet));
|
|
190
197
|
if (balance < cost + 10000n) {
|
|
191
|
-
return fail(`
|
|
192
|
-
`(reward ${sol(reward)} + refundable rent ${sol(rent)}).
|
|
198
|
+
return fail(`The iNVoke wallet has ${sol(balance)} SOL but this job needs about ${sol(cost)} SOL ` +
|
|
199
|
+
`(reward ${sol(reward)} + refundable rent ${sol(rent)}). ` +
|
|
200
|
+
`Send SOL to ${chain.wallet.toBase58()} and try again. Nothing was sent.`);
|
|
193
201
|
}
|
|
194
202
|
// Count the spend before sending so a crash mid-send cannot bypass the cap.
|
|
195
203
|
sessionSpend += cost;
|
|
@@ -258,7 +266,7 @@ async function main() {
|
|
|
258
266
|
});
|
|
259
267
|
await server.connect(new StdioServerTransport());
|
|
260
268
|
console.error(`coprocessor MCP server ready on ${chain.network}` +
|
|
261
|
-
(chain.wallet ? `, wallet ${chain.wallet.toBase58()}` : ", read-only
|
|
269
|
+
(chain.wallet ? `, wallet ${chain.wallet.toBase58()}` : ", read-only"));
|
|
262
270
|
}
|
|
263
271
|
main().catch((e) => {
|
|
264
272
|
console.error(firstLine(e));
|
package/package.json
CHANGED