charter-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 +17 -0
- package/dist/cli.js +103 -0
- package/dist/main.js +29 -21
- package/dist/server.js +87 -85
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -51,6 +51,23 @@ Until the wallet is funded the free tools work and the paid ones answer with the
|
|
|
51
51
|
|
|
52
52
|
A job tool waits up to 40 seconds by default, under most clients' tool timeout. A job still running then hands back its `leaseId`, and `charter_lease` collects the output for free.
|
|
53
53
|
|
|
54
|
+
## From a shell
|
|
55
|
+
|
|
56
|
+
The same seven actions, one command each, for an agent that runs commands instead of speaking MCP. Each prints one JSON document; a failure is `{"error": "..."}` with a non-zero exit code.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx -y charter-mcp offers
|
|
60
|
+
npx -y charter-mcp wallet
|
|
61
|
+
npx -y charter-mcp run-python job.py
|
|
62
|
+
echo 'print(2 + 2)' | npx -y charter-mcp run-python -
|
|
63
|
+
npx -y charter-mcp fetch https://example.com --wait 120
|
|
64
|
+
npx -y charter-mcp rent-home keys.pub
|
|
65
|
+
npx -y charter-mcp lease <leaseId>
|
|
66
|
+
npx -y charter-mcp extend <leaseId> 2
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`run-python`, `fetch`, `rent-home` and `extend` pay; the others are free. With no command it runs as the MCP server. The wallet, the caps and the count of the day's spend are shared by both.
|
|
70
|
+
|
|
54
71
|
## What bounds the money
|
|
55
72
|
|
|
56
73
|
- The server signs only `exact` payments in USDC on Base, to the payee Charter's door names at `GET /v1/door`. Anything else a 402 offers is never signed.
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export const USAGE = `usage:
|
|
2
|
+
charter-mcp run as an MCP server over stdio
|
|
3
|
+
charter-mcp offers free: the machines on sale and the price
|
|
4
|
+
charter-mcp wallet free: the wallet to fund, its balance, the caps
|
|
5
|
+
charter-mcp run-python <file | -> [--wait N] PAID, one interval: run a Python script, print its output
|
|
6
|
+
charter-mcp fetch <url> [url ...] [--wait N] PAID, one interval: load up to five pages, print their text
|
|
7
|
+
charter-mcp rent-home <keys.pub> [--image charter-home | charter-hermes]
|
|
8
|
+
PAID, one interval: open a Linux home with these SSH public keys
|
|
9
|
+
charter-mcp lease <leaseId> free: state, paid time left, SSH address, finished output
|
|
10
|
+
charter-mcp extend <leaseId> <hours> PAID, one interval each: pay the next 1 to 24 intervals
|
|
11
|
+
|
|
12
|
+
One interval is an hour at 0.007 USDC on the live host. --wait is 10 to 240 seconds (default 40); a job
|
|
13
|
+
still running then prints its leaseId, and \`lease\` collects the output for free.
|
|
14
|
+
Environment: CHARTER_MAX_USDC_PER_HOUR (0.01), CHARTER_MAX_USDC_PER_DAY (0.25), CHARTER_MCP_KEY_FILE,
|
|
15
|
+
CHARTER_MCP_NO_NEW_KEY, CHARTER_MCP_SPEND_FILE, CHARTER_BASE_RPC, CHARTER_DOOR_URL.
|
|
16
|
+
Docs: https://charter.mainnet.toonprotocol.dev/agents`;
|
|
17
|
+
class UsageError extends Error {
|
|
18
|
+
}
|
|
19
|
+
/** Splits `--name value` flags from the rest. Only the flags named in `known` are accepted. */
|
|
20
|
+
function parse(args, known) {
|
|
21
|
+
const rest = [];
|
|
22
|
+
const flags = {};
|
|
23
|
+
for (let i = 0; i < args.length; i++) {
|
|
24
|
+
const a = args[i];
|
|
25
|
+
if (a.startsWith('--')) {
|
|
26
|
+
const name = a.slice(2);
|
|
27
|
+
const value = args[i + 1];
|
|
28
|
+
if (!known.includes(name) || value === undefined)
|
|
29
|
+
throw new UsageError(`unknown or incomplete option ${a}`);
|
|
30
|
+
flags[name] = value;
|
|
31
|
+
i++;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
rest.push(a);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { rest, flags };
|
|
38
|
+
}
|
|
39
|
+
function waitOf(flags) {
|
|
40
|
+
if (flags.wait === undefined)
|
|
41
|
+
return undefined;
|
|
42
|
+
if (!/^\d{1,3}$/.test(flags.wait))
|
|
43
|
+
throw new UsageError('--wait takes a whole number of seconds, 10 to 240');
|
|
44
|
+
return Number(flags.wait);
|
|
45
|
+
}
|
|
46
|
+
export async function cli(argv, io) {
|
|
47
|
+
const [cmd, ...args] = argv;
|
|
48
|
+
const ok = (o) => ({ code: 0, out: JSON.stringify(o, null, 2) });
|
|
49
|
+
try {
|
|
50
|
+
switch (cmd) {
|
|
51
|
+
case 'offers':
|
|
52
|
+
parse(args, []);
|
|
53
|
+
return ok(await io.actions().offers());
|
|
54
|
+
case 'wallet':
|
|
55
|
+
parse(args, []);
|
|
56
|
+
return ok(await io.actions().wallet());
|
|
57
|
+
case 'run-python': {
|
|
58
|
+
const { rest, flags } = parse(args, ['wait']);
|
|
59
|
+
// A lone "-" is stdin, not an option.
|
|
60
|
+
if (rest.length !== 1)
|
|
61
|
+
throw new UsageError('run-python takes one script file, or - for stdin');
|
|
62
|
+
const wait = waitOf(flags);
|
|
63
|
+
const script = rest[0] === '-' ? await io.readStdin() : io.readFile(rest[0]);
|
|
64
|
+
return ok(await io.actions().runPython(script, wait));
|
|
65
|
+
}
|
|
66
|
+
case 'fetch': {
|
|
67
|
+
const { rest, flags } = parse(args, ['wait']);
|
|
68
|
+
if (rest.length < 1)
|
|
69
|
+
throw new UsageError('fetch takes one to five URLs');
|
|
70
|
+
return ok(await io.actions().fetchPages(rest, waitOf(flags)));
|
|
71
|
+
}
|
|
72
|
+
case 'rent-home': {
|
|
73
|
+
const { rest, flags } = parse(args, ['image']);
|
|
74
|
+
if (rest.length !== 1)
|
|
75
|
+
throw new UsageError('rent-home takes one file of SSH public keys, one a line');
|
|
76
|
+
const keys = io
|
|
77
|
+
.readFile(rest[0])
|
|
78
|
+
.split('\n')
|
|
79
|
+
.map((l) => l.trim())
|
|
80
|
+
.filter((l) => l && !l.startsWith('#'));
|
|
81
|
+
return ok(await io.actions().rentHome(keys, flags.image));
|
|
82
|
+
}
|
|
83
|
+
case 'lease': {
|
|
84
|
+
const { rest } = parse(args, []);
|
|
85
|
+
if (rest.length !== 1)
|
|
86
|
+
throw new UsageError('lease takes one leaseId');
|
|
87
|
+
return ok(await io.actions().lease(rest[0]));
|
|
88
|
+
}
|
|
89
|
+
case 'extend': {
|
|
90
|
+
const { rest } = parse(args, []);
|
|
91
|
+
if (rest.length !== 2 || !/^\d{1,2}$/.test(rest[1]))
|
|
92
|
+
throw new UsageError('extend takes a leaseId and a number of intervals, 1 to 24');
|
|
93
|
+
return ok(await io.actions().extend(rest[0], Number(rest[1])));
|
|
94
|
+
}
|
|
95
|
+
default:
|
|
96
|
+
throw new UsageError(cmd === undefined ? 'no command' : `unknown command ${cmd}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
const message = String(e?.message ?? e);
|
|
101
|
+
return { code: e instanceof UsageError ? 2 : 1, out: JSON.stringify({ error: e instanceof UsageError ? `${message}. Run charter-mcp --help.` : message }, null, 2) };
|
|
102
|
+
}
|
|
103
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { cli, USAGE } from './cli.js';
|
|
4
|
+
import { build, optionsFromEnv, run, VERSION } from './server.js';
|
|
5
|
+
const argv = process.argv.slice(2);
|
|
6
|
+
const arg = argv[0];
|
|
7
|
+
const die = (e) => {
|
|
8
|
+
process.stderr.write(`charter-mcp: ${String(e?.message ?? e)}\n`);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
};
|
|
4
11
|
if (arg === '--version' || arg === '-v') {
|
|
5
12
|
console.log(VERSION);
|
|
6
13
|
}
|
|
7
|
-
else if (arg === '--help' || arg === '-h') {
|
|
8
|
-
console.log(`charter-mcp ${VERSION}:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
CHARTER_MAX_USDC_PER_HOUR the most one interval may cost (default 0.01)
|
|
14
|
-
CHARTER_MAX_USDC_PER_DAY the most one UTC day may cost (default 0.25)
|
|
15
|
-
CHARTER_MCP_KEY_FILE the wallet key file (default ~/.charter/mcp.key, made on first run)
|
|
16
|
-
CHARTER_MCP_NO_NEW_KEY set to never make a key: with no key file the paid tools stay off
|
|
17
|
-
CHARTER_MCP_SPEND_FILE where the day's spend is kept (default ~/.charter/mcp-spend.json)
|
|
18
|
-
CHARTER_BASE_RPC Base RPC for the balance read
|
|
19
|
-
CHARTER_DOOR_URL the door (default https://charter.mainnet.toonprotocol.dev)
|
|
20
|
-
|
|
21
|
-
Docs: https://charter.mainnet.toonprotocol.dev/agents`);
|
|
14
|
+
else if (arg === '--help' || arg === '-h' || arg === 'help') {
|
|
15
|
+
console.log(`charter-mcp ${VERSION}: rent a Charter machine and pay for it in USDC on Base, as an MCP server or from the shell.\n\n${USAGE}`);
|
|
16
|
+
}
|
|
17
|
+
else if (arg === undefined) {
|
|
18
|
+
// No command: the MCP server, as an MCP client starts it.
|
|
19
|
+
run(process.env).catch(die);
|
|
22
20
|
}
|
|
23
21
|
else {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
process.
|
|
27
|
-
|
|
22
|
+
let actions;
|
|
23
|
+
cli(argv, {
|
|
24
|
+
actions: () => (actions ??= build(optionsFromEnv(process.env), (line) => void process.stderr.write(`charter-mcp: ${line}\n`)).actions),
|
|
25
|
+
readFile: (path) => readFileSync(path, 'utf8'),
|
|
26
|
+
readStdin: async () => {
|
|
27
|
+
const chunks = [];
|
|
28
|
+
for await (const c of process.stdin)
|
|
29
|
+
chunks.push(c);
|
|
30
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
31
|
+
},
|
|
32
|
+
}).then((r) => {
|
|
33
|
+
console.log(r.out);
|
|
34
|
+
process.exitCode = r.code;
|
|
35
|
+
}, die);
|
|
28
36
|
}
|
package/dist/server.js
CHANGED
|
@@ -20,7 +20,7 @@ import { privateKeyToAccount } from 'viem/accounts';
|
|
|
20
20
|
import { base } from 'viem/chains';
|
|
21
21
|
import { z } from 'zod';
|
|
22
22
|
import { BASE, BASE_USDC, CapError, DEFAULT_DOOR, PayError, extend, lease, microToUsdc, onlyDoorExact, output, rent, runJob, usdcToMicro, } from './core.js';
|
|
23
|
-
export const VERSION = '0.
|
|
23
|
+
export const VERSION = '0.2.0';
|
|
24
24
|
export function optionsFromEnv(env) {
|
|
25
25
|
const dir = join(homedir(), '.charter');
|
|
26
26
|
const v = (k) => env[k]?.trim() || undefined;
|
|
@@ -257,19 +257,18 @@ export function build(o, log, fetchFn = fetch) {
|
|
|
257
257
|
spentTodayUsdc: microToUsdc(spend.spent(today)),
|
|
258
258
|
};
|
|
259
259
|
};
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
try {
|
|
260
|
+
const wait = (n) => {
|
|
261
|
+
const w = n ?? 40;
|
|
262
|
+
if (!Number.isInteger(w) || w < 10 || w > 240)
|
|
263
|
+
throw new Error('the wait is 10 to 240 seconds; nothing was paid');
|
|
264
|
+
return w;
|
|
265
|
+
};
|
|
266
|
+
const actions = {
|
|
267
|
+
offers: async () => {
|
|
269
268
|
const r = await get('/v1/offers');
|
|
270
269
|
if (r.status !== 200 || !Array.isArray(r.body))
|
|
271
270
|
throw new Error(`GET /v1/offers answered ${r.status}`);
|
|
272
|
-
return
|
|
271
|
+
return {
|
|
273
272
|
offers: r.body.map((x) => ({
|
|
274
273
|
offerId: x.offerId,
|
|
275
274
|
usdcPerInterval: /^\d+$/.test(String(x.tickPrice)) ? microToUsdc(x.tickPrice) : x.tickPrice,
|
|
@@ -281,36 +280,90 @@ export function build(o, log, fetchFn = fetch) {
|
|
|
281
280
|
})),
|
|
282
281
|
docs: `${o.door}/agents`,
|
|
283
282
|
...caps(),
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return fail(e);
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
server.registerTool('charter_wallet', {
|
|
291
|
-
title: 'Charter payer wallet',
|
|
292
|
-
description: 'Free. The wallet this server pays Charter from: its address, its USDC balance on Base, the spending caps, what has been spent today, and how to fund it. Call this when a paid tool is refused, or to tell your operator where to send USDC.',
|
|
293
|
-
inputSchema: {},
|
|
294
|
-
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
295
|
-
}, async () => {
|
|
296
|
-
try {
|
|
283
|
+
};
|
|
284
|
+
},
|
|
285
|
+
wallet: async () => {
|
|
297
286
|
if (!account) {
|
|
298
|
-
return
|
|
287
|
+
return { address: null, paidTools: 'off', why: `no key at ${o.keyFile} and CHARTER_MCP_NO_NEW_KEY is set. Put a key there (0x and 64 hex digits, mode 600) or unset the variable to have one made.`, ...caps() };
|
|
299
288
|
}
|
|
300
289
|
const usdc = await balance().catch((e) => `unavailable (${e.message.slice(0, 80)})`);
|
|
301
|
-
return
|
|
290
|
+
return {
|
|
302
291
|
address: account.address,
|
|
303
292
|
usdcOnBase: usdc,
|
|
304
293
|
...caps(),
|
|
305
294
|
keyFile: o.keyFile,
|
|
306
295
|
fund: `Send USDC on Base (chain id 8453, token ${BASE_USDC}) to ${account.address}. No ETH is needed. 0.007 USDC buys one hour; 1 USDC is about 6 days of a home. Keep only what the rent needs in this wallet: the key is a plain file on this machine.`,
|
|
307
296
|
pays: 'Only Charter: exact USDC on Base, to the payee the door names, within the caps above. The operator changes the caps with CHARTER_MAX_USDC_PER_HOUR and CHARTER_MAX_USDC_PER_DAY.',
|
|
308
|
-
}
|
|
297
|
+
};
|
|
298
|
+
},
|
|
299
|
+
runPython: async (script, waitSeconds) => {
|
|
300
|
+
if (typeof script !== 'string' || script.length === 0)
|
|
301
|
+
throw new Error('the script is empty; nothing was paid');
|
|
302
|
+
if (Buffer.byteLength(script, 'utf8') > 8192)
|
|
303
|
+
throw new Error('the script is over 8192 bytes; nothing was paid');
|
|
304
|
+
return runJob(deps, { python: { script } }, wait(waitSeconds));
|
|
305
|
+
},
|
|
306
|
+
fetchPages: async (urls, waitSeconds) => {
|
|
307
|
+
if (!Array.isArray(urls) || urls.length < 1 || urls.length > 5)
|
|
308
|
+
throw new Error('give one to five URLs; nothing was paid');
|
|
309
|
+
for (const u of urls) {
|
|
310
|
+
if (typeof u !== 'string' || !/^https?:\/\//i.test(u) || !URL.canParse(u))
|
|
311
|
+
throw new Error(`not an http or https URL: ${String(u).slice(0, 80)}; nothing was paid`);
|
|
312
|
+
}
|
|
313
|
+
return runJob(deps, { urls }, wait(waitSeconds));
|
|
314
|
+
},
|
|
315
|
+
rentHome: async (sshKeys, image) => {
|
|
316
|
+
const keys = (Array.isArray(sshKeys) ? sshKeys : []).map((k) => String(k).trim()).filter(Boolean);
|
|
317
|
+
if (keys.length < 1 || keys.length > 8)
|
|
318
|
+
throw new Error('give 1 to 8 SSH public keys; nothing was paid');
|
|
319
|
+
const bad = keys.find((k) => k.length > 1023 || !SSH_KEY.test(k));
|
|
320
|
+
if (bad !== undefined) {
|
|
321
|
+
throw new Error(/PRIVATE KEY/.test(bad)
|
|
322
|
+
? 'that is a private key. Pass the PUBLIC key line only (the .pub file); nothing was sent or paid'
|
|
323
|
+
: 'each key must be one public key line starting with ssh-ed25519, ecdsa-sha2-nistp256/384/521 or ssh-rsa; nothing was paid');
|
|
324
|
+
}
|
|
325
|
+
if (image !== undefined && image !== 'charter-home' && image !== 'charter-hermes')
|
|
326
|
+
throw new Error('the image is charter-home or charter-hermes; nothing was paid');
|
|
327
|
+
const rented = await rent(deps, { home: { sshKeys: keys, ...(image ? { image } : {}) } });
|
|
328
|
+
return {
|
|
329
|
+
...rented,
|
|
330
|
+
next: 'Read the lease about once a minute until it shows ssh (the onion address is published within about a minute). Pay more time before paidThrough; a home that lapses keeps its disk 7 days and opens again with the same keys.',
|
|
331
|
+
};
|
|
332
|
+
},
|
|
333
|
+
lease: async (leaseId) => {
|
|
334
|
+
const { view } = await lease(deps, leaseId);
|
|
335
|
+
if ((view.state === 'done' || view.state === 'closed') && view.outputParts > 0)
|
|
336
|
+
return { lease: view, output: await output(deps, leaseId, view.outputParts) };
|
|
337
|
+
return { lease: view };
|
|
338
|
+
},
|
|
339
|
+
extend: async (leaseId, hours) => {
|
|
340
|
+
if (!Number.isInteger(hours) || hours < 1 || hours > 24)
|
|
341
|
+
throw new Error('pay 1 to 24 intervals at a time; nothing was paid');
|
|
342
|
+
return extend(deps, leaseId, hours);
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
const answer = async (run) => {
|
|
346
|
+
try {
|
|
347
|
+
return text(await run());
|
|
309
348
|
}
|
|
310
349
|
catch (e) {
|
|
311
350
|
return fail(e);
|
|
312
351
|
}
|
|
313
|
-
}
|
|
352
|
+
};
|
|
353
|
+
const server = new McpServer({ name: 'charter', version: VERSION });
|
|
354
|
+
const cost = 'Costs one interval of the cheapest machine: 0.007 USDC on the live host (see charter_offers), paid from this server\'s own wallet in USDC on Base.';
|
|
355
|
+
server.registerTool('charter_offers', {
|
|
356
|
+
title: 'Charter machines on sale',
|
|
357
|
+
description: 'Free. The machines for rent on Charter right now: price per interval in USDC (0.007 an hour on the live host), CPU, memory, the job images each runs, and how many home slots it has. Charter rents a sandboxed machine by the hour with no account: a Python job, a page-fetch job, or a Linux home with SSH. Call this first to see the price before any paid tool.',
|
|
358
|
+
inputSchema: {},
|
|
359
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
360
|
+
}, () => answer(actions.offers));
|
|
361
|
+
server.registerTool('charter_wallet', {
|
|
362
|
+
title: 'Charter payer wallet',
|
|
363
|
+
description: 'Free. The wallet this server pays Charter from: its address, its USDC balance on Base, the spending caps, what has been spent today, and how to fund it. Call this when a paid tool is refused, or to tell your operator where to send USDC.',
|
|
364
|
+
inputSchema: {},
|
|
365
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
366
|
+
}, () => answer(actions.wallet));
|
|
314
367
|
server.registerTool('charter_run_python', {
|
|
315
368
|
title: 'Run a Python script on a rented machine',
|
|
316
369
|
description: `PAID. ${cost} Runs your Python 3 script once in a sandbox on a rented machine and returns its stdout, stderr and exit code. NumPy is installed; there is no network and no other package; the script is at most 8 KiB. Most scripts finish in seconds. If it is still running when the wait ends, the leaseId comes back and charter_lease collects the output for free.`,
|
|
@@ -319,16 +372,7 @@ export function build(o, log, fetchFn = fetch) {
|
|
|
319
372
|
waitSeconds: z.number().int().min(10).max(240).optional().describe('how long to wait for the job before handing back the leaseId (default 40, under most clients\' 60 s tool timeout)'),
|
|
320
373
|
},
|
|
321
374
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
322
|
-
},
|
|
323
|
-
try {
|
|
324
|
-
if (Buffer.byteLength(script, 'utf8') > 8192)
|
|
325
|
-
throw new Error('the script is over 8192 bytes; nothing was paid');
|
|
326
|
-
return text(await runJob(deps, { python: { script } }, waitSeconds ?? 40));
|
|
327
|
-
}
|
|
328
|
-
catch (e) {
|
|
329
|
-
return fail(e);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
375
|
+
}, ({ script, waitSeconds }) => answer(() => actions.runPython(script, waitSeconds)));
|
|
332
376
|
server.registerTool('charter_fetch_pages', {
|
|
333
377
|
title: 'Fetch pages in a headless browser through a hidden exit',
|
|
334
378
|
description: `PAID. ${cost} Loads up to five http or https pages in a headless browser on a rented machine, through an exit on the Anyone network so the site sees neither you nor the host, and returns each page's text. Useful when a page needs JavaScript or your own address is refused. Slow (a page can take a minute) and some sites refuse shared exits. If it is still running when the wait ends, charter_lease collects the output for free.`,
|
|
@@ -337,14 +381,7 @@ export function build(o, log, fetchFn = fetch) {
|
|
|
337
381
|
waitSeconds: z.number().int().min(10).max(240).optional().describe('how long to wait for the job before handing back the leaseId (default 40, under most clients\' 60 s tool timeout; pages often need longer, so expect to collect with charter_lease)'),
|
|
338
382
|
},
|
|
339
383
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
340
|
-
},
|
|
341
|
-
try {
|
|
342
|
-
return text(await runJob(deps, { urls }, waitSeconds ?? 40));
|
|
343
|
-
}
|
|
344
|
-
catch (e) {
|
|
345
|
-
return fail(e);
|
|
346
|
-
}
|
|
347
|
-
});
|
|
384
|
+
}, ({ urls, waitSeconds }) => answer(() => actions.fetchPages(urls, waitSeconds)));
|
|
348
385
|
server.registerTool('charter_rent_home', {
|
|
349
386
|
title: 'Rent a Linux home with SSH',
|
|
350
387
|
description: `PAID. ${cost} Opens a Linux box of your own (Debian, 1 CPU, 1 GiB memory, a 2 GiB disk kept 7 days after the lease ends, user "tenant", no root) and pays its first interval. Pass 1 to 8 SSH PUBLIC keys; the key set is the home's identity, so the same keys open the same disk again. Read this before renting: SSH is reachable only at an onion address on the Anyone network, so whoever logs in needs an Anyone client; all outbound traffic leaves through Anyone and is slow; the live host has two home slots and an open answers busy when both are taken. After renting, call charter_lease about once a minute until it shows the SSH address, and charter_extend before the paid time runs out.`,
|
|
@@ -353,41 +390,13 @@ export function build(o, log, fetchFn = fetch) {
|
|
|
353
390
|
image: z.enum(['charter-home', 'charter-hermes']).optional().describe('charter-home (default) is a plain box; charter-hermes has Hermes Agent preinstalled'),
|
|
354
391
|
},
|
|
355
392
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
356
|
-
},
|
|
357
|
-
try {
|
|
358
|
-
const keys = sshKeys.map((k) => k.trim());
|
|
359
|
-
const bad = keys.find((k) => !SSH_KEY.test(k));
|
|
360
|
-
if (bad !== undefined) {
|
|
361
|
-
throw new Error(/PRIVATE KEY/.test(bad)
|
|
362
|
-
? 'that is a private key. Pass the PUBLIC key line only (the .pub file); nothing was sent or paid'
|
|
363
|
-
: 'each key must be one public key line starting with ssh-ed25519, ecdsa-sha2-nistp256/384/521 or ssh-rsa; nothing was paid');
|
|
364
|
-
}
|
|
365
|
-
const rented = await rent(deps, { home: { sshKeys: keys, ...(image ? { image } : {}) } });
|
|
366
|
-
return text({
|
|
367
|
-
...rented,
|
|
368
|
-
next: 'Call charter_lease with this leaseId about once a minute until it shows ssh (the onion address is published within about a minute). Pay more time with charter_extend before paidThrough; a home that lapses keeps its disk 7 days and opens again with the same keys.',
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
catch (e) {
|
|
372
|
-
return fail(e);
|
|
373
|
-
}
|
|
374
|
-
});
|
|
393
|
+
}, ({ sshKeys, image }) => answer(() => actions.rentHome(sshKeys, image)));
|
|
375
394
|
server.registerTool('charter_lease', {
|
|
376
395
|
title: 'Read a Charter lease',
|
|
377
396
|
description: 'Free. The state of a lease opened by this server: running, done or closed, the paid time left, a home\'s SSH address once published, and a finished job\'s output (a Python job\'s stdout, stderr and exit code, or a fetch job\'s page text).',
|
|
378
397
|
inputSchema: { leaseId: z.string().regex(/^[0-9a-f]{32}$/).describe('the 32 hex character leaseId a paid tool returned') },
|
|
379
398
|
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
380
|
-
},
|
|
381
|
-
try {
|
|
382
|
-
const { view } = await lease(deps, leaseId);
|
|
383
|
-
if ((view.state === 'done' || view.state === 'closed') && view.outputParts > 0)
|
|
384
|
-
return text({ lease: view, output: await output(deps, leaseId, view.outputParts) });
|
|
385
|
-
return text({ lease: view });
|
|
386
|
-
}
|
|
387
|
-
catch (e) {
|
|
388
|
-
return fail(e);
|
|
389
|
-
}
|
|
390
|
-
});
|
|
399
|
+
}, ({ leaseId }) => answer(() => actions.lease(leaseId)));
|
|
391
400
|
server.registerTool('charter_extend', {
|
|
392
401
|
title: 'Pay more time on a lease',
|
|
393
402
|
description: 'PAID. Pays the next intervals of a running lease, one payment each (0.007 USDC an hour on the live host), from this server\'s wallet. Use it to keep a home running: pay before the paid time runs out, ideally half an hour early. Stops at the first refused payment and reports what was paid. A lease that has closed cannot be extended; a home opens again with the same keys.',
|
|
@@ -396,15 +405,8 @@ export function build(o, log, fetchFn = fetch) {
|
|
|
396
405
|
hours: z.number().int().min(1).max(24).describe('how many intervals to pay now, 1 to 24. The door refunds nothing, so pay only what you will use.'),
|
|
397
406
|
},
|
|
398
407
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
399
|
-
},
|
|
400
|
-
|
|
401
|
-
return text(await extend(deps, leaseId, hours));
|
|
402
|
-
}
|
|
403
|
-
catch (e) {
|
|
404
|
-
return fail(e);
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
return { server, address: account?.address };
|
|
408
|
+
}, ({ leaseId, hours }) => answer(() => actions.extend(leaseId, hours)));
|
|
409
|
+
return { server, address: account?.address, actions };
|
|
408
410
|
}
|
|
409
411
|
export async function run(env) {
|
|
410
412
|
const log = (line) => void process.stderr.write(`charter-mcp: ${line}\n`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "charter-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MCP server that
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "MCP server and command line that let an agent rent a sandboxed machine by the hour on Charter and pay for it itself: run a Python script, fetch pages through a hidden exit, or rent a Linux home with SSH. USDC on Base over x402, no account.",
|
|
5
5
|
"mcpName": "io.github.drew-dot-com/charter",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|