baconservices-mcp 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.md +208 -2
- package/TRADEMARKS.md +13 -0
- package/bin/baconservices-mcp.js +8 -0
- package/package.json +49 -4
- package/src/catalog.js +71 -0
- package/src/config.js +103 -0
- package/src/contracts.js +194 -0
- package/src/ledger.js +165 -0
- package/src/money.js +26 -0
- package/src/networks.js +39 -0
- package/src/payment.js +621 -0
- package/src/server.js +343 -0
- package/src/wallet.js +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bacon Services
|
|
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
|
@@ -1,3 +1,209 @@
|
|
|
1
|
-
#
|
|
1
|
+
# baconservices-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An MCP server that lets an AI agent buy image work from [Bacon Services](https://baconservices.com),
|
|
4
|
+
one call at a time, paid in USDC on Base over [x402](https://x402.org) from **your own wallet**,
|
|
5
|
+
within spending limits you set. There's no account and no API key: the agent calls a tool, the
|
|
6
|
+
server checks the price against your limits, signs a USDC payment for exactly that price, and
|
|
7
|
+
returns the result.
|
|
8
|
+
|
|
9
|
+
Also listed in the MCP Registry as `io.github.afmontoya/baconservices-mcp`.
|
|
10
|
+
|
|
11
|
+
## Wallet safety
|
|
12
|
+
|
|
13
|
+
Your wallet private key stays on your machine. Bacon Services never receives or stores it.
|
|
14
|
+
Payments are signed locally and are subject to configurable per-call, session, and daily
|
|
15
|
+
spending limits.
|
|
16
|
+
|
|
17
|
+
## What it sells
|
|
18
|
+
|
|
19
|
+
| Tool | Does | Price (2026-10-17) |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `remove_background` | Removes the background from one photo; returns a transparent PNG at the photo's size | 0.20 USDC |
|
|
22
|
+
| `optimize_image` | Resizes so the longest side ≤ `max_width` (64–4096, default 1600) and encodes WebP at `quality` (40–95, default 80) | 0.01 USDC |
|
|
23
|
+
| `image_palette` | The colours one image is mostly made of, as JSON: up to `count` (1–12, default 6) hex colours with their share, `include_neutrals` (default true) | 0.01 USDC |
|
|
24
|
+
| `brand_from_url` | Reads one public web page (`url`) and returns its brand as JSON: name, description, logo URLs, colours, fonts, social profiles. No JavaScript runs; robots.txt is respected | 0.03 USDC |
|
|
25
|
+
|
|
26
|
+
Image tools take PNG, JPEG or WebP up to 8 MB, as `image_url` (public https) or `image_path` (a
|
|
27
|
+
local file). `remove_background` and `optimize_image` return a signed download link (valid 24
|
|
28
|
+
hours); `image_palette` and `brand_from_url` return their JSON result in the tool result. Add
|
|
29
|
+
`save_to` to write either kind to disk. Prices come from Bacon's live catalog, and each paid tool
|
|
30
|
+
states its current price in its description.
|
|
31
|
+
|
|
32
|
+
`image_palette` and `brand_from_url` appear once Bacon's catalog publishes them with contract
|
|
33
|
+
versions. A service the installed package doesn't understand is listed by `list_services` but
|
|
34
|
+
can't be called until you update the package.
|
|
35
|
+
|
|
36
|
+
Free tools:
|
|
37
|
+
|
|
38
|
+
- `list_services`: everything Bacon sells right now, with prices, limits, and whether this
|
|
39
|
+
version of the package can run it.
|
|
40
|
+
- `quote`: Bacon's current price for one service, and whether your limits and wallet allow it.
|
|
41
|
+
Nothing is signed.
|
|
42
|
+
- `wallet_status`: network, whether a wallet is configured, your limits and what's left of them,
|
|
43
|
+
and whether you can afford each service (yes/no).
|
|
44
|
+
|
|
45
|
+
## Before you start
|
|
46
|
+
|
|
47
|
+
1. **Node.js 20 or newer.**
|
|
48
|
+
2. **A dedicated wallet** holding only what you're willing to spend. Fund it with **USDC on Base**.
|
|
49
|
+
You don't need ETH: x402 payments are signed authorizations (EIP-3009), and the facilitator
|
|
50
|
+
pays the gas.
|
|
51
|
+
3. **Put the private key in a file** that only you can read, for example `~/.bacon/buyer.key`.
|
|
52
|
+
Pointing `BACON_WALLET_KEY_FILE` at that file keeps the key out of MCP host configs, which are
|
|
53
|
+
often synced or shared. `BACON_WALLET_PRIVATE_KEY` also works.
|
|
54
|
+
|
|
55
|
+
The key never leaves your machine. Only signatures are sent, and only to Bacon. The key is never
|
|
56
|
+
logged, never written to the spend ledger, and never accepted as a tool argument.
|
|
57
|
+
|
|
58
|
+
## Install
|
|
59
|
+
|
|
60
|
+
### Claude Code
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
claude mcp add bacon -e BACON_WALLET_KEY_FILE=/home/you/.bacon/buyer.key -- npx -y baconservices-mcp
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Add more `-e NAME=value` pairs for the limits below. Check it with `claude mcp list`.
|
|
67
|
+
|
|
68
|
+
### Claude Desktop
|
|
69
|
+
|
|
70
|
+
Settings → Developer → Edit Config (`claude_desktop_config.json`):
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"mcpServers": {
|
|
75
|
+
"bacon": {
|
|
76
|
+
"command": "npx",
|
|
77
|
+
"args": ["-y", "baconservices-mcp"],
|
|
78
|
+
"env": {
|
|
79
|
+
"BACON_WALLET_KEY_FILE": "/Users/you/.bacon/buyer.key",
|
|
80
|
+
"BACON_MAX_PER_CALL": "0.50",
|
|
81
|
+
"BACON_MAX_PER_SESSION": "1.00",
|
|
82
|
+
"BACON_MAX_PER_DAY": "5.00"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
On Windows, if `npx` isn't found, use `"command": "cmd"` with
|
|
90
|
+
`"args": ["/c", "npx", "-y", "baconservices-mcp"]`, and write paths as
|
|
91
|
+
`"C:\\Users\\you\\.bacon\\buyer.key"`. Restart Claude Desktop afterwards.
|
|
92
|
+
|
|
93
|
+
### Cursor, Windsurf and other clients with an `mcpServers` file
|
|
94
|
+
|
|
95
|
+
Use the same `command` / `args` / `env` block as Claude Desktop (for Cursor:
|
|
96
|
+
`~/.cursor/mcp.json` or `.cursor/mcp.json` in a project).
|
|
97
|
+
|
|
98
|
+
### VS Code (`.vscode/mcp.json`)
|
|
99
|
+
|
|
100
|
+
VS Code can prompt for the key once and store it securely:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"inputs": [
|
|
105
|
+
{ "type": "promptString", "id": "bacon-key", "description": "Bacon buyer wallet private key", "password": true }
|
|
106
|
+
],
|
|
107
|
+
"servers": {
|
|
108
|
+
"bacon": {
|
|
109
|
+
"type": "stdio",
|
|
110
|
+
"command": "npx",
|
|
111
|
+
"args": ["-y", "baconservices-mcp"],
|
|
112
|
+
"env": { "BACON_WALLET_PRIVATE_KEY": "${input:bacon-key}" }
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Any other MCP client
|
|
119
|
+
|
|
120
|
+
It's a stdio server: run `npx -y baconservices-mcp` with the environment below.
|
|
121
|
+
|
|
122
|
+
## Configuration
|
|
123
|
+
|
|
124
|
+
| Variable | Default | Meaning |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| `BACON_WALLET_KEY_FILE` | — | Path to a file containing the buyer wallet's private key. |
|
|
127
|
+
| `BACON_WALLET_PRIVATE_KEY` | — | The key itself (set only one of the two). Without either, the free tools still work. |
|
|
128
|
+
| `BACON_MAX_PER_CALL` | `0.50` | Largest single payment, in USDC. |
|
|
129
|
+
| `BACON_MAX_PER_SESSION` | `1.00` | Most this server process may spend. |
|
|
130
|
+
| `BACON_MAX_PER_DAY` | `5.00` | Most spent in any rolling 24 hours, across all processes and restarts. |
|
|
131
|
+
| `BACON_CONFIRM` | `auto` | `auto`: ask before each payment when the host can; `always`: refuse to pay when it can't; `never`: don't ask (for unattended agents; the limits still apply). |
|
|
132
|
+
| `BACON_NETWORK` | `base` | `base` (real USDC, baconservices.com) or `base-sepolia` (test USDC, a test copy of Bacon). |
|
|
133
|
+
| `BACON_API_URL` | — | Only with `base-sepolia`: the test copy's address. |
|
|
134
|
+
| `BACON_PAY_TO` | — | Only with `base-sepolia`: the test copy's receiving address. |
|
|
135
|
+
| `BACON_RPC_URL` | `https://mainnet.base.org` | RPC used to check your USDC balance before paying. |
|
|
136
|
+
| `BACON_LEDGER_DIR` | `~/.baconservices-mcp` | Where the spend ledger lives. |
|
|
137
|
+
| `BACON_DISCLOSE_BALANCE` | `false` | `true` adds the exact balance and the wallet address to `wallet_status`. |
|
|
138
|
+
|
|
139
|
+
## How your money is protected
|
|
140
|
+
|
|
141
|
+
All of these checks happen before anything is signed:
|
|
142
|
+
|
|
143
|
+
- **The price is Bacon's own.** Bacon answers each request with an x402 402 that names the price.
|
|
144
|
+
The server pays only if that price equals Bacon's live catalog price, for that exact endpoint,
|
|
145
|
+
in Base USDC, to Bacon's receiving address (which is pinned in the package). If any of these
|
|
146
|
+
can't be verified, it doesn't pay.
|
|
147
|
+
- **Your limits.** It checks the per-call limit, an optional `max_price_usdc` on the call, the
|
|
148
|
+
per-session limit, and the 24-hour limit. The 24-hour total is kept in a local ledger file
|
|
149
|
+
shared by every process, so restarting the MCP server or running it twice doesn't open a new
|
|
150
|
+
budget. If the ledger can't be read, nothing is paid. The x402 library's own per-payment
|
|
151
|
+
cap is set to your per-call limit as a second lock.
|
|
152
|
+
- **Funds.** It reads your USDC balance first. If it's too low, or the balance can't be read,
|
|
153
|
+
you get a plain message and nothing is signed.
|
|
154
|
+
- **Your approval, where possible.** If the MCP host supports it, you're asked *"Pay 0.2 USDC on
|
|
155
|
+
Base to Bacon Services to run remove_background?"* Not every host can ask, so the limits are
|
|
156
|
+
the real boundary.
|
|
157
|
+
- **No double payments.** Each purchase signs one payment for one request. If the connection drops,
|
|
158
|
+
the server resends that same signed payment once (Bacon answers a repeat with the same result)
|
|
159
|
+
and never signs a new one. Asking for the same thing again within 10 minutes returns the
|
|
160
|
+
earlier result for free, unless you pass `allow_repeat: true`.
|
|
161
|
+
- **Only known services run.** New services in Bacon's catalog show up in `list_services`. They
|
|
162
|
+
become callable tools only once a version of this package that understands their contract
|
|
163
|
+
(inputs, outputs, version) is installed.
|
|
164
|
+
|
|
165
|
+
If Bacon refuses a payment before taking it, the result says *"You have not been charged"* and
|
|
166
|
+
the amount goes back to your limits. If the outcome is unknown (for example the connection was lost
|
|
167
|
+
twice), the result says so and gives Bacon's request id. That amount keeps counting against your
|
|
168
|
+
limits.
|
|
169
|
+
|
|
170
|
+
## Test money
|
|
171
|
+
|
|
172
|
+
Production Bacon sells only for real USDC. To try things without real money, run against a local
|
|
173
|
+
or test copy of Bacon that sells on Base Sepolia:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
BACON_NETWORK=base-sepolia BACON_API_URL=http://127.0.0.1:8000 BACON_PAY_TO=0xYourTestPayTo npx -y baconservices-mcp
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The package refuses mismatched setups and pays nothing in each case: test money pointed at
|
|
180
|
+
baconservices.com, real money pointed anywhere else, or a Bacon whose catalog is on a different
|
|
181
|
+
network.
|
|
182
|
+
|
|
183
|
+
## Develop
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
npm install
|
|
187
|
+
npm test
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The tests run against a fake Bacon that checks every payment signature for real. Nothing reaches
|
|
191
|
+
a network.
|
|
192
|
+
|
|
193
|
+
## Hosted services
|
|
194
|
+
|
|
195
|
+
This MCP client is open source under the MIT License. Bacon Services' hosted APIs, Agent
|
|
196
|
+
Commerce services, x402-paid capabilities, infrastructure, and backend implementations are
|
|
197
|
+
separate services and are not licensed under the MIT License. Use of Bacon Services' hosted
|
|
198
|
+
APIs and x402 services is governed by the [Bacon Services terms](https://baconservices.com/terms).
|
|
199
|
+
|
|
200
|
+
## Trademark notice
|
|
201
|
+
|
|
202
|
+
The MIT License applies to the source code in this repository only. "Bacon Services," the
|
|
203
|
+
Bacon Services name, logos, and associated branding are not licensed under the MIT License. No
|
|
204
|
+
permission is granted to use Bacon Services trademarks, logos, or branding in a way that
|
|
205
|
+
suggests endorsement, sponsorship, or affiliation. See [TRADEMARKS.md](TRADEMARKS.md).
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
MIT. See [LICENSE](LICENSE).
|
package/TRADEMARKS.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Trademark Notice
|
|
2
|
+
|
|
3
|
+
The MIT License applies to the source code in this repository only. "Bacon Services," the Bacon
|
|
4
|
+
Services name, logos, and associated branding are not licensed under the MIT License. No
|
|
5
|
+
permission is granted to use Bacon Services trademarks, logos, or branding in a way that
|
|
6
|
+
suggests endorsement, sponsorship, or affiliation.
|
|
7
|
+
|
|
8
|
+
## Hosted services
|
|
9
|
+
|
|
10
|
+
This MCP client is open source under the MIT License. Bacon Services' hosted APIs, Agent
|
|
11
|
+
Commerce services, x402-paid capabilities, infrastructure, and backend implementations are
|
|
12
|
+
separate services and are not licensed under the MIT License. Use of Bacon Services' hosted
|
|
13
|
+
APIs and x402 services is governed by the Bacon Services terms: https://baconservices.com/terms
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// stdio entry point. stdout carries the MCP protocol only; nothing else is ever written there.
|
|
3
|
+
|
|
4
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
+
import { createBaconServer } from '../src/server.js';
|
|
6
|
+
|
|
7
|
+
const { server } = createBaconServer();
|
|
8
|
+
await server.connect(new StdioServerTransport());
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baconservices-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "MCP server that lets an AI agent buy Bacon Services image operations (remove background, optimize for the web) per call in USDC over x402, with local spending limits.",
|
|
5
|
+
"mcpName": "io.github.afmontoya/baconservices-mcp",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"baconservices-mcp": "bin/baconservices-mcp.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "src/server.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"src",
|
|
14
|
+
"README.md",
|
|
15
|
+
"TRADEMARKS.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "node --test --test-concurrency=1 \"test/*.test.js\""
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"mcp",
|
|
26
|
+
"x402",
|
|
27
|
+
"usdc",
|
|
28
|
+
"base",
|
|
29
|
+
"remove-background",
|
|
30
|
+
"image-optimization",
|
|
31
|
+
"agent-payments"
|
|
32
|
+
],
|
|
33
|
+
"homepage": "https://baconservices.com",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/afmontoya/baconservices-mcp.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/afmontoya/baconservices-mcp/issues"
|
|
40
|
+
},
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@modelcontextprotocol/sdk": "1.32.1",
|
|
44
|
+
"@x402/core": "2.28.0",
|
|
45
|
+
"@x402/evm": "2.28.0",
|
|
46
|
+
"ajv": "8.20.0",
|
|
47
|
+
"ajv-formats": "3.0.1",
|
|
48
|
+
"viem": "2.57.7",
|
|
49
|
+
"zod": "3.25.76"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/catalog.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// The live catalog: what Bacon sells right now, matched against the contracts this package knows.
|
|
2
|
+
|
|
3
|
+
import { CONTRACTS, checkEntry, contractForEntry, contractId } from './contracts.js';
|
|
4
|
+
import { formatUsdc } from './money.js';
|
|
5
|
+
|
|
6
|
+
export const CATALOG_PATH = '/api/agent-commerce/v1/capabilities';
|
|
7
|
+
|
|
8
|
+
export function endpointFor(apiUrl, id) {
|
|
9
|
+
return `${apiUrl}${CATALOG_PATH}/${id}/execute`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Fetches the catalog and decides, per entry, whether it is executable here.
|
|
14
|
+
* Throws with a plain message when the catalog cannot be read or is not on the configured network.
|
|
15
|
+
*/
|
|
16
|
+
export async function fetchCatalog(config, fetchImpl) {
|
|
17
|
+
let response;
|
|
18
|
+
try {
|
|
19
|
+
response = await fetchImpl(`${config.apiUrl}${CATALOG_PATH}`, { headers: { Accept: 'application/json' }, signal: AbortSignal.timeout(15_000) });
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new Error(`Could not reach Bacon's service catalog at ${config.apiUrl}${CATALOG_PATH} (${error.name === 'TimeoutError' ? 'timed out' : error.message}).`);
|
|
22
|
+
}
|
|
23
|
+
if (response.status === 404) {
|
|
24
|
+
throw new Error('Bacon is not selling services to agents right now (the catalog is closed).');
|
|
25
|
+
}
|
|
26
|
+
let data = null;
|
|
27
|
+
try {
|
|
28
|
+
data = await response.json();
|
|
29
|
+
} catch {
|
|
30
|
+
// checked below
|
|
31
|
+
}
|
|
32
|
+
if (!response.ok || !data || !Array.isArray(data.capabilities)) {
|
|
33
|
+
throw new Error(`Bacon's service catalog answered ${response.status} without a capability list.`);
|
|
34
|
+
}
|
|
35
|
+
if (data.protocol?.name !== 'x402' || data.protocol?.version !== 2 || data.protocol?.scheme !== 'exact') {
|
|
36
|
+
throw new Error('Bacon\'s catalog does not describe x402 v2 "exact" payments, which is all this package can make.');
|
|
37
|
+
}
|
|
38
|
+
if (data.network?.id !== config.network.id || data.network?.testnet !== config.network.testnet) {
|
|
39
|
+
throw new Error(`Bacon at ${config.apiUrl} sells on ${data.network?.id ?? 'an unknown network'}${data.network?.testnet ? ' (testnet)' : ''}, but this package is set to ${config.network.id} (${config.network.label}). Nothing can be paid until they match.`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const services = data.capabilities.map((entry) => {
|
|
43
|
+
const contract = contractForEntry(entry);
|
|
44
|
+
const reasons = checkEntry(entry, contract, { endpoint: endpointFor(config.apiUrl, entry.id), usdc: config.network.usdc.address, catalogVersion: data.contract_version });
|
|
45
|
+
return {
|
|
46
|
+
id: entry.id,
|
|
47
|
+
name: entry.name,
|
|
48
|
+
description: entry.description,
|
|
49
|
+
contract: contractId(entry.id, entry.version),
|
|
50
|
+
tool: contract?.tool ?? null,
|
|
51
|
+
executable: reasons.length === 0,
|
|
52
|
+
not_executable_because: reasons,
|
|
53
|
+
price: entry.price && /^\d+$/.test(entry.price.amount ?? '') ? { usdc: formatUsdc(entry.price.amount), atomic: entry.price.amount } : null,
|
|
54
|
+
execution: entry.execution ?? null,
|
|
55
|
+
output: entry.output ?? null,
|
|
56
|
+
limits: entry.limits ?? null,
|
|
57
|
+
entry,
|
|
58
|
+
contractDef: contract,
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return { network: data.network, contractVersion: data.contract_version ?? null, services };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The tools a catalog makes executable, in the package's own order. */
|
|
66
|
+
export function executableTools(catalog) {
|
|
67
|
+
if (!catalog) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
return CONTRACTS.map((c) => catalog.services.find((s) => s.tool === c.tool && s.executable)).filter(Boolean);
|
|
71
|
+
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Configuration from the environment, with the network guard.
|
|
2
|
+
//
|
|
3
|
+
// Real money (Base) talks to https://baconservices.com and nothing else. Test money (Base
|
|
4
|
+
// Sepolia) talks to a test copy of Bacon and never to production. A mismatch is a configuration
|
|
5
|
+
// problem: nothing is fetched and nothing can be paid until it is fixed.
|
|
6
|
+
|
|
7
|
+
import { homedir } from 'node:os';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { parseUsdc } from './money.js';
|
|
10
|
+
import { NETWORKS, PRODUCTION_API_URL } from './networks.js';
|
|
11
|
+
|
|
12
|
+
export const DEFAULT_LIMITS = { perCall: '0.50', perSession: '1.00', perDay: '5.00' };
|
|
13
|
+
export const CONFIRM_MODES = ['auto', 'always', 'never'];
|
|
14
|
+
|
|
15
|
+
const PRODUCTION_HOSTS = ['baconservices.com', 'www.baconservices.com'];
|
|
16
|
+
const LOCAL_HOSTS = ['localhost', '127.0.0.1', '[::1]'];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns {{ problems: string[], network: object|null, apiUrl: string|null, limits: object, confirm: string,
|
|
20
|
+
* ledgerDir: string, rpcUrl: string|null, payTo: string|null, discloseBalance: boolean }}
|
|
21
|
+
*/
|
|
22
|
+
export function loadConfig(env, { home = homedir() } = {}) {
|
|
23
|
+
const problems = [];
|
|
24
|
+
const read = (name) => (env[name] ?? '').trim();
|
|
25
|
+
|
|
26
|
+
const networkKey = read('BACON_NETWORK') || 'base';
|
|
27
|
+
const network = NETWORKS[networkKey] ?? null;
|
|
28
|
+
if (!network) {
|
|
29
|
+
problems.push(`BACON_NETWORK must be "base" (real USDC) or "base-sepolia" (test USDC), not "${networkKey}".`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let apiUrl = null;
|
|
33
|
+
const rawApi = read('BACON_API_URL').replace(/\/+$/, '');
|
|
34
|
+
if (network) {
|
|
35
|
+
if (!network.testnet) {
|
|
36
|
+
apiUrl = PRODUCTION_API_URL;
|
|
37
|
+
if (rawApi && rawApi !== PRODUCTION_API_URL) {
|
|
38
|
+
problems.push(`BACON_NETWORK=base pays real money and only talks to ${PRODUCTION_API_URL}; BACON_API_URL is "${rawApi}". For a test copy of Bacon use BACON_NETWORK=base-sepolia.`);
|
|
39
|
+
}
|
|
40
|
+
} else if (!rawApi) {
|
|
41
|
+
problems.push('BACON_NETWORK=base-sepolia needs BACON_API_URL: the address of a test copy of Bacon (production sells for real money only).');
|
|
42
|
+
} else {
|
|
43
|
+
let url = null;
|
|
44
|
+
try {
|
|
45
|
+
url = new URL(rawApi);
|
|
46
|
+
} catch {
|
|
47
|
+
problems.push(`BACON_API_URL "${rawApi}" is not a URL.`);
|
|
48
|
+
}
|
|
49
|
+
if (url) {
|
|
50
|
+
if (PRODUCTION_HOSTS.includes(url.hostname)) {
|
|
51
|
+
problems.push(`BACON_NETWORK=base-sepolia cannot use production (${url.hostname}): production sells for real money only. Use BACON_NETWORK=base, or point BACON_API_URL at a test copy of Bacon.`);
|
|
52
|
+
} else if (url.protocol !== 'https:' && !(url.protocol === 'http:' && LOCAL_HOSTS.includes(url.hostname))) {
|
|
53
|
+
problems.push('BACON_API_URL must be https (plain http only for localhost).');
|
|
54
|
+
} else {
|
|
55
|
+
apiUrl = url.origin;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let payTo = network?.payTo ?? null;
|
|
62
|
+
const rawPayTo = read('BACON_PAY_TO');
|
|
63
|
+
if (network?.testnet) {
|
|
64
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(rawPayTo)) {
|
|
65
|
+
problems.push('BACON_NETWORK=base-sepolia needs BACON_PAY_TO: the receiving address of the test copy of Bacon, so payments to anyone else are refused.');
|
|
66
|
+
} else {
|
|
67
|
+
payTo = rawPayTo;
|
|
68
|
+
}
|
|
69
|
+
} else if (network && rawPayTo && rawPayTo.toLowerCase() !== network.payTo) {
|
|
70
|
+
problems.push('BACON_PAY_TO cannot change Bacon\'s receiving address on Base; leave it unset.');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const limits = {};
|
|
74
|
+
for (const [key, name] of [['perCall', 'BACON_MAX_PER_CALL'], ['perSession', 'BACON_MAX_PER_SESSION'], ['perDay', 'BACON_MAX_PER_DAY']]) {
|
|
75
|
+
try {
|
|
76
|
+
limits[key] = parseUsdc(read(name) || DEFAULT_LIMITS[key], name);
|
|
77
|
+
if (limits[key] <= 0n) {
|
|
78
|
+
problems.push(`${name} must be more than 0.`);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
problems.push(error.message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const confirm = (read('BACON_CONFIRM') || 'auto').toLowerCase();
|
|
86
|
+
if (!CONFIRM_MODES.includes(confirm)) {
|
|
87
|
+
problems.push(`BACON_CONFIRM must be auto, always or never (got "${confirm}").`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const rpcUrl = read('BACON_RPC_URL') || network?.rpcUrl || null;
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
problems,
|
|
94
|
+
network,
|
|
95
|
+
apiUrl,
|
|
96
|
+
payTo,
|
|
97
|
+
limits,
|
|
98
|
+
confirm,
|
|
99
|
+
rpcUrl,
|
|
100
|
+
ledgerDir: read('BACON_LEDGER_DIR') || join(home, '.baconservices-mcp'),
|
|
101
|
+
discloseBalance: /^(1|true|yes)$/i.test(read('BACON_DISCLOSE_BALANCE')),
|
|
102
|
+
};
|
|
103
|
+
}
|