@commoditypriceapi/mcp 1.1.0 → 1.2.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 +45 -5
- package/dist/client.js +4 -2
- package/dist/server.js +27 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -221,7 +221,9 @@ Try these after setup:
|
|
|
221
221
|
|
|
222
222
|
## Tool Reference
|
|
223
223
|
|
|
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
|
|
224
|
+
All 8 tools map 1:1 to CommodityPriceAPI v3 endpoints. Tools that take `symbols` accept a comma-separated list (e.g. `XAU,XAG,XPT,BRENTOIL-SPOT`). Use `list_symbols` to look up valid symbols — there are 245 across Metals, Energy, Agriculture, and more.
|
|
225
|
+
|
|
226
|
+
Precious metals use ISO 4217 codes: `XAU` (gold), `XAG` (silver), `XPT` (platinum), `XPD` (palladium). Copper is `XCU`. The retired codes `PL`, `PA`, and `HG` still work on v3 — they are auto-resolved to the new symbol (see the note below).
|
|
225
227
|
|
|
226
228
|
### get_latest_rates
|
|
227
229
|
|
|
@@ -232,7 +234,13 @@ All 8 tools map 1:1 to CommodityPriceAPI v3 endpoints. Tools that take `symbols`
|
|
|
232
234
|
| `symbols` | Yes | Comma-separated symbols, e.g. `XAU,XAG,BRENTOIL-SPOT` |
|
|
233
235
|
| `quote` | No | Target quote currency (e.g. `EUR`). Premium/Plus plans only; omit for each symbol's default currency. |
|
|
234
236
|
|
|
235
|
-
Note
|
|
237
|
+
Note on `unresolved`: v3 appends an `unresolved` map, keyed by the symbol you typed, in three cases. The same applies to `get_historical_rates`, `get_time_series`, and `get_fluctuation`.
|
|
238
|
+
|
|
239
|
+
| Case | HTTP | What the entry holds |
|
|
240
|
+
|------|------|----------------------|
|
|
241
|
+
| Symbol is not a catalogue code but has exactly one match (e.g. `GOLD`, or retired `PL`) | `200` | `message` + `resolvedTo` — the rate was returned under `resolvedTo` in `rates`. Informational, not a failure. |
|
|
242
|
+
| Some symbols could not be returned | `206` | `message` + optional `suggestions` ("did you mean"). Valid rates are still in `rates`. |
|
|
243
|
+
| No symbol resolved | `404` | Tool returns a `SYMBOL_NOT_FOUND` error carrying the same `unresolved` map. |
|
|
236
244
|
|
|
237
245
|
### get_gold_price
|
|
238
246
|
|
|
@@ -241,14 +249,16 @@ Note: if some symbols in a multi-symbol request are invalid, the API returns the
|
|
|
241
249
|
| Parameter | Required | Description |
|
|
242
250
|
|-----------|----------|-------------|
|
|
243
251
|
| `quote` | No | Target quote currency. Premium/Plus plans only. |
|
|
252
|
+
| `include` | No | `gram`, `carat`, or `tola` — adds a per-gram rate, per-gram rates at each purity from 24k to 8k, or a per-tola rate alongside the ounce rate. |
|
|
244
253
|
|
|
245
254
|
### get_silver_price
|
|
246
255
|
|
|
247
|
-
`GET /v3/rates/latest/xag` — shortcut for the latest silver (XAG) rate.
|
|
256
|
+
`GET /v3/rates/latest/xag` — shortcut for the latest silver (XAG) rate, including bid/ask.
|
|
248
257
|
|
|
249
258
|
| Parameter | Required | Description |
|
|
250
259
|
|-----------|----------|-------------|
|
|
251
260
|
| `quote` | No | Target quote currency. Premium/Plus plans only. |
|
|
261
|
+
| `include` | No | `gram`, `carat`, or `tola` — adds a per-gram, per-carat, or per-tola rate alongside the ounce rate. |
|
|
252
262
|
|
|
253
263
|
### get_historical_rates
|
|
254
264
|
|
|
@@ -292,7 +302,8 @@ Note: if some symbols in a multi-symbol request are invalid, the API returns the
|
|
|
292
302
|
### Live prices
|
|
293
303
|
|
|
294
304
|
- What's the current gold price?
|
|
295
|
-
-
|
|
305
|
+
- What's gold per gram right now?
|
|
306
|
+
- Get the latest prices for silver, platinum, copper, and WTI crude.
|
|
296
307
|
- What's gold trading at in euros?
|
|
297
308
|
|
|
298
309
|
### Historical data
|
|
@@ -385,6 +396,35 @@ The text answers show what a client might say; exact wording depends on the mode
|
|
|
385
396
|
}
|
|
386
397
|
```
|
|
387
398
|
|
|
399
|
+
### Auto-resolved symbol
|
|
400
|
+
|
|
401
|
+
**Prompt:** What's the price of GOLD and platinum?
|
|
402
|
+
|
|
403
|
+
**Example answer:** Gold (XAU) is $4,386.23 and platinum (XPT) is $1,412.50 per troy ounce. Note: `GOLD` isn't a symbol code, so the API returned it under `XAU`.
|
|
404
|
+
|
|
405
|
+
```json
|
|
406
|
+
{
|
|
407
|
+
"success": true,
|
|
408
|
+
"timestamp": 1786617187,
|
|
409
|
+
"rates": {
|
|
410
|
+
"XAU": 4386.23,
|
|
411
|
+
"XPT": 1412.5
|
|
412
|
+
},
|
|
413
|
+
"metadata": {
|
|
414
|
+
"XAU": { "unit": "T.oz", "quote": "USD" },
|
|
415
|
+
"XPT": { "unit": "T.oz", "quote": "USD" }
|
|
416
|
+
},
|
|
417
|
+
"unresolved": {
|
|
418
|
+
"GOLD": {
|
|
419
|
+
"message": "GOLD is not a symbol code used by this API. Gold is available as \"XAU\", so its rate was returned under that symbol.",
|
|
420
|
+
"resolvedTo": "XAU"
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
Status is `200` — an entry with `resolvedTo` never downgrades the response.
|
|
427
|
+
|
|
388
428
|
## Error Codes
|
|
389
429
|
|
|
390
430
|
Tool calls never crash the server. Upstream errors are returned as structured tool results with `error`, `code`, `message`, and a `guidance` field so the client can explain what went wrong instead of echoing a status code.
|
|
@@ -457,7 +497,7 @@ COMMODITYPRICEAPI_KEY=<YOUR_KEY> npx @modelcontextprotocol/inspector node dist/c
|
|
|
457
497
|
|
|
458
498
|
**401 errors:** Check that `COMMODITYPRICEAPI_KEY` is set in your MCP client config's `env` block.
|
|
459
499
|
|
|
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. `
|
|
500
|
+
**A symbol is missing from a multi-symbol response:** Look at the `unresolved` map in the result. If the entry has `resolvedTo`, nothing is missing — the rate is in `rates` under that symbol (e.g. `GOLD` → `XAU`, `PL` → `XPT`). Otherwise each missing symbol has a message and usually `suggestions` (e.g. `OIL` → `WTIOIL-SPOT`, `BRENTOIL-SPOT`, …). If there are no suggestions, call `list_symbols` to find the correct symbol.
|
|
461
501
|
|
|
462
502
|
**499 timeouts:** The upstream API did not respond in time. Increase `COMMODITYPRICEAPI_REQUEST_TIMEOUT_MS` (default: 15000 ms).
|
|
463
503
|
|
package/dist/client.js
CHANGED
|
@@ -26,8 +26,10 @@ function getApiKey() {
|
|
|
26
26
|
* param, since the upstream API accepts either.
|
|
27
27
|
*
|
|
28
28
|
* v3 answers 206 (still `response.ok`) with an `unresolved` map appended to
|
|
29
|
-
* the body when some requested symbols could not be returned
|
|
30
|
-
*
|
|
29
|
+
* the body when some requested symbols could not be returned, and 200 with an
|
|
30
|
+
* `unresolved` map when a symbol was auto-resolved to its single match
|
|
31
|
+
* (`resolvedTo`). The body is passed through as-is so tool results include
|
|
32
|
+
* those notes and suggestions.
|
|
31
33
|
*/
|
|
32
34
|
export async function callCommodityApi(path, params = {}) {
|
|
33
35
|
const apiKey = getApiKey();
|
package/dist/server.js
CHANGED
|
@@ -3,8 +3,20 @@ 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'.
|
|
6
|
+
.describe("Comma-separated commodity symbols, e.g. 'XAU,XAG,XPT,BRENTOIL-SPOT'. Precious metals use ISO 4217 codes (XAU gold, XAG silver, XPT platinum, XPD palladium); copper is XCU. See the list_symbols tool for valid values. " +
|
|
7
|
+
"The response may include an 'unresolved' map keyed by the symbol you typed. Three cases: " +
|
|
8
|
+
"(1) HTTP 200 with an entry carrying 'resolvedTo' — the symbol was not a catalogue code but had exactly one match (e.g. GOLD -> XAU, retired PL -> XPT), so its rate was returned under the 'resolvedTo' symbol in 'rates'; this is informational, not a failure. " +
|
|
9
|
+
"(2) HTTP 206 — some symbols could not be returned; each entry has a message and, where available, 'did you mean' suggestions, while the valid rates are still in 'rates'. " +
|
|
10
|
+
"(3) If none resolve, the error result carries the same 'unresolved' map.");
|
|
7
11
|
const dateParam = z.string().describe("Date in YYYY-MM-DD format.");
|
|
12
|
+
const quoteParam = z
|
|
13
|
+
.string()
|
|
14
|
+
.optional()
|
|
15
|
+
.describe("Target quote currency code (e.g. 'USD', 'EUR'). Premium/Plus plans only; omit to use each symbol's default currency.");
|
|
16
|
+
const includeParam = z
|
|
17
|
+
.enum(["gram", "carat", "tola"])
|
|
18
|
+
.optional()
|
|
19
|
+
.describe("Add a per-unit breakdown alongside the per-troy-ounce rate: 'gram' adds a per-gram rate, 'tola' adds a per-tola rate, 'carat' adds per-gram rates at each purity from 24k down to 8k. Omit for the ounce rate only.");
|
|
8
20
|
function textResult(data) {
|
|
9
21
|
return {
|
|
10
22
|
content: [
|
|
@@ -65,7 +77,7 @@ function guidanceFor(code, errorType) {
|
|
|
65
77
|
export function createServer() {
|
|
66
78
|
const server = new McpServer({
|
|
67
79
|
name: "commoditypriceapi-mcp",
|
|
68
|
-
version: "1.
|
|
80
|
+
version: "1.2.0",
|
|
69
81
|
});
|
|
70
82
|
server.registerTool("get_usage", {
|
|
71
83
|
title: "Get API usage",
|
|
@@ -82,7 +94,7 @@ export function createServer() {
|
|
|
82
94
|
});
|
|
83
95
|
server.registerTool("list_symbols", {
|
|
84
96
|
title: "List supported commodity symbols",
|
|
85
|
-
description: "Returns all commodity symbols supported by CommodityPriceAPI, including category, default currency, and unit. Use this to look up a symbol before calling rate tools.",
|
|
97
|
+
description: "Returns all commodity symbols supported by CommodityPriceAPI, including category, default currency, and unit. Use this to look up a symbol before calling rate tools. Precious metals use ISO 4217 codes (XAU, XAG, XPT, XPD); copper is XCU.",
|
|
86
98
|
inputSchema: {},
|
|
87
99
|
}, async () => {
|
|
88
100
|
try {
|
|
@@ -95,13 +107,10 @@ export function createServer() {
|
|
|
95
107
|
});
|
|
96
108
|
server.registerTool("get_latest_rates", {
|
|
97
109
|
title: "Get latest commodity rates",
|
|
98
|
-
description: "Returns the latest rates for one or more commodity symbols (e.g. gold, silver, crude oil). Rates may lag up to 10 minutes depending on plan. Use 'quote' to convert to a specific currency (Premium/Plus plans only).",
|
|
110
|
+
description: "Returns the latest rates for one or more commodity symbols (e.g. gold, silver, crude oil). Rates may lag up to 10 minutes depending on plan. Use 'quote' to convert to a specific currency (Premium/Plus plans only). Common names with a single match (e.g. GOLD) are auto-resolved to the real symbol and flagged in 'unresolved' with 'resolvedTo'.",
|
|
99
111
|
inputSchema: {
|
|
100
112
|
symbols: symbolsParam,
|
|
101
|
-
quote:
|
|
102
|
-
.string()
|
|
103
|
-
.optional()
|
|
104
|
-
.describe("Target quote currency code (e.g. 'USD', 'EUR'). Premium/Plus plans only; omit to use each symbol's default currency."),
|
|
113
|
+
quote: quoteParam,
|
|
105
114
|
},
|
|
106
115
|
}, async ({ symbols, quote }) => {
|
|
107
116
|
try {
|
|
@@ -114,16 +123,14 @@ export function createServer() {
|
|
|
114
123
|
});
|
|
115
124
|
server.registerTool("get_gold_price", {
|
|
116
125
|
title: "Get latest gold (XAU) price",
|
|
117
|
-
description: "Shortcut for the latest gold (XAU) rate without needing to pass a symbols list.",
|
|
126
|
+
description: "Shortcut for the latest gold (XAU) rate, with bid/ask, without needing to pass a symbols list. Use 'include' to add a per-gram, per-tola, or per-carat breakdown.",
|
|
118
127
|
inputSchema: {
|
|
119
|
-
quote:
|
|
120
|
-
|
|
121
|
-
.optional()
|
|
122
|
-
.describe("Target quote currency code. Premium/Plus plans only."),
|
|
128
|
+
quote: quoteParam,
|
|
129
|
+
include: includeParam,
|
|
123
130
|
},
|
|
124
|
-
}, async ({ quote }) => {
|
|
131
|
+
}, async ({ quote, include }) => {
|
|
125
132
|
try {
|
|
126
|
-
const data = await callCommodityApi("/rates/latest/xau", { quote });
|
|
133
|
+
const data = await callCommodityApi("/rates/latest/xau", { quote, include });
|
|
127
134
|
return textResult(data);
|
|
128
135
|
}
|
|
129
136
|
catch (err) {
|
|
@@ -132,16 +139,14 @@ export function createServer() {
|
|
|
132
139
|
});
|
|
133
140
|
server.registerTool("get_silver_price", {
|
|
134
141
|
title: "Get latest silver (XAG) price",
|
|
135
|
-
description: "Shortcut for the latest silver (XAG) rate without needing to pass a symbols list.",
|
|
142
|
+
description: "Shortcut for the latest silver (XAG) rate, with bid/ask, without needing to pass a symbols list. Use 'include' to add a per-gram, per-tola, or per-carat breakdown.",
|
|
136
143
|
inputSchema: {
|
|
137
|
-
quote:
|
|
138
|
-
|
|
139
|
-
.optional()
|
|
140
|
-
.describe("Target quote currency code. Premium/Plus plans only."),
|
|
144
|
+
quote: quoteParam,
|
|
145
|
+
include: includeParam,
|
|
141
146
|
},
|
|
142
|
-
}, async ({ quote }) => {
|
|
147
|
+
}, async ({ quote, include }) => {
|
|
143
148
|
try {
|
|
144
|
-
const data = await callCommodityApi("/rates/latest/xag", { quote });
|
|
149
|
+
const data = await callCommodityApi("/rates/latest/xag", { quote, include });
|
|
145
150
|
return textResult(data);
|
|
146
151
|
}
|
|
147
152
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commoditypriceapi/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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",
|