nirium-mcp 0.4.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.
Files changed (4) hide show
  1. package/LICENSE +171 -0
  2. package/README.md +73 -0
  3. package/dist/index.js +292 -0
  4. package/package.json +63 -0
package/LICENSE ADDED
@@ -0,0 +1,171 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or otherwise designated in writing by the copyright owner as
57
+ "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and subsequently
61
+ incorporated within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any Contribution
81
+ incorporated within the Work constitutes direct or contributory patent
82
+ infringement, then any patent licenses granted to You under this License
83
+ for that Work shall terminate as of the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the
86
+ Work or Derivative Works thereof in any medium, with or without
87
+ modifications, and in Source or Object form, provided that You
88
+ meet the following conditions:
89
+
90
+ (a) You must give any other recipients of the Work or Derivative Works
91
+ a copy of this License; and
92
+
93
+ (b) You must cause any modified files to carry prominent notices
94
+ stating that You changed the files; and
95
+
96
+ (c) You must retain, in the Source form of any Derivative Works
97
+ that You distribute, all copyright, patent, trademark, and
98
+ attribution notices from the Source form of the Work,
99
+ excluding those notices that do not pertain to any part of
100
+ the Derivative Works; and
101
+
102
+ (d) If the Work includes a "NOTICE" text file as part of its
103
+ distribution, You must include a readable copy of the attribution
104
+ notices contained within such NOTICE file, in at least one of the
105
+ following places: within a NOTICE text file distributed as part of
106
+ the Derivative Works; within the Source form or documentation, if
107
+ provided along with the Derivative Works; or, within a display
108
+ generated by the Derivative Works, if and wherever such third-party
109
+ notices normally appear. The contents of the NOTICE file are for
110
+ informational purposes only and do not modify the License.
111
+
112
+ (e) You may add Your own attribution notices within Derivative Works
113
+ that You distribute, alongside or as an addendum to the NOTICE text
114
+ from the Work, provided that such additional attribution notices
115
+ cannot be construed as modifying the License.
116
+
117
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
118
+ any Contribution intentionally submitted for inclusion in the Work
119
+ by You to the Licensor shall be under the terms and conditions of
120
+ this License, without any additional terms or conditions.
121
+
122
+ 6. Trademarks. This License does not grant permission to use the trade
123
+ names, trademarks, service marks, or product names of the Licensor,
124
+ except as required for reasonable and customary use in describing the
125
+ origin of the Work and reproducing the content of the NOTICE file.
126
+
127
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
128
+ to in writing, Licensor provides the Work (and each Contributor provides
129
+ its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
130
+ OF ANY KIND, either express or implied, including, without limitation,
131
+ any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY,
132
+ or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
133
+ determining the appropriateness of using or redistributing the Work and
134
+ assume any risks associated with Your exercise of permissions under this
135
+ License.
136
+
137
+ 8. Limitation of Liability. In no event and under no legal theory, whether
138
+ in tort (including negligence), contract, or otherwise, unless required
139
+ by applicable law (such as deliberate and grossly negligent acts) or
140
+ agreed to in writing, shall any Contributor be liable to You for damages,
141
+ including any direct, indirect, special, incidental, or consequential
142
+ damages of any character arising as a result of this License or out of
143
+ the use or inability to use the Work (including but not limited to
144
+ damages for loss of goodwill, work stoppage, computer failure or
145
+ malfunction, or all other commercial damages or losses), even if such
146
+ Contributor has been advised of the possibility of such damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing the
149
+ Work or Derivative Works thereof, You may choose to offer, and charge a
150
+ fee for, acceptance of support, warranty, indemnity, or other liability
151
+ obligations and rights consistent with this License. However, in
152
+ accepting such obligations, You may offer only conditions consistent
153
+ with this License. You must indemnify every Contributor for any
154
+ liability incurred by, or claims asserted against, such Contributor by
155
+ reason of your accepting any such warranty or additional liability.
156
+
157
+ END OF TERMS AND CONDITIONS
158
+
159
+ Copyright 2026 Nirium Protocol Contributors
160
+
161
+ Licensed under the Apache License, Version 2.0 (the "License");
162
+ you may not use this file except in compliance with the License.
163
+ You may obtain a copy of the License at
164
+
165
+ http://www.apache.org/licenses/LICENSE-2.0
166
+
167
+ Unless required by applicable law or agreed to in writing, software
168
+ distributed under the License is distributed on an "AS IS" BASIS,
169
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170
+ See the License for the specific language governing permissions and
171
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # nirium-mcp
2
+
3
+ Model Context Protocol server for [Nirium](https://nirium.xyz) — exposes market data, autonomous treasury loop control, and x402/MPP paid signals to any MCP-compatible AI: Claude, GPT, Cursor, VS Code Copilot, and others.
4
+
5
+ Software-only. This server never holds funds — paid tools sign per-request payments from a Stellar wallet you control via `STELLAR_SECRET_KEY`.
6
+
7
+ ## Install
8
+
9
+ No install needed — run directly with `npx`, or add to your MCP client config.
10
+
11
+ ## Claude Desktop config
12
+
13
+ ```json
14
+ {
15
+ "mcpServers": {
16
+ "nirium": {
17
+ "command": "npx",
18
+ "args": ["-y", "nirium-mcp"],
19
+ "env": {
20
+ "AGENT_API_URL": "https://nirium-agent.fly.dev",
21
+ "STELLAR_SECRET_KEY": "S...",
22
+ "NIRIUM_API_KEY": "sk_free_..."
23
+ }
24
+ }
25
+ }
26
+ }
27
+ ```
28
+
29
+ `STELLAR_SECRET_KEY` and `NIRIUM_API_KEY` are optional — omit them and the free tools still work; paid (x402/MPP) and authenticated tools will tell you what's missing instead of failing silently.
30
+
31
+ ## Tools
32
+
33
+ **Free — no key required**
34
+ - `get_market_state` — XLM/USDC price, SDEX spread, base fee, Blend rate
35
+ - `get_loop_status` — autonomous loop status, scan count, last AI decision
36
+ - `execute_demo` — dry-run a strategy via real Soroban simulation, no funds moved
37
+ - `get_wallet_info` — show the configured x402/MPP wallet and enabled tools
38
+
39
+ **Authenticated — requires `NIRIUM_API_KEY`**
40
+ - `start_loop` — start the autonomous scanning loop
41
+ - `stop_loop` — stop it
42
+
43
+ **Paid via x402 — requires a funded `STELLAR_SECRET_KEY`**
44
+ - `get_premium_signals` — $0.02 USDC — arbitrage signals with execution paths and confidence scores
45
+ - `get_premium_market` — $0.05 USDC — enriched market state
46
+ - `execute_paid_strategy` — $0.25 USDC — execute a strategy on-chain, no account required
47
+
48
+ **Paid via MPP — requires a funded `STELLAR_SECRET_KEY`**
49
+ - `get_mpp_signals` — $0.01 USDC — same signal data as `get_premium_signals`, settled via direct Soroban SAC transfer, no external facilitator
50
+ - `get_mpp_market` — $0.01 USDC — same as `get_premium_market`, MPP-settled
51
+
52
+ ## Environment variables
53
+
54
+ | Variable | Required | Purpose |
55
+ |---|---|---|
56
+ | `AGENT_API_URL` | No (defaults to `http://127.0.0.1:3001`) | Nirium agent API base URL |
57
+ | `STELLAR_SECRET_KEY` | For paid tools | Funds x402 and MPP payments |
58
+ | `NIRIUM_API_KEY` | For `start_loop`/`stop_loop` | Agent API key from [nirium.xyz/keys](https://nirium.xyz/keys) |
59
+ | `STELLAR_NETWORK` | No (defaults to `testnet`) | `testnet` or `mainnet` |
60
+ | `SOROBAN_RPC_URL` | No | Override the default Soroban RPC endpoint |
61
+
62
+ ## Run from source
63
+
64
+ ```bash
65
+ git clone https://github.com/nirium-protocol/nirium-sdk
66
+ cd nirium-sdk/packages/mcp
67
+ npm install
68
+ STELLAR_SECRET_KEY=S... AGENT_API_URL=http://localhost:3001 npx tsx src/index.ts
69
+ ```
70
+
71
+ ## License
72
+
73
+ Apache-2.0 — see [LICENSE](./LICENSE).
package/dist/index.js ADDED
@@ -0,0 +1,292 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ // Copyright 2026 Nirium Protocol Contributors
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // ═══════════════════════════════════════════════════════════════
7
+ // Nirium MCP Server v0.4.0 — x402 + MPP tool suite
8
+ // ═══════════════════════════════════════════════════════════════
9
+ //
10
+ // Exposes Nirium Protocol capabilities to any MCP-compatible AI:
11
+ // Claude, GPT, Codex, Cursor, VS Code Copilot, etc.
12
+ //
13
+ // Three tiers of tools:
14
+ // FREE — market data, loop status (standard HTTP to agent API)
15
+ // PAID (x402) — premium signals via the OpenZeppelin Channels facilitator
16
+ // PAID (MPP) — same signals via direct Soroban SAC transfer,
17
+ // no external facilitator required
18
+ //
19
+ // Usage (stdio transport, from source):
20
+ // STELLAR_SECRET_KEY=S... AGENT_API_URL=http://localhost:3001 npx tsx src/index.ts
21
+ //
22
+ // Claude Desktop config (published package):
23
+ // {
24
+ // "mcpServers": {
25
+ // "nirium": {
26
+ // "command": "npx",
27
+ // "args": ["-y", "nirium-mcp"],
28
+ // "env": {
29
+ // "STELLAR_SECRET_KEY": "S...",
30
+ // "AGENT_API_URL": "https://nirium-agent.fly.dev"
31
+ // }
32
+ // }
33
+ // }
34
+ // }
35
+ //
36
+ // ═══════════════════════════════════════════════════════════════
37
+ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
38
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
39
+ const zod_1 = require("zod");
40
+ const fetch_1 = require("@x402/fetch");
41
+ const stellar_1 = require("@x402/stellar");
42
+ const stellar_2 = require("@x402/stellar");
43
+ const client_1 = require("mppx/client");
44
+ const client_2 = require("@stellar/mpp/charge/client");
45
+ // ─── Configuration ────────────────────────────────────────────
46
+ const API_URL = process.env.AGENT_API_URL || 'http://127.0.0.1:3001';
47
+ const STELLAR_KEY = process.env.STELLAR_SECRET_KEY || '';
48
+ const NIRIUM_API_KEY = process.env.NIRIUM_API_KEY || '';
49
+ const STELLAR_NET = (process.env.STELLAR_NETWORK === 'mainnet'
50
+ ? 'stellar:pubnet'
51
+ : stellar_2.STELLAR_TESTNET_CAIP2);
52
+ const RPC_URL = process.env.SOROBAN_RPC_URL || stellar_2.DEFAULT_TESTNET_RPC_URL;
53
+ // Derive public key from secret key if available, or use explicit env var
54
+ const STELLAR_PUBLIC_KEY = (() => {
55
+ if (process.env.STELLAR_PUBLIC_KEY)
56
+ return process.env.STELLAR_PUBLIC_KEY;
57
+ if (STELLAR_KEY) {
58
+ try {
59
+ return (0, stellar_2.createEd25519Signer)(STELLAR_KEY, stellar_2.STELLAR_TESTNET_CAIP2).address;
60
+ }
61
+ catch {
62
+ return '';
63
+ }
64
+ }
65
+ return '';
66
+ })();
67
+ // Auth headers for authenticated endpoints
68
+ const authHeaders = () => NIRIUM_API_KEY ? { 'x-api-key': NIRIUM_API_KEY } : {};
69
+ // Auth + legal consent headers (required by loop/start and execute endpoints)
70
+ const consentHeaders = () => ({
71
+ ...authHeaders(),
72
+ ...(STELLAR_PUBLIC_KEY ? { 'x-stellar-account': STELLAR_PUBLIC_KEY } : {}),
73
+ });
74
+ // ─── x402 Payment Client ──────────────────────────────────────
75
+ //
76
+ // Set up once; reused for all x402 premium tool calls.
77
+ // Requires STELLAR_SECRET_KEY env var with funded testnet wallet.
78
+ //
79
+ let paidFetch = fetch;
80
+ if (STELLAR_KEY) {
81
+ const signer = (0, stellar_2.createEd25519Signer)(STELLAR_KEY, STELLAR_NET);
82
+ const client = new fetch_1.x402Client()
83
+ .register(STELLAR_NET, new stellar_1.ExactStellarScheme(signer, { url: RPC_URL }));
84
+ paidFetch = (0, fetch_1.wrapFetchWithPayment)(fetch, client);
85
+ console.error(`[Nirium MCP] x402 wallet: ${signer.address} | network: ${STELLAR_NET}`);
86
+ }
87
+ else {
88
+ console.error('[Nirium MCP] No STELLAR_SECRET_KEY — premium (paid) tools will return 402 errors');
89
+ }
90
+ // ─── MPP Payment Client ───────────────────────────────────────
91
+ //
92
+ // MPP Charge mode: per-request Soroban SAC transfer.
93
+ // No external facilitator — server verifies directly.
94
+ // Same STELLAR_SECRET_KEY funds both x402 and MPP payments.
95
+ //
96
+ let mppFetch = fetch;
97
+ if (STELLAR_KEY) {
98
+ const mppx = client_1.Mppx.create({
99
+ methods: [
100
+ client_2.stellar.charge({
101
+ secretKey: STELLAR_KEY,
102
+ rpcUrl: RPC_URL,
103
+ }),
104
+ ],
105
+ });
106
+ mppFetch = mppx.fetch;
107
+ console.error(`[Nirium MCP] MPP Charge enabled | network: ${STELLAR_NET}`);
108
+ }
109
+ else {
110
+ console.error('[Nirium MCP] No STELLAR_SECRET_KEY — MPP tools will return 402 errors');
111
+ }
112
+ // ─── Server ───────────────────────────────────────────────────
113
+ const server = new mcp_js_1.McpServer({ name: 'nirium-mcp-server', version: '0.4.0' }, { capabilities: { tools: {} } });
114
+ // ─── FREE TOOLS ───────────────────────────────────────────────
115
+ server.tool('get_market_state', 'Fetch real-time market data: XLM/USDC price (CoinGecko), SDEX spread, base fee, Blend APY. Free — no API key required.', {}, async () => {
116
+ const res = await fetch(`${API_URL}/api/tickers`);
117
+ const data = await res.json();
118
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
119
+ });
120
+ server.tool('get_loop_status', 'Check the autonomous scanning loop: running/stopped, scan count, uptime, last AI decision. Free.', {}, async () => {
121
+ const res = await fetch(`${API_URL}/api/loop/status`);
122
+ const data = await res.json();
123
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
124
+ });
125
+ server.tool('start_loop', 'Start the autonomous market scanning loop. Requires NIRIUM_API_KEY env var.', {
126
+ minProfitPercentage: zod_1.z.number().optional().describe('Minimum profit % to trigger (default: 0.3)'),
127
+ maxBaseFee: zod_1.z.number().optional().describe('Max Stellar base fee in stroops (default: 500)'),
128
+ }, async (args) => {
129
+ const res = await fetch(`${API_URL}/api/loop/start`, {
130
+ method: 'POST',
131
+ headers: { 'Content-Type': 'application/json', ...consentHeaders() },
132
+ body: JSON.stringify({ config: args }),
133
+ });
134
+ const data = await res.json();
135
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
136
+ });
137
+ server.tool('stop_loop', 'Stop the autonomous scanning loop. Requires NIRIUM_API_KEY env var.', {}, async () => {
138
+ const res = await fetch(`${API_URL}/api/loop/stop`, {
139
+ method: 'POST',
140
+ headers: authHeaders(),
141
+ });
142
+ const data = await res.json();
143
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
144
+ });
145
+ server.tool('execute_demo', 'Dry-run a strategy via Soroban simulation — no real transaction. Free.', {
146
+ strategy: zod_1.z.string().describe('Strategy name: flash-loan-arb, path-arbitrage, cross-dex, blend-yield, soroswap-swap'),
147
+ asset: zod_1.z.string().describe('Trading pair, e.g. XLM-USDC'),
148
+ }, async (args) => {
149
+ const res = await fetch(`${API_URL}/api/execute-demo`, {
150
+ method: 'POST',
151
+ headers: { 'Content-Type': 'application/json' },
152
+ body: JSON.stringify(args),
153
+ });
154
+ const data = await res.json();
155
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
156
+ });
157
+ // ─── PAID TOOLS (x402) ────────────────────────────────────────
158
+ //
159
+ // Each call automatically:
160
+ // 1. Hits the endpoint → receives HTTP 402 + payment requirements
161
+ // 2. Signs a Soroban auth entry for the USDC amount
162
+ // 3. Submits X-PAYMENT header → receives 200 + data
163
+ //
164
+ // Cost: $0.02 USDC per signals call, $0.05 per market call, $0.25 per execution.
165
+ // Requires STELLAR_SECRET_KEY env var with funded testnet wallet.
166
+ //
167
+ server.tool('get_premium_signals', 'PAID ($0.02 USDC via x402) — Premium arbitrage signals with execution paths, confidence scores, profit estimates, and valid-until ledger windows. Requires funded Stellar wallet.', {
168
+ count: zod_1.z.number().optional().describe('Number of signals to fetch (default: 20, max: 100)'),
169
+ }, async (args) => {
170
+ const count = args.count || 20;
171
+ try {
172
+ const res = await paidFetch(`${API_URL}/api/v1/premium/signals?count=${count}`);
173
+ if (!res.ok) {
174
+ return { content: [{ type: 'text', text: `Error ${res.status}: ${await res.text()}` }], isError: true };
175
+ }
176
+ const data = await res.json();
177
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
178
+ }
179
+ catch (err) {
180
+ return { content: [{ type: 'text', text: `x402 payment failed: ${err.message}` }], isError: true };
181
+ }
182
+ });
183
+ server.tool('get_premium_market', 'PAID ($0.05 USDC via x402) — Enriched market state: arbitrage windows, yield ranking, fee pressure alerts, and execution recommendation. Requires funded Stellar wallet.', {}, async () => {
184
+ try {
185
+ const res = await paidFetch(`${API_URL}/api/v1/premium/market`);
186
+ if (!res.ok) {
187
+ return { content: [{ type: 'text', text: `Error ${res.status}: ${await res.text()}` }], isError: true };
188
+ }
189
+ const data = await res.json();
190
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
191
+ }
192
+ catch (err) {
193
+ return { content: [{ type: 'text', text: `x402 payment failed: ${err.message}` }], isError: true };
194
+ }
195
+ });
196
+ server.tool('execute_paid_strategy', 'PAID ($0.25 USDC via x402) — Execute a DeFi strategy on Stellar via Soroban. No Nirium account required — pay per execution. Requires funded Stellar wallet.', {
197
+ strategy: zod_1.z.string().describe('Strategy: flash-loan-arb | path-arbitrage | cross-dex | blend-yield | soroswap-swap'),
198
+ asset: zod_1.z.string().describe('Trading pair, e.g. XLM-USDC'),
199
+ params: zod_1.z.record(zod_1.z.unknown()).optional().describe('Strategy-specific parameters'),
200
+ }, async (args) => {
201
+ try {
202
+ const res = await paidFetch(`${API_URL}/api/v1/premium/execute`, {
203
+ method: 'POST',
204
+ headers: { 'Content-Type': 'application/json' },
205
+ body: JSON.stringify(args),
206
+ });
207
+ if (!res.ok) {
208
+ return { content: [{ type: 'text', text: `Error ${res.status}: ${await res.text()}` }], isError: true };
209
+ }
210
+ const data = await res.json();
211
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
212
+ }
213
+ catch (err) {
214
+ return { content: [{ type: 'text', text: `x402 payment failed: ${err.message}` }], isError: true };
215
+ }
216
+ });
217
+ server.tool('get_wallet_info', 'Show the x402 + MPP wallet address and payment configuration for this MCP session. Free.', {}, async () => {
218
+ if (!STELLAR_KEY) {
219
+ return { content: [{ type: 'text', text: 'No STELLAR_SECRET_KEY configured. Set it to enable paid tools.' }] };
220
+ }
221
+ const signer = (0, stellar_2.createEd25519Signer)(STELLAR_KEY, STELLAR_NET);
222
+ return {
223
+ content: [{
224
+ type: 'text',
225
+ text: JSON.stringify({
226
+ address: signer.address,
227
+ network: STELLAR_NET,
228
+ rpcUrl: RPC_URL,
229
+ agentApiUrl: API_URL,
230
+ niriumApiKeySet: !!NIRIUM_API_KEY,
231
+ x402Enabled: true,
232
+ mppEnabled: true,
233
+ freeTools: ['get_market_state', 'get_loop_status', 'execute_demo'],
234
+ authenticatedTools: ['start_loop', 'stop_loop'],
235
+ paidToolsX402: ['get_premium_signals', 'get_premium_market', 'execute_paid_strategy'],
236
+ paidToolsMpp: ['get_mpp_signals', 'get_mpp_market'],
237
+ }, null, 2),
238
+ }],
239
+ };
240
+ });
241
+ // ─── PAID TOOLS (MPP) ─────────────────────────────────────────
242
+ //
243
+ // MPP Charge mode: no external facilitator.
244
+ // The client signs a Soroban SAC transfer and sends it inline.
245
+ // Server verifies the on-chain transfer and returns 200.
246
+ //
247
+ // Advantage over x402: no Coinbase facilitator dependency.
248
+ // Both x402 and MPP tools are available — client chooses.
249
+ //
250
+ server.tool('get_mpp_signals', 'PAID ($0.01 USDC via MPP Charge) — Premium arbitrage signals settled via direct Soroban SAC transfer. No external facilitator. Same signal data as get_premium_signals. Requires funded Stellar wallet.', {
251
+ count: zod_1.z.number().optional().describe('Number of signals to fetch (default: 20, max: 100)'),
252
+ }, async (args) => {
253
+ const count = args.count || 20;
254
+ try {
255
+ const res = await mppFetch(`${API_URL}/api/v1/mpp/signals?count=${count}`);
256
+ if (!res.ok) {
257
+ return { content: [{ type: 'text', text: `Error ${res.status}: ${await res.text()}` }], isError: true };
258
+ }
259
+ const data = await res.json();
260
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
261
+ }
262
+ catch (err) {
263
+ return { content: [{ type: 'text', text: `MPP payment failed: ${err.message}` }], isError: true };
264
+ }
265
+ });
266
+ server.tool('get_mpp_market', 'PAID ($0.01 USDC via MPP Charge) — Enriched market state settled via direct Soroban SAC transfer. No external facilitator. Includes arbitrage windows, yield ranking, and fee alerts. Requires funded Stellar wallet.', {}, async () => {
267
+ try {
268
+ const res = await mppFetch(`${API_URL}/api/v1/mpp/market`);
269
+ if (!res.ok) {
270
+ return { content: [{ type: 'text', text: `Error ${res.status}: ${await res.text()}` }], isError: true };
271
+ }
272
+ const data = await res.json();
273
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
274
+ }
275
+ catch (err) {
276
+ return { content: [{ type: 'text', text: `MPP payment failed: ${err.message}` }], isError: true };
277
+ }
278
+ });
279
+ // ─── Start ────────────────────────────────────────────────────
280
+ async function main() {
281
+ const transport = new stdio_js_1.StdioServerTransport();
282
+ await server.connect(transport);
283
+ console.error('[Nirium MCP] v0.4.0 running on stdio');
284
+ console.error(`[Nirium MCP] Agent API: ${API_URL}`);
285
+ console.error(`[Nirium MCP] NIRIUM_API_KEY set: ${!!NIRIUM_API_KEY}`);
286
+ console.error(`[Nirium MCP] x402 enabled: ${!!STELLAR_KEY}`);
287
+ console.error(`[Nirium MCP] MPP Charge enabled: ${!!STELLAR_KEY}`);
288
+ }
289
+ main().catch((err) => {
290
+ console.error('[Nirium MCP] Fatal error:', err);
291
+ process.exit(1);
292
+ });
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "nirium-mcp",
3
+ "version": "0.4.0",
4
+ "description": "Model Context Protocol server for Nirium — exposes market data, autonomous loop control, and x402/MPP paid signals to any MCP-compatible AI (Claude, GPT, Cursor, VS Code Copilot).",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "nirium-mcp": "dist/index.js"
8
+ },
9
+ "homepage": "https://nirium.xyz",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/nirium-protocol/nirium-sdk"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/nirium-protocol/nirium-sdk/issues",
16
+ "email": "niriumprotocol@gmail.com"
17
+ },
18
+ "author": {
19
+ "name": "Nirium Protocol",
20
+ "email": "niriumprotocol@gmail.com",
21
+ "url": "https://nirium.xyz"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md"
26
+ ],
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "start": "node dist/index.js",
30
+ "dev": "tsc --watch"
31
+ },
32
+ "dependencies": {
33
+ "@modelcontextprotocol/sdk": "^1.27.1",
34
+ "@stellar/mpp": "^0.4.0",
35
+ "@stellar/stellar-sdk": "^14.0.0",
36
+ "@x402/core": "^2.9.0",
37
+ "@x402/fetch": "^2.9.0",
38
+ "@x402/stellar": "^2.9.0",
39
+ "mppx": "^0.5.5",
40
+ "zod": "^3.25.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^22.0.0",
44
+ "tsx": "^4.19.0",
45
+ "typescript": "^5.7.0"
46
+ },
47
+ "keywords": [
48
+ "nirium",
49
+ "mcp",
50
+ "model-context-protocol",
51
+ "stellar",
52
+ "soroban",
53
+ "agent",
54
+ "autonomous",
55
+ "treasury",
56
+ "x402",
57
+ "mpp",
58
+ "agentic-payments",
59
+ "claude",
60
+ "llm-tools"
61
+ ],
62
+ "license": "Apache-2.0"
63
+ }