@bsvkey/inference-mcp 1.0.0 → 1.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Embryo Space Inc. (BSVKey)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Embryo Space Inc. (BSVKey)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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
@@ -19,27 +24,28 @@ need a funded channel key.
19
24
 
20
25
  ## Install
21
26
 
27
+ Published on npm as **[@bsvkey/inference-mcp](https://www.npmjs.com/package/@bsvkey/inference-mcp)**.
28
+
22
29
  ### Claude Code
23
30
  ```bash
24
31
  claude mcp add bsvkey-inference \
25
32
  --env BSVKEY_API_KEY=channelId:channelSecret \
26
- -- node /absolute/path/to/integrations/mcp/server.js
33
+ -- npx -y @bsvkey/inference-mcp
27
34
  ```
28
- Once published to npm, replace the command with `npx -y @bsvkey/inference-mcp`.
29
35
 
30
36
  ### Claude Desktop / Codex / any MCP host (JSON config)
31
37
  ```json
32
38
  {
33
39
  "mcpServers": {
34
40
  "bsvkey-inference": {
35
- "command": "node",
36
- "args": ["/absolute/path/to/integrations/mcp/server.js"],
41
+ "command": "npx",
42
+ "args": ["-y", "@bsvkey/inference-mcp"],
37
43
  "env": { "BSVKEY_API_KEY": "channelId:channelSecret" }
38
44
  }
39
45
  }
40
46
  }
41
47
  ```
42
- After npm publish: `"command": "npx", "args": ["-y", "@bsvkey/inference-mcp"]`.
48
+ No npm? Grab the single-file server directly (`https://inference.bsvkey.com/mcp/server.js`) and use `"command": "node", "args": ["server.js"]`.
43
49
 
44
50
  ## Configuration (env)
45
51
  | Var | Default | Meaning |
@@ -62,7 +68,8 @@ printf '%s\n' \
62
68
  > compatible, optional live web search, on-chain settlement. MCP + portable SKILL.md.
63
69
 
64
70
  ## Publishing (operator)
65
- - To make `npx @bsvkey/inference-mcp` work, publish this folder to npm
66
- (`npm publish --access public`) from an account that owns the `@bsvkey` scope.
71
+ - Live on npm under the `@bsvkey` org (owner: `interence`). First publish: v1.0.0.
72
+ - To ship an update: bump `version` in `package.json`, then
73
+ `npm publish --access public` (2FA/security-key prompt applies).
74
+ - Canonical source: https://github.com/BSVKey/inference-mcp
67
75
  - To list on a skills marketplace (e.g. bopen.ai), submit `SKILL.md` + this README.
68
- - Publishing is an operator action requiring your own credentials — not done here.
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,14 +1,21 @@
1
1
  {
2
2
  "name": "@bsvkey/inference-mcp",
3
- "version": "1.0.0",
4
- "description": "MCP server: buy Claude & Grok inference metered per token, settled in BSV, through the hosted inference.bsvkey.com gateway.",
3
+ "version": "1.1.0",
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",
5
6
  "type": "module",
6
7
  "bin": { "bsvkey-inference-mcp": "server.js" },
7
8
  "main": "server.js",
8
9
  "engines": { "node": ">=18" },
9
10
  "files": ["server.js", "SKILL.md", "README.md", "LICENSE"],
11
+ "optionalDependencies": {
12
+ "@bsvkey/x402-bsv-client": "^0.1.0",
13
+ "@bsv/sdk": "^1"
14
+ },
10
15
  "keywords": ["mcp", "model-context-protocol", "bsv", "inference", "pay-per-token", "http-402", "x402", "claude", "grok", "micropayments", "agents"],
11
16
  "author": "Embryo Space Inc. DBA BSVKey",
12
17
  "license": "MIT",
13
- "homepage": "https://inference.bsvkey.com"
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" }
14
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
  }