@pipeworx/mcp-metals-api 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pipeworx
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 ADDED
@@ -0,0 +1,55 @@
1
+ # mcp-metals-api
2
+
3
+ Metals API MCP — wraps Metals-API (metals-api.com)
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 965+ live data sources.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+
12
+ ## Quick Start
13
+
14
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "metals-api": {
20
+ "url": "https://gateway.pipeworx.io/metals-api/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 965+ data sources:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "pipeworx": {
32
+ "url": "https://gateway.pipeworx.io/mcp"
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Using with ask_pipeworx
39
+
40
+ Instead of calling tools directly, you can ask questions in plain English:
41
+
42
+ ```
43
+ ask_pipeworx({ question: "your question about Metals Api data" })
44
+ ```
45
+
46
+ The gateway picks the right tool and fills the arguments automatically.
47
+
48
+ ## More
49
+
50
+ - [All tools and guides](https://github.com/pipeworx-io/examples)
51
+ - [pipeworx.io](https://pipeworx.io)
52
+
53
+ ## License
54
+
55
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-metals-api",
3
+ "version": "0.1.0",
4
+ "description": "Metals API MCP — wraps Metals-API (metals-api.com)",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "metals-api"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-metals-api"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/metals-api",
4
+ "title": "Metals Api",
5
+ "description": "Metals API MCP — wraps Metals-API (metals-api.com)",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/metals-api",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-metals-api",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/metals-api/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,174 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ meter?: { credits: number };
15
+ cost?: Record<string, unknown>;
16
+ provider?: string;
17
+ }
18
+
19
+ /**
20
+ * Metals API MCP — wraps Metals-API (metals-api.com)
21
+ *
22
+ * BYO key: requires an API key from https://metals-api.com/
23
+ * Passed via _apiKey parameter. Free tier: 50 requests/month.
24
+ *
25
+ * Tools:
26
+ * - get_latest: get latest precious/base metal prices
27
+ * - get_historical: get metal prices for a specific date
28
+ */
29
+
30
+
31
+ const BASE = 'https://metals-api.com/api';
32
+
33
+ // ── Helpers ───────────────────────────────────────────────────────────
34
+
35
+ function extractKey(args: Record<string, unknown>): string {
36
+ const key = args._apiKey as string;
37
+ delete args._apiKey;
38
+ if (!key) throw new Error('Metals-API key required. Get one at https://metals-api.com/ and pass via _apiKey.');
39
+ return key;
40
+ }
41
+
42
+ async function metalsGet(apiKey: string, path: string, params: Record<string, string>): Promise<unknown> {
43
+ const url = new URL(`${BASE}${path}`);
44
+ url.searchParams.set('access_key', apiKey);
45
+ for (const [k, v] of Object.entries(params)) {
46
+ url.searchParams.set(k, v);
47
+ }
48
+
49
+ const res = await fetch(url.toString(), {
50
+ headers: { Accept: 'application/json' },
51
+ });
52
+ if (!res.ok) {
53
+ const text = await res.text();
54
+ throw new Error(`Metals-API error (${res.status}): ${text}`);
55
+ }
56
+
57
+ const data = (await res.json()) as Record<string, unknown>;
58
+ if (data.success === false) {
59
+ const err = data.error as { info?: string; type?: string } | undefined;
60
+ throw new Error(`Metals-API error: ${err?.info ?? err?.type ?? 'Unknown error'}`);
61
+ }
62
+
63
+ return data;
64
+ }
65
+
66
+ // ── Tool definitions ──────────────────────────────────────────────────
67
+
68
+ const tools: McpToolExport['tools'] = [
69
+ {
70
+ name: 'get_latest',
71
+ description:
72
+ 'Get the latest precious and base metal spot prices (gold, silver, platinum, palladium, copper, etc.). Prices are per troy ounce. Optionally specify base currency and metal symbols.',
73
+ inputSchema: {
74
+ type: 'object' as const,
75
+ properties: {
76
+ _apiKey: { type: 'string', description: 'Metals-API key' },
77
+ base: {
78
+ type: 'string',
79
+ description: 'Base currency (default "USD"). E.g., "EUR", "GBP"',
80
+ },
81
+ symbols: {
82
+ type: 'string',
83
+ description: 'Comma-separated metal symbols to filter (e.g., "XAU,XAG,XPT"). XAU=gold, XAG=silver, XPT=platinum, XPD=palladium, XCU=copper',
84
+ },
85
+ },
86
+ required: ['_apiKey'],
87
+ },
88
+ },
89
+ {
90
+ name: 'get_historical',
91
+ description:
92
+ 'Get metal prices for a specific historical date. Returns spot prices per troy ounce for that day. Useful for tracking price changes or computing returns.',
93
+ inputSchema: {
94
+ type: 'object' as const,
95
+ properties: {
96
+ _apiKey: { type: 'string', description: 'Metals-API key' },
97
+ date: {
98
+ type: 'string',
99
+ description: 'Date in YYYY-MM-DD format (e.g., "2024-01-15")',
100
+ },
101
+ base: {
102
+ type: 'string',
103
+ description: 'Base currency (default "USD")',
104
+ },
105
+ symbols: {
106
+ type: 'string',
107
+ description: 'Comma-separated metal symbols (e.g., "XAU,XAG")',
108
+ },
109
+ },
110
+ required: ['_apiKey', 'date'],
111
+ },
112
+ },
113
+ ];
114
+
115
+ // ── callTool dispatcher ───────────────────────────────────────────────
116
+
117
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
118
+ const key = extractKey(args);
119
+
120
+ switch (name) {
121
+ case 'get_latest':
122
+ return getLatest(key, args.base as string | undefined, args.symbols as string | undefined);
123
+ case 'get_historical':
124
+ return getHistorical(key, args.date as string, args.base as string | undefined, args.symbols as string | undefined);
125
+ default:
126
+ throw new Error(`Unknown tool: ${name}`);
127
+ }
128
+ }
129
+
130
+ // ── Tool implementations ─────────────────────────────────────────────
131
+
132
+ async function getLatest(apiKey: string, base?: string, symbols?: string) {
133
+ const params: Record<string, string> = {};
134
+ if (base) params.base = base;
135
+ if (symbols) params.symbols = symbols;
136
+
137
+ const data = (await metalsGet(apiKey, '/latest', params)) as {
138
+ success: boolean;
139
+ base: string;
140
+ date: string;
141
+ rates: Record<string, number>;
142
+ timestamp: number;
143
+ };
144
+
145
+ return {
146
+ base: data.base,
147
+ date: data.date,
148
+ timestamp: data.timestamp,
149
+ rates: data.rates,
150
+ };
151
+ }
152
+
153
+ async function getHistorical(apiKey: string, date: string, base?: string, symbols?: string) {
154
+ const params: Record<string, string> = {};
155
+ if (base) params.base = base;
156
+ if (symbols) params.symbols = symbols;
157
+
158
+ const data = (await metalsGet(apiKey, `/${date}`, params)) as {
159
+ success: boolean;
160
+ base: string;
161
+ date: string;
162
+ rates: Record<string, number>;
163
+ timestamp: number;
164
+ };
165
+
166
+ return {
167
+ base: data.base,
168
+ date: data.date,
169
+ timestamp: data.timestamp,
170
+ rates: data.rates,
171
+ };
172
+ }
173
+
174
+ export default { tools, callTool, meter: { credits: 5 } } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }