@last-price/tools-mcp 0.2.0 → 0.6.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/README.md CHANGED
@@ -6,7 +6,33 @@ API, built on `@last-price/tools-core`, and it holds no pricing, billing or rout
6
6
 
7
7
  If you would rather install nothing, the hosted endpoint is `https://api.last-price.ai/api/mcp/rpc`.
8
8
 
9
- ## Use it
9
+ ## One command for every coding agent in a project
10
+
11
+ ```bash
12
+ npx -y @last-price/tools-mcp init
13
+ ```
14
+
15
+ Run it in a project's root. It adds the hosted Last Price server (no local process, no key needed for the demo
16
+ tools) to the agents that project uses, and a short block to `AGENTS.md` saying when to ask Last Price for a
17
+ price instead of guessing:
18
+
19
+ | File | Agent | Written |
20
+ |------|-------|---------|
21
+ | `.mcp.json` | Claude Code | always |
22
+ | `.cursor/mcp.json` | Cursor | when `.cursor/` exists |
23
+ | `.vscode/mcp.json` | VS Code, GitHub Copilot | when `.vscode/` exists |
24
+ | `.gemini/settings.json` | Gemini CLI | when `.gemini/` exists |
25
+ | `AGENTS.md` (and `CLAUDE.md` if present) | Codex, Cursor, Copilot, Gemini, Claude Code | always |
26
+
27
+ Other servers and an existing `lastprice` entry are kept, and a second run changes nothing. `--only claude,agents`
28
+ picks targets, `--dry-run` shows what would change, `--dir <path>` runs it elsewhere. Codex keeps servers in your
29
+ own config, so `init` prints the `codex mcp add` command for it instead of editing that file. Commit the files and
30
+ everyone who opens the project gets the same setup.
31
+
32
+ `init` needs 0.4.0 or later. If `npx` reuses an older cached copy, the command starts the stdio server and waits
33
+ instead; press Ctrl+C and run `npx -y @last-price/tools-mcp@latest init`.
34
+
35
+ ## Run it as a local stdio server
10
36
 
11
37
  Create an API key in Settings, API keys at https://last-price.ai (without one only the public demo tools work).
12
38
 
package/dist/cli.d.ts CHANGED
@@ -6,5 +6,8 @@
6
6
  * LASTPRICE_JWT a JWT instead of a key
7
7
  * LASTPRICE_API_URL default https://api.last-price.ai
8
8
  * LASTPRICE_TIMEOUT_MS time limit per tool call, default 30000
9
+ *
10
+ * `last-price-mcp init` instead adds the hosted server to this project's coding
11
+ * agents (see ./init.ts) and exits.
9
12
  */
10
13
  export {};
package/dist/cli.js CHANGED
@@ -7,37 +7,61 @@
7
7
  * LASTPRICE_JWT a JWT instead of a key
8
8
  * LASTPRICE_API_URL default https://api.last-price.ai
9
9
  * LASTPRICE_TIMEOUT_MS time limit per tool call, default 30000
10
+ *
11
+ * `last-price-mcp init` instead adds the hosted server to this project's coding
12
+ * agents (see ./init.ts) and exits.
10
13
  */
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  const server_1 = require("./server");
13
- const client = (0, server_1.clientFromEnv)(process.env);
14
- let buffer = '';
15
- function send(message) {
16
- process.stdout.write(`${JSON.stringify(message)}\n`);
17
- }
18
- async function processLine(line) {
19
- let parsed;
20
- try {
21
- parsed = JSON.parse(line);
16
+ const init_1 = require("./init");
17
+ if (process.argv[2] === 'init') {
18
+ const rest = process.argv.slice(3);
19
+ if (rest.includes('--help') || rest.includes('-h')) {
20
+ process.stdout.write(`${init_1.INIT_HELP}\n`);
22
21
  }
23
- catch {
24
- send({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } });
25
- return;
22
+ else {
23
+ try {
24
+ process.stdout.write(`${(0, init_1.runInit)((0, init_1.parseInitArgs)(rest, process.cwd())).join('\n')}\n`);
25
+ }
26
+ catch (error) {
27
+ process.stderr.write(`last-price-mcp init: ${error.message}\n`);
28
+ process.exitCode = 1;
29
+ }
26
30
  }
27
- const reply = await (0, server_1.handleMessage)(client, parsed);
28
- if (reply)
29
- send(reply);
30
31
  }
31
- // Decode at the stream level so a multibyte character split across chunks survives.
32
- process.stdin.setEncoding('utf8');
33
- process.stdin.on('data', (chunk) => {
34
- buffer += chunk;
35
- let newline = buffer.indexOf('\n');
36
- while (newline >= 0) {
37
- const line = buffer.slice(0, newline).trim();
38
- buffer = buffer.slice(newline + 1);
39
- if (line)
40
- void processLine(line);
41
- newline = buffer.indexOf('\n');
32
+ else {
33
+ serve();
34
+ }
35
+ function serve() {
36
+ const client = (0, server_1.clientFromEnv)(process.env);
37
+ let buffer = '';
38
+ function send(message) {
39
+ process.stdout.write(`${JSON.stringify(message)}\n`);
42
40
  }
43
- });
41
+ async function processLine(line) {
42
+ let parsed;
43
+ try {
44
+ parsed = JSON.parse(line);
45
+ }
46
+ catch {
47
+ send({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } });
48
+ return;
49
+ }
50
+ const reply = await (0, server_1.handleMessage)(client, parsed);
51
+ if (reply)
52
+ send(reply);
53
+ }
54
+ // Decode at the stream level so a multibyte character split across chunks survives.
55
+ process.stdin.setEncoding('utf8');
56
+ process.stdin.on('data', (chunk) => {
57
+ buffer += chunk;
58
+ let newline = buffer.indexOf('\n');
59
+ while (newline >= 0) {
60
+ const line = buffer.slice(0, newline).trim();
61
+ buffer = buffer.slice(newline + 1);
62
+ if (line)
63
+ void processLine(line);
64
+ newline = buffer.indexOf('\n');
65
+ }
66
+ });
67
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './server';
2
+ export * from './init';
package/dist/index.js CHANGED
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./server"), exports);
18
+ __exportStar(require("./init"), exports);
package/dist/init.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * `npx -y @last-price/tools-mcp init`: add Last Price to the coding agents a
3
+ * project uses, with no marketplace, plugin directory or connector listing in
4
+ * between. It writes project files only, and only what it names:
5
+ *
6
+ * .mcp.json Claude Code (project scope)
7
+ * .cursor/mcp.json Cursor, when .cursor/ exists
8
+ * .vscode/mcp.json VS Code and GitHub Copilot, when .vscode/ exists
9
+ * .gemini/settings.json Gemini CLI, when .gemini/ exists
10
+ * AGENTS.md a marked block telling any agent when to call Last Price
11
+ * (Codex, Cursor, Copilot, Gemini and Claude Code read it;
12
+ * CLAUDE.md gets the same block when it exists)
13
+ *
14
+ * Every server entry is the hosted endpoint, so nothing runs locally and no
15
+ * key is needed for the demo tools. Existing entries and other servers are
16
+ * kept; running it twice changes nothing. Codex keeps its servers in the
17
+ * user's own config, so for Codex the command is printed, not run.
18
+ */
19
+ export declare const INIT_VIA = "npx-init";
20
+ export declare const INIT_MCP_URL = "https://api.last-price.ai/api/mcp/rpc?profile=directory&via=npx-init";
21
+ export declare const INIT_SERVER_NAME = "lastprice";
22
+ export declare const BLOCK_START = "<!-- last-price:start -->";
23
+ export declare const BLOCK_END = "<!-- last-price:end -->";
24
+ export type Target = 'claude' | 'cursor' | 'vscode' | 'gemini' | 'agents';
25
+ export declare const ALL_TARGETS: readonly Target[];
26
+ /** The block written into AGENTS.md (and CLAUDE.md when present). Plain Markdown, no secrets. */
27
+ export declare const AGENTS_BLOCK: string;
28
+ export interface FileChange {
29
+ /** Path relative to the project root. */
30
+ file: string;
31
+ /** What the file will hold, or null when it is already right. */
32
+ content: string | null;
33
+ /** One line for the summary. */
34
+ note: string;
35
+ }
36
+ /** Puts the Last Price block at the end of a Markdown file, or refreshes it in place. */
37
+ export declare function withAgentsBlock(file: string, before: string | undefined): FileChange;
38
+ /**
39
+ * The changes for a project. `read` returns a file's text or undefined;
40
+ * `exists` says whether a directory exists. No file system access here.
41
+ */
42
+ export declare function planInit(read: (file: string) => string | undefined, exists: (dir: string) => boolean, only?: readonly Target[]): FileChange[];
43
+ export interface InitOptions {
44
+ dir: string;
45
+ only?: Target[];
46
+ dryRun?: boolean;
47
+ }
48
+ export declare function parseInitArgs(argv: readonly string[], cwd: string): InitOptions;
49
+ export declare const INIT_HELP: string;
50
+ /** Runs init on the real file system and returns the lines to print. */
51
+ export declare function runInit(options: InitOptions): string[];
package/dist/init.js ADDED
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ /**
3
+ * `npx -y @last-price/tools-mcp init`: add Last Price to the coding agents a
4
+ * project uses, with no marketplace, plugin directory or connector listing in
5
+ * between. It writes project files only, and only what it names:
6
+ *
7
+ * .mcp.json Claude Code (project scope)
8
+ * .cursor/mcp.json Cursor, when .cursor/ exists
9
+ * .vscode/mcp.json VS Code and GitHub Copilot, when .vscode/ exists
10
+ * .gemini/settings.json Gemini CLI, when .gemini/ exists
11
+ * AGENTS.md a marked block telling any agent when to call Last Price
12
+ * (Codex, Cursor, Copilot, Gemini and Claude Code read it;
13
+ * CLAUDE.md gets the same block when it exists)
14
+ *
15
+ * Every server entry is the hosted endpoint, so nothing runs locally and no
16
+ * key is needed for the demo tools. Existing entries and other servers are
17
+ * kept; running it twice changes nothing. Codex keeps its servers in the
18
+ * user's own config, so for Codex the command is printed, not run.
19
+ */
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.INIT_HELP = exports.AGENTS_BLOCK = exports.ALL_TARGETS = exports.BLOCK_END = exports.BLOCK_START = exports.INIT_SERVER_NAME = exports.INIT_MCP_URL = exports.INIT_VIA = void 0;
25
+ exports.withAgentsBlock = withAgentsBlock;
26
+ exports.planInit = planInit;
27
+ exports.parseInitArgs = parseInitArgs;
28
+ exports.runInit = runInit;
29
+ const node_fs_1 = __importDefault(require("node:fs"));
30
+ const node_path_1 = __importDefault(require("node:path"));
31
+ exports.INIT_VIA = 'npx-init';
32
+ exports.INIT_MCP_URL = `https://api.last-price.ai/api/mcp/rpc?profile=directory&via=${exports.INIT_VIA}`;
33
+ exports.INIT_SERVER_NAME = 'lastprice';
34
+ exports.BLOCK_START = '<!-- last-price:start -->';
35
+ exports.BLOCK_END = '<!-- last-price:end -->';
36
+ exports.ALL_TARGETS = ['claude', 'cursor', 'vscode', 'gemini', 'agents'];
37
+ /** The block written into AGENTS.md (and CLAUDE.md when present). Plain Markdown, no secrets. */
38
+ exports.AGENTS_BLOCK = [
39
+ exports.BLOCK_START,
40
+ '## Prices: ask Last Price',
41
+ '',
42
+ 'When a task needs a price (quoting work, pricing a product or an API call, checking whether a',
43
+ 'quote or a purchase is sound, or negotiating), call the `lastprice` MCP server instead of guessing:',
44
+ '`compute_price` for a price, `verify_price` to check one before charging or paying it,',
45
+ '`pricing_conversation` when inputs are missing. It works without a key (rate-limited demo);',
46
+ 'a key from https://last-price.ai goes in the `x-api-key` header.',
47
+ 'Without MCP: `POST https://api.last-price.ai/api/public/compute/demo` or read https://last-price.ai/llms.txt.',
48
+ exports.BLOCK_END,
49
+ ].join('\n');
50
+ function parseJson(text, file) {
51
+ if (text === undefined || text.trim() === '')
52
+ return {};
53
+ let parsed;
54
+ try {
55
+ parsed = JSON.parse(text);
56
+ }
57
+ catch {
58
+ throw new Error(`${file} is not valid JSON; fix it or pass --only to skip it`);
59
+ }
60
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
61
+ throw new Error(`${file} does not hold a JSON object; fix it or pass --only to skip it`);
62
+ }
63
+ return parsed;
64
+ }
65
+ /** Adds `servers[name] = entry` under `key` unless an entry by that name is already there. */
66
+ function withServer(file, before, key, entry) {
67
+ const json = parseJson(before, file);
68
+ const servers = (json[key] && typeof json[key] === 'object' ? json[key] : {});
69
+ if (servers[exports.INIT_SERVER_NAME])
70
+ return { file, content: null, note: `${file}: already has "${exports.INIT_SERVER_NAME}", left as is` };
71
+ json[key] = { ...servers, [exports.INIT_SERVER_NAME]: entry };
72
+ return { file, content: `${JSON.stringify(json, null, 2)}\n`, note: `${file}: added "${exports.INIT_SERVER_NAME}"` };
73
+ }
74
+ /** Puts the Last Price block at the end of a Markdown file, or refreshes it in place. */
75
+ function withAgentsBlock(file, before) {
76
+ const text = before ?? '';
77
+ const start = text.indexOf(exports.BLOCK_START);
78
+ const end = text.indexOf(exports.BLOCK_END);
79
+ let next;
80
+ if (start >= 0 && end > start) {
81
+ next = text.slice(0, start) + exports.AGENTS_BLOCK + text.slice(end + exports.BLOCK_END.length);
82
+ }
83
+ else {
84
+ const sep = text === '' ? '' : text.endsWith('\n\n') ? '' : text.endsWith('\n') ? '\n' : '\n\n';
85
+ next = `${text}${sep}${exports.AGENTS_BLOCK}\n`;
86
+ }
87
+ if (next === text)
88
+ return { file, content: null, note: `${file}: block already current` };
89
+ return { file, content: next, note: `${file}: ${start >= 0 ? 'refreshed' : 'added'} the Last Price block` };
90
+ }
91
+ /**
92
+ * The changes for a project. `read` returns a file's text or undefined;
93
+ * `exists` says whether a directory exists. No file system access here.
94
+ */
95
+ function planInit(read, exists, only) {
96
+ const explicit = only && only.length > 0;
97
+ const wanted = (t, dir) => (explicit ? only.includes(t) : !dir || exists(dir));
98
+ const changes = [];
99
+ if (wanted('claude'))
100
+ changes.push(withServer('.mcp.json', read('.mcp.json'), 'mcpServers', { type: 'http', url: exports.INIT_MCP_URL }));
101
+ if (wanted('cursor', '.cursor'))
102
+ changes.push(withServer('.cursor/mcp.json', read('.cursor/mcp.json'), 'mcpServers', { url: exports.INIT_MCP_URL }));
103
+ if (wanted('vscode', '.vscode'))
104
+ changes.push(withServer('.vscode/mcp.json', read('.vscode/mcp.json'), 'servers', { type: 'http', url: exports.INIT_MCP_URL }));
105
+ if (wanted('gemini', '.gemini'))
106
+ changes.push(withServer('.gemini/settings.json', read('.gemini/settings.json'), 'mcpServers', { httpUrl: exports.INIT_MCP_URL }));
107
+ if (wanted('agents')) {
108
+ changes.push(withAgentsBlock('AGENTS.md', read('AGENTS.md')));
109
+ const claudeMd = read('CLAUDE.md');
110
+ if (claudeMd !== undefined && !claudeMd.includes('@AGENTS.md'))
111
+ changes.push(withAgentsBlock('CLAUDE.md', claudeMd));
112
+ }
113
+ return changes;
114
+ }
115
+ function parseInitArgs(argv, cwd) {
116
+ const options = { dir: cwd };
117
+ for (let i = 0; i < argv.length; i++) {
118
+ const arg = argv[i];
119
+ if (arg === '--dry-run')
120
+ options.dryRun = true;
121
+ else if (arg === '--dir')
122
+ options.dir = node_path_1.default.resolve(cwd, argv[++i] ?? '.');
123
+ else if (arg === '--only') {
124
+ const list = (argv[++i] ?? '').split(',').map((s) => s.trim()).filter(Boolean);
125
+ for (const t of list) {
126
+ if (!exports.ALL_TARGETS.includes(t))
127
+ throw new Error(`unknown target "${t}"; use ${exports.ALL_TARGETS.join(', ')}`);
128
+ }
129
+ options.only = list;
130
+ }
131
+ else
132
+ throw new Error(`unknown option "${arg}"`);
133
+ }
134
+ return options;
135
+ }
136
+ exports.INIT_HELP = `Usage: npx -y @last-price/tools-mcp init [--only ${exports.ALL_TARGETS.join(',')}] [--dir <path>] [--dry-run]
137
+
138
+ Adds the hosted Last Price MCP server to this project's coding agents and a short
139
+ "when to ask Last Price" block to AGENTS.md. Cursor, VS Code and Gemini files are
140
+ written only when their folder exists, unless named with --only.`;
141
+ /** Runs init on the real file system and returns the lines to print. */
142
+ function runInit(options) {
143
+ const read = (file) => {
144
+ try {
145
+ return node_fs_1.default.readFileSync(node_path_1.default.join(options.dir, file), 'utf8');
146
+ }
147
+ catch {
148
+ return undefined;
149
+ }
150
+ };
151
+ const exists = (dir) => {
152
+ try {
153
+ return node_fs_1.default.statSync(node_path_1.default.join(options.dir, dir)).isDirectory();
154
+ }
155
+ catch {
156
+ return false;
157
+ }
158
+ };
159
+ const changes = planInit(read, exists, options.only);
160
+ const lines = [];
161
+ for (const change of changes) {
162
+ if (change.content !== null && !options.dryRun) {
163
+ const target = node_path_1.default.join(options.dir, change.file);
164
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(target), { recursive: true });
165
+ node_fs_1.default.writeFileSync(target, change.content);
166
+ }
167
+ lines.push(`${options.dryRun && change.content !== null ? '(dry run) ' : ''}${change.note}`);
168
+ }
169
+ lines.push('', 'Codex keeps servers in your own config; to add it there run:', ` codex mcp add ${exports.INIT_SERVER_NAME} --url "${exports.INIT_MCP_URL}"`, '', 'No key is needed for the demo tools. For your workspace, create a key at https://last-price.ai', 'and send it as the x-api-key header in the entries above.');
170
+ return lines;
171
+ }
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LastPriceClient } from '@last-price/tools-core';
2
2
  /** Matches `version` in package.json (a test holds the two together). */
3
- export declare const SERVER_VERSION = "0.2.0";
3
+ export declare const SERVER_VERSION = "0.6.1";
4
4
  /** MCP protocol revisions this server speaks, newest first. */
5
5
  export declare const SUPPORTED_PROTOCOLS: readonly ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
6
6
  export declare const SERVER_INSTRUCTIONS: string;
package/dist/server.js CHANGED
@@ -5,7 +5,7 @@ exports.handleMessage = handleMessage;
5
5
  exports.clientFromEnv = clientFromEnv;
6
6
  const tools_core_1 = require("@last-price/tools-core");
7
7
  /** Matches `version` in package.json (a test holds the two together). */
8
- exports.SERVER_VERSION = '0.2.0';
8
+ exports.SERVER_VERSION = '0.6.1';
9
9
  /** MCP protocol revisions this server speaks, newest first. */
10
10
  exports.SUPPORTED_PROTOCOLS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
11
11
  exports.SERVER_INSTRUCTIONS = 'Last Price: compute and verify prices, and manage your pricing workspace. With no credential only the public ' +
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@last-price/tools-mcp",
3
- "version": "0.2.0",
4
- "description": "A stdio MCP server for the Last Price pricing API, runnable with npx.",
3
+ "mcpName": "ai.last-price/pricing",
4
+ "version": "0.6.1",
5
+ "description": "The Last Price pricing API for coding agents: npx @last-price/tools-mcp init adds it to Claude Code, Cursor, VS Code, Gemini CLI and AGENTS.md; or run it as a stdio MCP server.",
5
6
  "license": "MIT",
6
7
  "homepage": "https://last-price.ai",
7
8
  "repository": {
@@ -15,9 +16,18 @@
15
16
  "keywords": [
16
17
  "last-price",
17
18
  "pricing",
19
+ "pricing-api",
20
+ "price-check",
18
21
  "agents",
19
22
  "mcp",
20
- "model-context-protocol"
23
+ "mcp-server",
24
+ "model-context-protocol",
25
+ "claude-code",
26
+ "codex",
27
+ "cursor",
28
+ "gemini-cli",
29
+ "agents-md",
30
+ "x402"
21
31
  ],
22
32
  "main": "./dist/index.js",
23
33
  "types": "./dist/index.d.ts",
@@ -46,7 +56,7 @@
46
56
  "provenance": true
47
57
  },
48
58
  "dependencies": {
49
- "@last-price/tools-core": "0.2.0"
59
+ "@last-price/tools-core": "0.6.1"
50
60
  },
51
61
  "scripts": {
52
62
  "build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/cli.js"