@bsvkey/inference-mcp 1.0.1 → 1.1.1

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.
Files changed (4) hide show
  1. package/README.md +6 -1
  2. package/SKILL.md +4 -1
  3. package/package.json +21 -17
  4. package/server.js +57 -0
package/README.md CHANGED
@@ -5,7 +5,12 @@ settled in BSV**, through the hosted gateway at **inference.bsvkey.com**. Zero
5
5
  dependencies (Node ≥ 18, uses global `fetch`). It's a thin HTTP client — it never
6
6
  holds your keys or runs models; every call is billed through the gateway.
7
7
 
8
- Tools: `list_models`, `infer`, `channel_balance`, `open_channel`.
8
+ Tools: `list_models`, `infer`, `channel_balance`, `open_channel`, `x402_infer`.
9
+
10
+ Two ways to pay: a **prepaid channel** (`infer`, fund once, draw down per token) or
11
+ **per call via x402** (`x402_infer` — no channel; the agent pays each request in BSV
12
+ with its own key). `x402_infer` needs a funded WIF (`wif` arg or `BSVKEY_WIF`) and the
13
+ optional `@bsvkey/x402-bsv-client` + `@bsv/sdk` packages (installed with this one).
9
14
 
10
15
  ## Quick start
11
16
  1. **Fund a channel once** at https://inference.bsvkey.com (BRC-100 wallet, or
package/SKILL.md CHANGED
@@ -12,7 +12,10 @@ subscription, no account, no card. Models: Claude (haiku/sonnet/opus) and Grok
12
12
  (grok-4.3 fast, grok-4.6), with optional live web search.
13
13
 
14
14
  Install it as an MCP server (see README.md) — this skill assumes those four tools
15
- are available: `list_models`, `open_channel`, `infer`, `channel_balance`.
15
+ are available: `list_models`, `open_channel`, `infer`, `channel_balance`, `x402_infer`.
16
+
17
+ `x402_infer` is an alternative to `infer`: instead of a prepaid channel, it pays for a
18
+ single call in BSV via x402, using a funded key (`wif` arg or `BSVKEY_WIF`). No channel setup.
16
19
 
17
20
  ## When to use
18
21
  - The user/agent wants to buy inference on demand and pay only for what it uses.
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
- {
2
- "name": "@bsvkey/inference-mcp",
3
- "version": "1.0.1",
4
- "description": "MCP server: buy Claude & Grok inference metered per token, settled in BSV, through the hosted inference.bsvkey.com gateway.",
5
- "mcpName": "io.github.BSVKey/inference-mcp",
6
- "type": "module",
7
- "bin": { "bsvkey-inference-mcp": "server.js" },
8
- "main": "server.js",
9
- "engines": { "node": ">=18" },
10
- "files": ["server.js", "SKILL.md", "README.md", "LICENSE"],
11
- "keywords": ["mcp", "model-context-protocol", "bsv", "inference", "pay-per-token", "http-402", "x402", "claude", "grok", "micropayments", "agents"],
12
- "author": "Embryo Space Inc. DBA BSVKey",
13
- "license": "MIT",
14
- "homepage": "https://inference.bsvkey.com",
15
- "repository": { "type": "git", "url": "git+https://github.com/BSVKey/inference-mcp.git" },
16
- "bugs": { "url": "https://github.com/BSVKey/inference-mcp/issues" }
17
- }
1
+ {
2
+ "name": "@bsvkey/inference-mcp",
3
+ "version": "1.1.1",
4
+ "description": "MCP server: buy Claude & Grok inference metered per token, settled in BSV, through the hosted inference.bsvkey.com gateway. Channels or per-call x402.",
5
+ "mcpName": "io.github.BSVKey/inference-mcp",
6
+ "type": "module",
7
+ "bin": { "bsvkey-inference-mcp": "server.js" },
8
+ "main": "server.js",
9
+ "engines": { "node": ">=18" },
10
+ "files": ["server.js", "SKILL.md", "README.md", "LICENSE"],
11
+ "optionalDependencies": {
12
+ "@bsvkey/x402-bsv-client": "^0.2.0",
13
+ "@bsv/sdk": "^2"
14
+ },
15
+ "keywords": ["mcp", "model-context-protocol", "bsv", "inference", "pay-per-token", "http-402", "x402", "claude", "grok", "micropayments", "agents"],
16
+ "author": "Embryo Space Inc. DBA BSVKey",
17
+ "license": "MIT",
18
+ "homepage": "https://inference.bsvkey.com",
19
+ "repository": { "type": "git", "url": "git+https://github.com/BSVKey/inference-mcp.git" },
20
+ "bugs": { "url": "https://github.com/BSVKey/inference-mcp/issues" }
21
+ }
package/server.js CHANGED
@@ -85,6 +85,24 @@ export const TOOLS = [
85
85
  'Explains how to open + fund a prepaid channel. Funding is a real BSV payment signed by a wallet, so it is done once at the website; you then paste the returned channel key here (or set BSVKEY_API_KEY).',
86
86
  inputSchema: { type: 'object', properties: {}, additionalProperties: false },
87
87
  },
88
+ {
89
+ name: 'x402_infer',
90
+ description:
91
+ 'Run one inference paid PER CALL in BSV via x402 — no prepaid channel needed. You provide a funded BSV private key (wif or BSVKEY_WIF); the tool fetches the 402 quote, builds + signs a BSV payment, retries with X-PAYMENT, and returns the completion plus the on-chain settlement txid. Non-custodial: signing happens locally in this process, the key never leaves it. Needs @bsvkey/x402-bsv-client + @bsv/sdk (installed with this package).',
92
+ inputSchema: {
93
+ type: 'object',
94
+ properties: {
95
+ prompt: { type: 'string', description: 'The user prompt.' },
96
+ model: { type: 'string', description: 'Model id or policy: auto|cheapest|best, claude-*, grok-*.', default: 'grok-4.3' },
97
+ system: { type: 'string', description: 'Optional system prompt.' },
98
+ maxTokens: { type: 'integer', description: 'Max output tokens.', default: 512 },
99
+ webSearch: { type: 'boolean', description: 'Let the model search the live web (adds a per-search fee to the quote).', default: false },
100
+ wif: { type: 'string', description: 'A funded BSV private key (WIF) to pay from. Omit to use BSVKEY_WIF. Never leaves this process.' },
101
+ },
102
+ required: ['prompt'],
103
+ additionalProperties: false,
104
+ },
105
+ },
88
106
  ];
89
107
 
90
108
  async function callTool(name, args = {}) {
@@ -154,6 +172,45 @@ async function callTool(name, args = {}) {
154
172
  ],
155
173
  };
156
174
  }
175
+ case 'x402_infer': {
176
+ const wif = args.wif || process.env.BSVKEY_WIF || '';
177
+ if (!wif) throw new Error(`No BSV key. Pass wif "<WIF>" or set BSVKEY_WIF — an agent-funded key to pay per call. Fund its address at ${SITE}.`);
178
+ let x402;
179
+ try {
180
+ x402 = await import('@bsvkey/x402-bsv-client');
181
+ } catch {
182
+ throw new Error('Pay-per-call needs @bsvkey/x402-bsv-client and @bsv/sdk. Install them: npm i @bsvkey/x402-bsv-client @bsv/sdk');
183
+ }
184
+ const url = `${BASE}/x402/chat/completions`;
185
+ const init = {
186
+ method: 'POST',
187
+ headers: { 'content-type': 'application/json' },
188
+ body: JSON.stringify({
189
+ model: args.model || 'grok-4.3',
190
+ messages: [
191
+ ...(args.system ? [{ role: 'system', content: args.system }] : []),
192
+ { role: 'user', content: String(args.prompt || '') },
193
+ ],
194
+ max_tokens: args.maxTokens || 512,
195
+ web_search: args.webSearch === true,
196
+ }),
197
+ };
198
+ const res = await x402.fetchWithX402(url, init, { wif });
199
+ const data = await res.json().catch(() => ({}));
200
+ if (!res.ok) {
201
+ const msg = data?.error?.message || data?.error || data?.reason || `x402 inference failed (${res.status})`;
202
+ throw new Error(typeof msg === 'string' ? msg : JSON.stringify(msg));
203
+ }
204
+ const settle = x402.readSettlement(res) || {};
205
+ return {
206
+ model: data.model || args.model,
207
+ completion: data.choices?.[0]?.message?.content ?? '',
208
+ paidSats: data.x_bsv?.paidSats,
209
+ payTo: data.x_bsv?.payTo,
210
+ settlementTxid: settle.transaction,
211
+ network: settle.network,
212
+ };
213
+ }
157
214
  default:
158
215
  throw new Error(`unknown tool: ${name}`);
159
216
  }