baconservices-mcp 0.1.1 → 0.1.2

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 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
@@ -197,6 +197,12 @@ Commerce services, x402-paid capabilities, infrastructure, and backend implement
197
197
  separate services and are not licensed under the MIT License. Use of Bacon Services' hosted
198
198
  APIs and x402 services is governed by the [Bacon Services terms](https://baconservices.com/terms).
199
199
 
200
+ ## Support
201
+
202
+ For MCP, x402, or Agent Commerce support, contact Bacon Services:
203
+ https://baconservices.com/contact?topic=mcp. Please never send a wallet private key. Bugs in
204
+ this package can also be reported as issues on its repository.
205
+
200
206
  ## Trademark notice
201
207
 
202
208
  The MIT License applies to the source code in this repository only. "Bacon Services," the
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "baconservices-mcp",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
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
5
  "mcpName": "io.github.afmontoya/baconservices-mcp",
6
6
  "type": "module",
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
+ }