baconservices-mcp 0.1.2 → 0.3.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 +21 -21
- package/README.md +9 -6
- package/bin/baconservices-mcp.js +8 -8
- package/package.json +4 -2
- package/src/catalog.js +71 -71
- package/src/config.js +103 -103
- package/src/contracts.js +241 -194
- package/src/ledger.js +165 -165
- package/src/money.js +26 -26
- package/src/networks.js +39 -39
- package/src/payment.js +625 -621
- package/src/server.js +1 -1
- package/src/wallet.js +60 -60
package/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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
|
@@ -18,19 +18,22 @@ spending limits.
|
|
|
18
18
|
|
|
19
19
|
| Tool | Does | Price (2026-10-17) |
|
|
20
20
|
|---|---|---|
|
|
21
|
-
| `remove_background` | Removes the background from one photo; returns a transparent PNG at the photo's size | 0.
|
|
21
|
+
| `remove_background` | Removes the background from one photo; returns a transparent PNG at the photo's size | 0.05 USDC |
|
|
22
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
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
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
|
+
| `page_metadata` | Reads one public web page (`url`) and returns its SEO and link-preview metadata as JSON: title and description with lengths, canonical, redirects, robots rules, Open Graph and Twitter cards, headings, JSON-LD types, and a list of issues. Nothing it links to is fetched; robots.txt is respected | 0.01 USDC |
|
|
26
|
+
| `accessibility_check` | An automated WCAG check of one public web page (`url`) with axe-core: `standard` (`wcag22aa` default, or `wcag21aa`), `viewport` (`desktop` default, or `mobile`). JSON: failing rules with WCAG criteria, element counts and examples, what needs review, and the criteria a person must test. The page's own scripts don't run. Not a certification of WCAG or ADA conformance | 0.05 USDC |
|
|
27
|
+
| `vectorize_image` | Traces one image into an SVG of flat-colour paths: `colors` (2–32, default 16), `detail` (`smooth`, `balanced` or `detailed`, default `balanced`). Best for logos and icons | 0.05 USDC |
|
|
25
28
|
|
|
26
29
|
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 `
|
|
28
|
-
hours); `image_palette` and `
|
|
30
|
+
local file). `remove_background`, `optimize_image` and `vectorize_image` return a signed download
|
|
31
|
+
link (valid 24 hours); `image_palette`, `brand_from_url`, `page_metadata` and `accessibility_check` return their JSON result in the tool result. Add
|
|
29
32
|
`save_to` to write either kind to disk. Prices come from Bacon's live catalog, and each paid tool
|
|
30
33
|
states its current price in its description.
|
|
31
34
|
|
|
32
|
-
`image_palette` and `
|
|
33
|
-
versions. A service the installed package doesn't understand is listed by `list_services` but
|
|
35
|
+
`image_palette`, `brand_from_url`, `page_metadata`, `accessibility_check` and `vectorize_image` appear once Bacon's catalog publishes
|
|
36
|
+
them with contract versions. A service the installed package doesn't understand is listed by `list_services` but
|
|
34
37
|
can't be called until you update the package.
|
|
35
38
|
|
|
36
39
|
Free tools:
|
|
@@ -151,7 +154,7 @@ All of these checks happen before anything is signed:
|
|
|
151
154
|
cap is set to your per-call limit as a second lock.
|
|
152
155
|
- **Funds.** It reads your USDC balance first. If it's too low, or the balance can't be read,
|
|
153
156
|
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.
|
|
157
|
+
- **Your approval, where possible.** If the MCP host supports it, you're asked *"Pay 0.05 USDC on
|
|
155
158
|
Base to Bacon Services to run remove_background?"* Not every host can ask, so the limits are
|
|
156
159
|
the real boundary.
|
|
157
160
|
- **No double payments.** Each purchase signs one payment for one request. If the connection drops,
|
package/bin/baconservices-mcp.js
CHANGED
|
@@ -1,8 +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());
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baconservices-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MCP server that lets an AI agent buy Bacon Services
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "MCP server that lets an AI agent buy Bacon Services tools per call in USDC over x402: remove a background, optimize an image for the web, read an image's colour palette, read a brand from a URL, read a page's SEO metadata, run an automated WCAG accessibility check, trace an image into an SVG. With local spending limits.",
|
|
5
5
|
"mcpName": "io.github.afmontoya/baconservices-mcp",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
"base",
|
|
29
29
|
"remove-background",
|
|
30
30
|
"image-optimization",
|
|
31
|
+
"color-palette",
|
|
32
|
+
"brand-kit",
|
|
31
33
|
"agent-payments"
|
|
32
34
|
],
|
|
33
35
|
"homepage": "https://baconservices.com",
|
package/src/catalog.js
CHANGED
|
@@ -1,71 +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
|
-
}
|
|
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
CHANGED
|
@@ -1,103 +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
|
-
}
|
|
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
|
+
}
|