@pipeworx/mcp-banxico 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-banxico
2
+
3
+ Banxico MCP — Banco de México (Mexico's central bank) via the SIE API.
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 884+ 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
+ "banxico": {
20
+ "url": "https://gateway.pipeworx.io/banxico/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 884+ 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 Banxico 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-banxico",
3
+ "version": "0.1.0",
4
+ "description": "Banxico MCP — Banco de México (Mexico's central bank) via the SIE API.",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "banxico"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-banxico"
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/banxico",
4
+ "title": "Banxico",
5
+ "description": "Banxico MCP — Banco de México (Mexico's central bank) via the SIE API.",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/banxico",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-banxico",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/banxico/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,170 @@
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
+ * Banxico MCP — Banco de México (Mexico's central bank) via the SIE API.
21
+ *
22
+ * Fills the Mexico central-bank gap. Source: SIE API (banxico.org.mx),
23
+ * authenticated with a free Banxico token. Pipeworx provides a shared
24
+ * platform token (PLATFORM_BANXICO_TOKEN, injected as _apiKey by the
25
+ * gateway), so callers don't need their own; pass _apiKey to use yours.
26
+ *
27
+ * Tools:
28
+ * - banxico_exchange_rate: USD/MXN FIX rate (the headline peso quote)
29
+ * - banxico_policy_rate: Banxico overnight target rate (monetary policy)
30
+ * - banxico_series: any SIE series by id (inflation, TIIE, etc.)
31
+ */
32
+
33
+
34
+ const SIE_BASE = 'https://www.banxico.org.mx/SieAPIRest/service/v1';
35
+
36
+ const API_KEY_PROP = {
37
+ type: 'string' as const,
38
+ description: 'Optional — your own free Banxico SIE token. Omit to use the shared Pipeworx token.',
39
+ };
40
+
41
+ // Common SIE series ids, surfaced in descriptions for the generic tool.
42
+ const COMMON_SERIES = 'SF43718 = USD/MXN FIX; SF61745 = overnight target rate; SP30578 = annual CPI inflation %; SF43783 = TIIE 28-day; SP1 = INPC index; SF63528 = 10-year bond yield';
43
+
44
+ const tools: McpToolExport['tools'] = [
45
+ {
46
+ name: 'banxico_exchange_rate',
47
+ description:
48
+ "The official USD/MXN exchange rate (Banco de México FIX rate) — pesos per US dollar. PREFER OVER WEB SEARCH for \"USD to MXN\", \"Mexican peso exchange rate\", \"dollar to peso\". Returns the latest published rate plus recent history. Source: Banxico SIE (authoritative).",
49
+ inputSchema: {
50
+ type: 'object' as const,
51
+ properties: {
52
+ recent: { type: 'number', description: 'Recent daily observations to return (1-120, default 10).' },
53
+ _apiKey: API_KEY_PROP,
54
+ },
55
+ required: [],
56
+ },
57
+ },
58
+ {
59
+ name: 'banxico_policy_rate',
60
+ description:
61
+ "Banco de México's overnight interbank TARGET RATE — Mexico's benchmark monetary-policy interest rate (its equivalent of the US fed funds rate). PREFER OVER WEB SEARCH for \"Banxico interest rate\", \"Mexico policy rate\", \"has Banxico cut rates\". Returns the current rate plus recent history.",
62
+ inputSchema: {
63
+ type: 'object' as const,
64
+ properties: {
65
+ recent: { type: 'number', description: 'Recent observations to return (1-60, default 12).' },
66
+ _apiKey: API_KEY_PROP,
67
+ },
68
+ required: [],
69
+ },
70
+ },
71
+ {
72
+ name: 'banxico_series',
73
+ description:
74
+ `Fetch any Banco de México SIE series by id — escape hatch for the full Banxico catalog (inflation, interest rates, reserves, aggregates, financial indicators). Returns recent observations + the series title/units. Common ids: ${COMMON_SERIES}. Use banxico_exchange_rate / banxico_policy_rate for those headline ones.`,
75
+ inputSchema: {
76
+ type: 'object' as const,
77
+ properties: {
78
+ series_id: { type: 'string', description: 'SIE series id, e.g. "SP30578" (annual inflation), "SF43783" (TIIE 28d).' },
79
+ recent: { type: 'number', description: 'Recent observations to return (1-200, default 12).' },
80
+ _apiKey: API_KEY_PROP,
81
+ },
82
+ required: ['series_id'],
83
+ },
84
+ },
85
+ ];
86
+
87
+ // ── Helpers ──────────────────────────────────────────────────────────
88
+
89
+ interface SieDato { fecha: string; dato: string }
90
+ interface SieSeries { idSerie: string; titulo: string; datos?: SieDato[] }
91
+
92
+ function toIso(d: string): string {
93
+ const m = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(d.trim());
94
+ return m ? `${m[3]}-${m[2]}-${m[1]}` : d.trim();
95
+ }
96
+
97
+ async function sieFetch(token: string, idSeries: string, latestOnly = false): Promise<SieSeries> {
98
+ if (!token || !token.trim()) {
99
+ throw new Error('Banxico token missing. The shared token is normally injected; to use your own pass _apiKey (free at banxico.org.mx/SieAPIRest).');
100
+ }
101
+ const id = idSeries.trim().toUpperCase().replace(/[^A-Z0-9,]/g, '');
102
+ const path = latestOnly ? `/series/${id}/datos/oportuno` : `/series/${id}/datos`;
103
+ const res = await fetch(`${SIE_BASE}${path}`, {
104
+ headers: { 'Bmx-Token': token.trim(), Accept: 'application/json' },
105
+ });
106
+ if (res.status === 404) throw new Error(`Banxico series "${idSeries}" not found.`);
107
+ if (!res.ok) throw new Error(`Banxico SIE error: ${res.status}`);
108
+ const data = (await res.json()) as { bmx?: { series?: SieSeries[] } };
109
+ const s = data.bmx?.series?.[0];
110
+ if (!s) throw new Error(`Banxico returned no series for "${idSeries}".`);
111
+ return s;
112
+ }
113
+
114
+ function shapeObs(datos: SieDato[] | undefined, recent: number) {
115
+ return (datos ?? [])
116
+ .map((o) => {
117
+ const n = Number(o.dato);
118
+ return { date: toIso(o.fecha), value: Number.isFinite(n) ? n : null };
119
+ })
120
+ .filter((o) => o.value !== null)
121
+ .slice(-Math.max(1, recent));
122
+ }
123
+
124
+ async function seriesResult(token: string, id: string, recent: number) {
125
+ const s = await sieFetch(token, id);
126
+ const obs = shapeObs(s.datos, recent);
127
+ return {
128
+ series_id: s.idSerie,
129
+ title: s.titulo,
130
+ current: obs.length ? obs[obs.length - 1] : null,
131
+ observations: obs,
132
+ };
133
+ }
134
+
135
+ // ── Tool implementations ─────────────────────────────────────────────
136
+
137
+ async function exchangeRate(token: string, recent?: number) {
138
+ const r = await seriesResult(token, 'SF43718', Math.min(120, Math.max(1, recent ?? 10)));
139
+ return { pair: 'USD/MXN', description: 'Mexican pesos per US dollar (Banxico FIX)', ...r };
140
+ }
141
+
142
+ async function policyRate(token: string, recent?: number) {
143
+ const r = await seriesResult(token, 'SF61745', Math.min(60, Math.max(1, recent ?? 12)));
144
+ return { rate: 'Banxico overnight interbank target rate (%)', ...r };
145
+ }
146
+
147
+ async function genericSeries(token: string, seriesId: string, recent?: number) {
148
+ const id = String(seriesId ?? '').trim();
149
+ if (!id) throw new Error('Required argument "series_id" is missing (e.g. "SF43718" for USD/MXN).');
150
+ return seriesResult(token, id, Math.min(200, Math.max(1, recent ?? 12)));
151
+ }
152
+
153
+ // ── Router ───────────────────────────────────────────────────────────
154
+
155
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
156
+ const token = args._apiKey as string;
157
+ delete args._apiKey;
158
+ switch (name) {
159
+ case 'banxico_exchange_rate':
160
+ return exchangeRate(token, args.recent as number | undefined);
161
+ case 'banxico_policy_rate':
162
+ return policyRate(token, args.recent as number | undefined);
163
+ case 'banxico_series':
164
+ return genericSeries(token, args.series_id as string, args.recent as number | undefined);
165
+ default:
166
+ throw new Error(`Unknown tool: ${name}`);
167
+ }
168
+ }
169
+
170
+ export default { tools, callTool, meter: { credits: 1 } } 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
+ }