@commoditypriceapi/mcp 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -221,22 +221,22 @@ Try these after setup:
221
221
 
222
222
  ## Tool Reference
223
223
 
224
- All 8 tools map 1:1 to CommodityPriceAPI v2 endpoints. Tools that take `symbols` accept a comma-separated list (e.g. `XAU,XAG,BRENTOIL-SPOT`). Use `list_symbols` to look up valid symbols — there are 148 across Metals, Energy, Agriculture, and more.
224
+ All 8 tools map 1:1 to CommodityPriceAPI v3 endpoints. Tools that take `symbols` accept a comma-separated list (e.g. `XAU,XAG,BRENTOIL-SPOT`). Use `list_symbols` to look up valid symbols — there are 148 across Metals, Energy, Agriculture, and more.
225
225
 
226
226
  ### get_latest_rates
227
227
 
228
- `GET /v2/rates/latest` — latest rates for one or more symbols. Rates may lag up to 10 minutes depending on plan.
228
+ `GET /v3/rates/latest` — latest rates for one or more symbols. Rates may lag up to 10 minutes depending on plan.
229
229
 
230
230
  | Parameter | Required | Description |
231
231
  |-----------|----------|-------------|
232
232
  | `symbols` | Yes | Comma-separated symbols, e.g. `XAU,XAG,BRENTOIL-SPOT` |
233
233
  | `quote` | No | Target quote currency (e.g. `EUR`). Premium/Plus plans only; omit for each symbol's default currency. |
234
234
 
235
- Note: if a symbol in a multi-symbol request is invalid, the API silently omits it from the response rather than returning an error. A missing symbol in the result means the symbol is wrong — check `list_symbols`.
235
+ Note: if some symbols in a multi-symbol request are invalid, the API returns the valid rates (HTTP 206) plus an `unresolved` map — one entry per missing symbol with a message and, where available, `suggestions` ("did you mean"). If no symbol resolves, the tool returns a `SYMBOL_NOT_FOUND` error carrying the same `unresolved` map. The same applies to `get_historical_rates`, `get_time_series`, and `get_fluctuation`.
236
236
 
237
237
  ### get_gold_price
238
238
 
239
- `GET /v2/rates/latest/xau` — shortcut for the latest gold (XAU) rate, including bid/ask.
239
+ `GET /v3/rates/latest/xau` — shortcut for the latest gold (XAU) rate, including bid/ask.
240
240
 
241
241
  | Parameter | Required | Description |
242
242
  |-----------|----------|-------------|
@@ -244,7 +244,7 @@ Note: if a symbol in a multi-symbol request is invalid, the API silently omits i
244
244
 
245
245
  ### get_silver_price
246
246
 
247
- `GET /v2/rates/latest/xag` — shortcut for the latest silver (XAG) rate.
247
+ `GET /v3/rates/latest/xag` — shortcut for the latest silver (XAG) rate.
248
248
 
249
249
  | Parameter | Required | Description |
250
250
  |-----------|----------|-------------|
@@ -252,7 +252,7 @@ Note: if a symbol in a multi-symbol request is invalid, the API silently omits i
252
252
 
253
253
  ### get_historical_rates
254
254
 
255
- `GET /v2/rates/historical` — open/high/low/close rates for one or more symbols on a specific past date, available back to 1990-01-01. If no rate exists for that exact date, the API returns the nearest available date.
255
+ `GET /v3/rates/historical` — open/high/low/close rates for one or more symbols on a specific past date, available back to 1990-01-01. If no rate exists for that exact date, the API returns the nearest available date.
256
256
 
257
257
  | Parameter | Required | Description |
258
258
  |-----------|----------|-------------|
@@ -261,7 +261,7 @@ Note: if a symbol in a multi-symbol request is invalid, the API silently omits i
261
261
 
262
262
  ### get_time_series
263
263
 
264
- `GET /v2/rates/time-series` — daily historical rates for one or more symbols between two dates. Max span: 1 year.
264
+ `GET /v3/rates/time-series` — daily historical rates for one or more symbols between two dates. Max span: 1 year.
265
265
 
266
266
  | Parameter | Required | Description |
267
267
  |-----------|----------|-------------|
@@ -271,7 +271,7 @@ Note: if a symbol in a multi-symbol request is invalid, the API silently omits i
271
271
 
272
272
  ### get_fluctuation
273
273
 
274
- `GET /v2/rates/fluctuation` — how each symbol changed between two dates: start rate, end rate, absolute change, and percent change.
274
+ `GET /v3/rates/fluctuation` — how each symbol changed between two dates: start rate, end rate, absolute change, and percent change.
275
275
 
276
276
  | Parameter | Required | Description |
277
277
  |-----------|----------|-------------|
@@ -281,11 +281,11 @@ Note: if a symbol in a multi-symbol request is invalid, the API silently omits i
281
281
 
282
282
  ### list_symbols
283
283
 
284
- `GET /v2/symbols` — all supported commodity symbols with name, category, quote currency, unit, and update interval. Takes no parameters. Call this before rate tools when unsure of a symbol.
284
+ `GET /v3/symbols` — all supported commodity symbols with name, category, quote currency, unit, and update interval. Takes no parameters. Call this before rate tools when unsure of a symbol.
285
285
 
286
286
  ### get_usage
287
287
 
288
- `GET /v2/usage` — current plan, quota, and usage for the configured API key. Takes no parameters.
288
+ `GET /v3/usage` — current plan, quota, and usage for the configured API key. Takes no parameters.
289
289
 
290
290
  ## Prompt Examples
291
291
 
@@ -412,7 +412,7 @@ Example error result for an invalid symbol:
412
412
 
413
413
  ## How It Works
414
414
 
415
- This is a stdio MCP server that wraps the CommodityPriceAPI v2 REST API.
415
+ This is a stdio MCP server that wraps the CommodityPriceAPI v3 REST API.
416
416
 
417
417
  At runtime:
418
418
 
@@ -457,7 +457,7 @@ COMMODITYPRICEAPI_KEY=<YOUR_KEY> npx @modelcontextprotocol/inspector node dist/c
457
457
 
458
458
  **401 errors:** Check that `COMMODITYPRICEAPI_KEY` is set in your MCP client config's `env` block.
459
459
 
460
- **A symbol is missing from a multi-symbol response:** The upstream API silently drops invalid symbols instead of erroring. Call `list_symbols` to find the correct symbol — e.g. Brent crude is `BRENTOIL-SPOT`, not `BRENTOIL`.
460
+ **A symbol is missing from a multi-symbol response:** Look at the `unresolved` map in the result — each missing symbol has a message and usually `suggestions` (e.g. `BRENTOIL` → `BRENTOIL-SPOT`). If there are no suggestions, call `list_symbols` to find the correct symbol.
461
461
 
462
462
  **499 timeouts:** The upstream API did not respond in time. Increase `COMMODITYPRICEAPI_REQUEST_TIMEOUT_MS` (default: 15000 ms).
463
463
 
package/dist/client.js CHANGED
@@ -1,14 +1,16 @@
1
- const BASE_URL = "https://api.commoditypriceapi.com/v2";
1
+ const BASE_URL = "https://api.commoditypriceapi.com/v3";
2
2
  export class CommodityApiError extends Error {
3
3
  code;
4
4
  errorType;
5
5
  path;
6
- constructor(code, errorType, message, path) {
6
+ unresolved;
7
+ constructor(code, errorType, message, path, unresolved) {
7
8
  super(message);
8
9
  this.name = "CommodityApiError";
9
10
  this.code = code;
10
11
  this.errorType = errorType;
11
12
  this.path = path;
13
+ this.unresolved = unresolved;
12
14
  }
13
15
  }
14
16
  function getApiKey() {
@@ -19,9 +21,13 @@ function getApiKey() {
19
21
  return key;
20
22
  }
21
23
  /**
22
- * Calls a CommodityPriceAPI v2 endpoint.
24
+ * Calls a CommodityPriceAPI v3 endpoint.
23
25
  * Sends the API key via both the x-api-key header AND the apiKey query
24
26
  * param, since the upstream API accepts either.
27
+ *
28
+ * v3 answers 206 (still `response.ok`) with an `unresolved` map appended to
29
+ * the body when some requested symbols could not be returned; the body is
30
+ * passed through as-is so tool results include those suggestions.
25
31
  */
26
32
  export async function callCommodityApi(path, params = {}) {
27
33
  const apiKey = getApiKey();
@@ -64,7 +70,7 @@ export async function callCommodityApi(path, params = {}) {
64
70
  throw new CommodityApiError(response.status, "INVALID_RESPONSE", `CommodityPriceAPI returned a non-JSON response: ${text.slice(0, 500)}`);
65
71
  }
66
72
  if (!response.ok) {
67
- throw new CommodityApiError(response.status, body.error ?? "UNKNOWN_ERROR", body.message ?? `CommodityPriceAPI request failed with status ${response.status}.`, body.path);
73
+ throw new CommodityApiError(response.status, body.error ?? "UNKNOWN_ERROR", body.message ?? `CommodityPriceAPI request failed with status ${response.status}.`, body.path, body.unresolved);
68
74
  }
69
75
  return body;
70
76
  }
package/dist/server.js CHANGED
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  import { callCommodityApi, CommodityApiError } from "./client.js";
4
4
  const symbolsParam = z
5
5
  .string()
6
- .describe("Comma-separated commodity symbols, e.g. 'XAU,XAG,BRENTOIL-SPOT'. See the list_symbols tool for valid values. Invalid symbols in a multi-symbol request are silently omitted from the response, not errored.");
6
+ .describe("Comma-separated commodity symbols, e.g. 'XAU,XAG,BRENTOIL-SPOT'. See the list_symbols tool for valid values. If some symbols cannot be resolved, the response still succeeds (HTTP 206) with the valid rates plus an 'unresolved' map giving a message and 'did you mean' suggestions for each missing symbol. If none resolve, the error result carries the same 'unresolved' map.");
7
7
  const dateParam = z.string().describe("Date in YYYY-MM-DD format.");
8
8
  function textResult(data) {
9
9
  return {
@@ -26,6 +26,7 @@ function errorResult(err) {
26
26
  error: err.errorType,
27
27
  code: err.code,
28
28
  message: err.message,
29
+ ...(err.unresolved ? { unresolved: err.unresolved } : {}),
29
30
  guidance: guidanceFor(err.code, err.errorType),
30
31
  }, null, 2),
31
32
  },
@@ -52,7 +53,7 @@ function guidanceFor(code, errorType) {
52
53
  return "You've hit your API key's usage limit. Upgrade your plan or wait for the quota to reset.";
53
54
  case 404:
54
55
  if (errorType === "SYMBOL_NOT_FOUND") {
55
- return "Call list_symbols to see valid commodity symbols.";
56
+ return "None of the requested symbols are valid. Check the 'unresolved' map above for suggested symbols, or call list_symbols to see all valid commodity symbols.";
56
57
  }
57
58
  return "The requested resource was not found.";
58
59
  case 429:
@@ -64,7 +65,7 @@ function guidanceFor(code, errorType) {
64
65
  export function createServer() {
65
66
  const server = new McpServer({
66
67
  name: "commoditypriceapi-mcp",
67
- version: "1.0.1",
68
+ version: "1.1.0",
68
69
  });
69
70
  server.registerTool("get_usage", {
70
71
  title: "Get API usage",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commoditypriceapi/mcp",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Official MCP server for CommodityPriceAPI \u2014 real-time and historical commodity rates (gold, silver, oil, and 130+ more) as MCP tools for Claude, Cursor, Windsurf, and any MCP client.",
5
5
  "keywords": [
6
6
  "mcp",