aegis-x402-mcp 1.0.3 → 1.0.4
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 +4 -2
- package/dist/index.d.ts +8 -0
- package/dist/index.js +64 -6
- package/dist/test.js +28 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -106,8 +106,10 @@ Add to `~/.codeium/windsurf/mcp_config.json`:
|
|
|
106
106
|
| Variable | Description |
|
|
107
107
|
|---|---|
|
|
108
108
|
| `AEGIS_GATEWAY_URL` | Gateway URL (defaults to `https://aegis-audit-x402.project-easy-x.workers.dev`). |
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
109
|
+
| `AEGIS_CREDIT_TOKEN` | Tier-bound 24h prepaid credit token generated from `/pay` or prior `X-Aegis-Credit-Token` settlement headers. |
|
|
110
|
+
| `AEGIS_PRIVATE_KEY` | Optional local EVM private key (`0x...`) used in-process to sign EIP-3009 USDC authorizations on Base without keys ever leaving your machine. |
|
|
111
|
+
| `AEGIS_API_KEY` | Alias for `AEGIS_CREDIT_TOKEN` / prepaid enterprise API key. |
|
|
112
|
+
| `X402_PAYMENT_HEADER` | Pre-signed base64 EIP-3009 payment header or authorization token. |
|
|
111
113
|
|
|
112
114
|
---
|
|
113
115
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
export declare const ALLOWED_PAYTO: string;
|
|
3
3
|
export declare const BASE_USDC: string;
|
|
4
|
+
export declare function parseChainIdFromNetwork(network?: string): number;
|
|
4
5
|
/**
|
|
5
6
|
* Signs EIP-3009 TransferWithAuthorization locally inside the user's MCP process.
|
|
6
7
|
* Keys never leave the local machine.
|
|
7
8
|
* Protected by strict recipient allowlist guard: only signs toward official Aegis address.
|
|
8
9
|
*/
|
|
9
10
|
export declare function signEip3009Payment(privateKeyHex: string, accepts: any, resource?: any): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* 3-Tier Execution Pipeline:
|
|
13
|
+
* Tier 1: Zero-config free tools execute immediately.
|
|
14
|
+
* Tier 2: Prepaid credit token (AEGIS_CREDIT_TOKEN / AEGIS_API_KEY) in env.
|
|
15
|
+
* Tier 3: Local wallet signing (AEGIS_PRIVATE_KEY) in env -> signs 402 challenge and retries seamlessly.
|
|
16
|
+
*/
|
|
17
|
+
export declare function fetchFromAegis(endpoint: string, options?: RequestInit): Promise<any>;
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,10 @@ const PRIVATE_KEY = process.env.AEGIS_PRIVATE_KEY || '';
|
|
|
11
11
|
const PAYMENT_HEADER = process.env.X402_PAYMENT_HEADER || '';
|
|
12
12
|
export const ALLOWED_PAYTO = '0x111ef680B6EFdd859FbEc473b907aCe95F0D1acB'.toLowerCase();
|
|
13
13
|
export const BASE_USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'.toLowerCase();
|
|
14
|
+
export function parseChainIdFromNetwork(network) {
|
|
15
|
+
const match = String(network || '').match(/^eip155:(\d+)$/);
|
|
16
|
+
return match ? Number(match[1]) : 8453;
|
|
17
|
+
}
|
|
14
18
|
/**
|
|
15
19
|
* Signs EIP-3009 TransferWithAuthorization locally inside the user's MCP process.
|
|
16
20
|
* Keys never leave the local machine.
|
|
@@ -33,10 +37,11 @@ export async function signEip3009Payment(privateKeyHex, accepts, resource) {
|
|
|
33
37
|
const fromChecksum = getAddress(account.address);
|
|
34
38
|
const toChecksum = getAddress(accepts.payTo || accepts.recipient);
|
|
35
39
|
const assetChecksum = getAddress(accepts.asset || BASE_USDC);
|
|
40
|
+
const chainId = parseChainIdFromNetwork(accepts.network);
|
|
36
41
|
const domain = {
|
|
37
42
|
name: accepts.extra?.name || 'USD Coin',
|
|
38
43
|
version: accepts.extra?.version || '2',
|
|
39
|
-
chainId
|
|
44
|
+
chainId,
|
|
40
45
|
verifyingContract: assetChecksum,
|
|
41
46
|
};
|
|
42
47
|
const types = {
|
|
@@ -89,7 +94,7 @@ export async function signEip3009Payment(privateKeyHex, accepts, resource) {
|
|
|
89
94
|
* Tier 2: Prepaid credit token (AEGIS_CREDIT_TOKEN / AEGIS_API_KEY) in env.
|
|
90
95
|
* Tier 3: Local wallet signing (AEGIS_PRIVATE_KEY) in env -> signs 402 challenge and retries seamlessly.
|
|
91
96
|
*/
|
|
92
|
-
async function fetchFromAegis(endpoint, options = {}) {
|
|
97
|
+
export async function fetchFromAegis(endpoint, options = {}) {
|
|
93
98
|
const url = `${GATEWAY_URL}${endpoint}`;
|
|
94
99
|
const headers = {
|
|
95
100
|
'Accept': 'application/json',
|
|
@@ -120,9 +125,22 @@ async function fetchFromAegis(endpoint, options = {}) {
|
|
|
120
125
|
if (retryRes.ok) {
|
|
121
126
|
return retryRes.json();
|
|
122
127
|
}
|
|
128
|
+
const retryBody = await retryRes.json().catch(async () => ({ raw: await retryRes.text().catch(() => '') }));
|
|
129
|
+
return {
|
|
130
|
+
status: 'UPSTREAM_ERROR',
|
|
131
|
+
statusCode: retryRes.status,
|
|
132
|
+
charged: false,
|
|
133
|
+
message: retryBody?.message || retryBody?.error || retryRes.statusText || 'Payment retry failed',
|
|
134
|
+
details: retryBody,
|
|
135
|
+
};
|
|
123
136
|
}
|
|
124
137
|
catch (signErr) {
|
|
125
|
-
|
|
138
|
+
return {
|
|
139
|
+
status: 'UPSTREAM_ERROR',
|
|
140
|
+
statusCode: 500,
|
|
141
|
+
charged: false,
|
|
142
|
+
message: `Local EIP-3009 signing failed: ${signErr?.message || String(signErr)}`,
|
|
143
|
+
};
|
|
126
144
|
}
|
|
127
145
|
}
|
|
128
146
|
// Friendly, structured notification for the LLM without crashing
|
|
@@ -132,8 +150,8 @@ async function fetchFromAegis(endpoint, options = {}) {
|
|
|
132
150
|
statusCode: 402,
|
|
133
151
|
price,
|
|
134
152
|
payTo: accepts?.recipient || accepts?.payTo || ALLOWED_PAYTO,
|
|
135
|
-
network: 'eip155:8453
|
|
136
|
-
message: `[AEGIS x402 PAYMENT REQUIRED] This tool costs ${price} on Base
|
|
153
|
+
network: `${accepts?.network || 'eip155:8453'}`,
|
|
154
|
+
message: `[AEGIS x402 PAYMENT REQUIRED] This tool costs ${price} on Base.`,
|
|
137
155
|
setupInstructions: {
|
|
138
156
|
optionA_prepaidCredits: 'Top up in 1-click at https://aegis-audit-x402.project-easy-x.workers.dev/pay and add AEGIS_CREDIT_TOKEN in your MCP settings (zero signing required).',
|
|
139
157
|
optionB_agenticWallet: 'Add AEGIS_PRIVATE_KEY in your MCP config; the local process will sign EIP-3009 gasless settlements on-demand without keys ever leaving your machine.',
|
|
@@ -141,11 +159,21 @@ async function fetchFromAegis(endpoint, options = {}) {
|
|
|
141
159
|
paymentDetails: paymentReq,
|
|
142
160
|
};
|
|
143
161
|
}
|
|
162
|
+
if (!res.ok) {
|
|
163
|
+
const errBody = await res.json().catch(async () => ({ raw: await res.text().catch(() => '') }));
|
|
164
|
+
return {
|
|
165
|
+
status: 'UPSTREAM_ERROR',
|
|
166
|
+
statusCode: res.status,
|
|
167
|
+
charged: false,
|
|
168
|
+
message: errBody?.message || errBody?.error || res.statusText || 'Aegis gateway request failed',
|
|
169
|
+
details: errBody,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
144
172
|
return res.json();
|
|
145
173
|
}
|
|
146
174
|
const server = new Server({
|
|
147
175
|
name: 'aegis-x402-mcp',
|
|
148
|
-
version: '1.0.
|
|
176
|
+
version: '1.0.4',
|
|
149
177
|
}, {
|
|
150
178
|
capabilities: {
|
|
151
179
|
tools: {},
|
|
@@ -270,6 +298,24 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
270
298
|
required: ['url'],
|
|
271
299
|
},
|
|
272
300
|
},
|
|
301
|
+
{
|
|
302
|
+
name: 'aegis_grounded_chat',
|
|
303
|
+
description: 'USE WHEN: Running OpenAI-compatible LLM reasoning grounded in live Base/Ethereum/Solana on-chain security telemetry ($0.005 USDC on Base).',
|
|
304
|
+
inputSchema: {
|
|
305
|
+
type: 'object',
|
|
306
|
+
properties: {
|
|
307
|
+
prompt: {
|
|
308
|
+
type: 'string',
|
|
309
|
+
description: 'Security or DeFi analysis question to run with live on-chain token context',
|
|
310
|
+
},
|
|
311
|
+
model: {
|
|
312
|
+
type: 'string',
|
|
313
|
+
description: 'Optional model identifier (defaults to aegis-llama-3.3-70b-grounded)',
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
required: ['prompt'],
|
|
317
|
+
},
|
|
318
|
+
},
|
|
273
319
|
{
|
|
274
320
|
name: 'aegis_recent_audits',
|
|
275
321
|
description: 'USE WHEN: Monitoring the real-time stream of recently scanned tokens on Base, Ethereum, and Solana (FREE).',
|
|
@@ -336,6 +382,18 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
336
382
|
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
337
383
|
};
|
|
338
384
|
}
|
|
385
|
+
if (name === 'aegis_grounded_chat') {
|
|
386
|
+
const prompt = String(args?.prompt || 'Analyze Base USDC safety.');
|
|
387
|
+
const model = String(args?.model || 'aegis-llama-3.3-70b-grounded');
|
|
388
|
+
const data = await fetchFromAegis('/v1/chat/completions', {
|
|
389
|
+
method: 'POST',
|
|
390
|
+
headers: { 'Content-Type': 'application/json' },
|
|
391
|
+
body: JSON.stringify({ model, messages: [{ role: 'user', content: prompt }] }),
|
|
392
|
+
});
|
|
393
|
+
return {
|
|
394
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
395
|
+
};
|
|
396
|
+
}
|
|
339
397
|
if (name === 'aegis_recent_audits') {
|
|
340
398
|
const data = await fetchFromAegis('/api/v1/recent');
|
|
341
399
|
return {
|
package/dist/test.js
CHANGED
|
@@ -130,17 +130,17 @@ test('MCP stdio handshake (SDK 1.32.2) initializes cleanly and exposes all 7 too
|
|
|
130
130
|
params: {
|
|
131
131
|
protocolVersion: '2025-06-18',
|
|
132
132
|
capabilities: {},
|
|
133
|
-
clientInfo: { name: 'aegis-ci-test', version: '1.0.
|
|
133
|
+
clientInfo: { name: 'aegis-ci-test', version: '1.0.4' },
|
|
134
134
|
},
|
|
135
135
|
}) + '\n');
|
|
136
136
|
});
|
|
137
137
|
const initRes = responses.find((r) => r.id === 1);
|
|
138
138
|
assert.ok(initRes?.result?.serverInfo, 'initialize must return serverInfo');
|
|
139
139
|
assert.equal(initRes.result.serverInfo.name, 'aegis-x402-mcp');
|
|
140
|
-
assert.equal(initRes.result.serverInfo.version, '1.0.
|
|
140
|
+
assert.equal(initRes.result.serverInfo.version, '1.0.4');
|
|
141
141
|
const listRes = responses.find((r) => r.id === 2);
|
|
142
142
|
const tools = listRes?.result?.tools || [];
|
|
143
|
-
assert.equal(tools.length,
|
|
143
|
+
assert.equal(tools.length, 8, 'Must expose all 8 Aegis MCP tools');
|
|
144
144
|
const names = tools.map((t) => t.name);
|
|
145
145
|
assert.ok(names.includes('aegis_preflight_bundle'));
|
|
146
146
|
assert.ok(names.includes('aegis_priority_audit'));
|
|
@@ -148,5 +148,30 @@ test('MCP stdio handshake (SDK 1.32.2) initializes cleanly and exposes all 7 too
|
|
|
148
148
|
assert.ok(names.includes('aegis_token_preview'));
|
|
149
149
|
assert.ok(names.includes('aegis_wallet_kya'));
|
|
150
150
|
assert.ok(names.includes('aegis_web_scrape'));
|
|
151
|
+
assert.ok(names.includes('aegis_grounded_chat'));
|
|
151
152
|
assert.ok(names.includes('aegis_recent_audits'));
|
|
152
153
|
});
|
|
154
|
+
test('parseChainIdFromNetwork resolves mainnet, sepolia, and safe fallback', async () => {
|
|
155
|
+
const { parseChainIdFromNetwork } = await import('./index.js');
|
|
156
|
+
assert.equal(parseChainIdFromNetwork('eip155:8453'), 8453);
|
|
157
|
+
assert.equal(parseChainIdFromNetwork('eip155:84532'), 84532);
|
|
158
|
+
assert.equal(parseChainIdFromNetwork('solana:mainnet'), 8453);
|
|
159
|
+
assert.equal(parseChainIdFromNetwork(undefined), 8453);
|
|
160
|
+
});
|
|
161
|
+
test('fetchFromAegis returns structured UPSTREAM_ERROR on non-OK HTTP responses instead of throwing on res.json', async () => {
|
|
162
|
+
const { fetchFromAegis } = await import('./index.js');
|
|
163
|
+
const origFetch = globalThis.fetch;
|
|
164
|
+
globalThis.fetch = (async () => new Response(JSON.stringify({ error: 'UPSTREAM_502_ABORTED_BEFORE_CHARGE' }), {
|
|
165
|
+
status: 502,
|
|
166
|
+
headers: { 'Content-Type': 'application/json' },
|
|
167
|
+
}));
|
|
168
|
+
try {
|
|
169
|
+
const out = await fetchFromAegis('/api/v1/token/audit');
|
|
170
|
+
assert.equal(out.status, 'UPSTREAM_ERROR');
|
|
171
|
+
assert.equal(out.statusCode, 502);
|
|
172
|
+
assert.equal(out.charged, false);
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
globalThis.fetch = origFetch;
|
|
176
|
+
}
|
|
177
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegis-x402-mcp",
|
|
3
3
|
"mcpName": "io.github.Goatincrypto/aegis-x402-mcp",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"description": "MCP server for AegisAudit x402 token security, honeypot simulation, KYA, and PreFlight clearance",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|