aegis-x402 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +69 -2
- package/dist/scripts/scan-mcp-leaderboard.d.ts +1 -0
- package/dist/scripts/scan-mcp-leaderboard.js +286 -0
- package/dist/scripts/simulate-a2a-economy.d.ts +1 -0
- package/dist/scripts/simulate-a2a-economy.js +47 -0
- package/dist/src/a2a/tasks.d.ts +35 -0
- package/dist/src/a2a/tasks.js +90 -0
- package/dist/src/app.d.ts +18 -0
- package/dist/src/app.js +1094 -0
- package/dist/src/cli/aegis-mcp-bridge.d.ts +2 -0
- package/dist/src/cli/aegis-mcp-bridge.js +45 -0
- package/dist/src/commerce/engine.d.ts +77 -0
- package/dist/src/commerce/engine.js +314 -0
- package/dist/src/commerce/seed.d.ts +2 -0
- package/dist/src/commerce/seed.js +67 -0
- package/dist/src/config.d.ts +36 -0
- package/dist/src/config.js +88 -0
- package/dist/src/crypto/jcs-jws.d.ts +25 -0
- package/dist/src/crypto/jcs-jws.js +160 -0
- package/dist/src/db/runtime.d.ts +25 -0
- package/dist/src/db/runtime.js +308 -0
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.js +12 -0
- package/dist/src/ledger/double-entry.d.ts +31 -0
- package/dist/src/ledger/double-entry.js +79 -0
- package/dist/src/payments/x402.d.ts +104 -0
- package/dist/src/payments/x402.js +291 -0
- package/dist/src/policy/cache.d.ts +10 -0
- package/dist/src/policy/cache.js +33 -0
- package/dist/src/policy/deobfuscate.d.ts +8 -0
- package/dist/src/policy/deobfuscate.js +180 -0
- package/dist/src/policy/detectors.d.ts +19 -0
- package/dist/src/policy/detectors.js +125 -0
- package/dist/src/policy/engine.d.ts +40 -0
- package/dist/src/policy/engine.js +362 -0
- package/dist/src/sdk/aegis-x402-client.d.ts +85 -0
- package/dist/src/sdk/aegis-x402-client.js +238 -0
- package/dist/src/security/guards.d.ts +7 -0
- package/dist/src/security/guards.js +84 -0
- package/dist/src/server.d.ts +1 -0
- package/dist/src/server.js +29 -0
- package/dist/src/skills/engine.d.ts +175 -0
- package/dist/src/skills/engine.js +355 -0
- package/mcp-registry.json +33 -0
- package/package.json +68 -4
- package/smithery.yaml +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MWS Middleware Solutions
|
|
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
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Aegis-x402
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Zero-signup, wallet-native HTTP 402 Security Firewall & Escrow Clearinghouse for A2A & MCP Agents.**
|
|
4
|
+
|
|
5
|
+
No API keys, no forms, no B2B sales calls. Any autonomous agent arrives with an EVM wallet, receives a machine-readable `HTTP 402` USDC challenge on Base (`a2a-x402` v2 / EIP-3009), signs `TransferWithAuthorization`, and receives verified security sanitization or escrowed commerce execution in one round-trip.
|
|
6
|
+
|
|
7
|
+
## Core Capabilities
|
|
8
|
+
|
|
9
|
+
1. **Zero-Signup Paid Security Skills (`POST /v1/x402/*`, A2A `/v1/message:send`, MCP `/mcp`)**
|
|
10
|
+
- `sanitize_payload` ($0.002 USDC): Multi-layer de-obfuscation (Base64/Hex/URL/Unicode NFKC/homoglyphs/leetspeak), Luhn PAN & Mod-97 IBAN DLP, secret entropy detection, multilingual prompt injection, shell/SQLi/SSRF detection, and MCP tool poisoning defense.
|
|
11
|
+
- `verify_agent_card` ($0.002 USDC): ES256/Ed25519 JWS + RFC 8785 JCS signature verification + `_agentpin` DNS check + skill description safety inspection.
|
|
12
|
+
- `scan_code_sarif` ($0.25 USDC): Static security scanner for MCP servers, TS/JS/Python agents, iOS AppIntents, and Android AppFunctions emitting OASIS SARIF 2.1.0.
|
|
13
|
+
- `attest_receipt` ($0.003 USDC): Signed Ed25519 cryptographic attestation over any payload digest.
|
|
14
|
+
2. **Wallet-Native A2A/MCP Buy & Rent Escrow Clearinghouse (`/v1/commerce/*`)**
|
|
15
|
+
- Any seller agent publishes `BUY`, `RENT`, or `PAY_PER_CALL` offers using an EVM wallet (`POST /v1/commerce/listings`).
|
|
16
|
+
- Buyer agents fund orders directly via `HTTP 402` (`POST /v1/commerce/orders`) into escrow.
|
|
17
|
+
- `RENT` orders automatically mint a metered `aegis_lease_...` bearer token verified in 1 call (`POST /v1/commerce/leases/verify`).
|
|
18
|
+
- Fulfillment releases **97% to the seller** and **3% platform fee** into the SHA-256 hash-chained double-entry ledger; disputes refund **100% to the buyer**.
|
|
19
|
+
3. **Machine Discovery**
|
|
20
|
+
- `GET /.well-known/agent-card.json` (ES256 JWS signed A2A v1.0.1 card)
|
|
21
|
+
- `GET /.well-known/jwks.json`
|
|
22
|
+
- `GET /llms.txt` & `GET /llms-full.txt`
|
|
23
|
+
- `GET /openapi.json`
|
|
24
|
+
- `POST /mcp` (Streamable HTTP MCP JSON-RPC 2.0)
|
|
25
|
+
|
|
26
|
+
## Quickstart (Zero Docker Required)
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install
|
|
30
|
+
npm run build
|
|
31
|
+
npm test
|
|
32
|
+
npm run dev
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
In a second terminal, run the live Agent-to-Agent economy simulation:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm run simulate:economy
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## SDK Usage (`AegisX402Client`)
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { AegisX402Client } from "aegis-x402";
|
|
45
|
+
|
|
46
|
+
const agent = new AegisX402Client({
|
|
47
|
+
baseUrl: "https://your-aegis-x402-host.example",
|
|
48
|
+
privateKey: process.env.AGENT_EVM_PRIVATE_KEY as `0x${string}`,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Automatically negotiates HTTP 402 -> signs EIP-3009 USDC -> returns result
|
|
52
|
+
const verdict = await agent.sanitize({ prompt: "Check user transfer" }, { mode: "REDACT" });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Production Deployment
|
|
56
|
+
|
|
57
|
+
1. Set your real Base Mainnet (`8453`) treasury address in `AEGIS_BASE_TREASURY_EVM` and `AEGIS_GATEWAY_TREASURY_EVM`.
|
|
58
|
+
2. Switch `X402_SETTLEMENT_MODE=facilitator` (using `https://x402.org/facilitator`) or `direct_rpc` with `BASE_RELAYER_PRIVATE_KEY`.
|
|
59
|
+
3. Provision Postgres 16 + Redis (run `sql/001_aegis_x402.sql` on Postgres) and deploy with `Dockerfile`, `railway.json`, `render.yaml`, or Google Cloud Run:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
docker compose up --build -d
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Machine Distribution Checklist
|
|
66
|
+
|
|
67
|
+
Once deployed on your HTTPS domain (`https://api.yourdomain.com`):
|
|
68
|
+
- Submit `https://api.yourdomain.com/.well-known/agent-card.json` to A2A directories and Coinbase x402 Bazaar.
|
|
69
|
+
- Submit `https://api.yourdomain.com/mcp` to the official MCP Registry / Smithery.
|
|
70
|
+
- Ensure `https://api.yourdomain.com/llms.txt` and `/.well-known/jwks.json` are publicly crawlable without auth.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { inspectPayload, resolveInspectionPolicy } from "../src/policy/engine.js";
|
|
4
|
+
import { runScanCodeSarif } from "../src/skills/engine.js";
|
|
5
|
+
const CURATED_REPOS = [
|
|
6
|
+
{ name: "playwright-mcp", repo: "microsoft/playwright-mcp", category: "Browser", stars: 12000, paths: ["src/index.ts", "packages/playwright-mcp/src/index.ts", "index.js"] },
|
|
7
|
+
{ name: "context7-mcp", repo: "upstash/context7", category: "Documentation", stars: 11000, paths: ["packages/mcp/src/index.ts", "src/index.ts"] },
|
|
8
|
+
{ name: "firecrawl-mcp-server", repo: "mendableai/firecrawl-mcp-server", category: "Web Scraping", stars: 4200, paths: ["src/index.ts"] },
|
|
9
|
+
{ name: "browserbase-mcp", repo: "browserbase/mcp-server-browserbase", category: "Browser", stars: 2600, paths: ["src/index.ts", "browserbase/src/index.ts"] },
|
|
10
|
+
{ name: "cloudflare-mcp", repo: "cloudflare/mcp-server-cloudflare", category: "Cloud", stars: 2500, paths: ["src/index.ts", "apps/workers-bindings/src/index.ts"] },
|
|
11
|
+
{ name: "notion-mcp-server", repo: "makenotion/notion-mcp-server", category: "Productivity", stars: 2400, paths: ["src/index.ts", "scripts/start-server.ts"] },
|
|
12
|
+
{ name: "supabase-mcp", repo: "supabase-community/supabase-mcp", category: "Database", stars: 2100, paths: ["packages/mcp-server-supabase/src/index.ts", "src/index.ts"] },
|
|
13
|
+
{ name: "stripe-agent-toolkit", repo: "stripe/agent-toolkit", category: "Payments", stars: 1900, paths: ["typescript/src/modelcontextprotocol/index.ts", "modelcontextprotocol/src/index.ts"] },
|
|
14
|
+
{ name: "tavily-mcp", repo: "tavily-ai/tavily-mcp", category: "Search", stars: 1400, paths: ["src/index.ts"] },
|
|
15
|
+
{ name: "qdrant-mcp", repo: "qdrant/mcp-server-qdrant", category: "Vector DB", stars: 1300, paths: ["src/mcp_server_qdrant/server.py"] },
|
|
16
|
+
{ name: "chroma-mcp", repo: "chroma-core/chroma-mcp", category: "Vector DB", stars: 950, paths: ["src/chroma_mcp/server.py"] },
|
|
17
|
+
{ name: "grafana-mcp", repo: "grafana/mcp-grafana", category: "Observability", stars: 1500, paths: ["cmd/mcp-grafana/main.go", "internal/linter/linter.go"] },
|
|
18
|
+
{ name: "clickhouse-mcp", repo: "ClickHouse/mcp-clickhouse", category: "Database", stars: 1100, paths: ["mcp_clickhouse/mcp_server.py"] },
|
|
19
|
+
{ name: "neo4j-mcp", repo: "neo4j-contrib/mcp-neo4j", category: "Database", stars: 900, paths: ["servers/mcp-neo4j-cypher/src/mcp_neo4j_cypher/server.py"] },
|
|
20
|
+
{ name: "perplexity-ask-mcp", repo: "ppl-ai/modelcontextprotocol", category: "Search", stars: 1600, paths: ["perplexity-ask/index.ts"] },
|
|
21
|
+
{ name: "exa-mcp-server", repo: "exa-labs/exa-mcp-server", category: "Search", stars: 1500, paths: ["src/index.ts"] },
|
|
22
|
+
{ name: "e2b-mcp-server", repo: "e2b-dev/mcp-server", category: "Sandbox", stars: 850, paths: ["packages/js/src/index.ts", "packages/python/src/e2b_mcp_server/server.py"] },
|
|
23
|
+
{ name: "apify-actors-mcp", repo: "apify/actors-mcp-server", category: "Web Scraping", stars: 750, paths: ["src/index.ts"] },
|
|
24
|
+
{ name: "axiom-mcp", repo: "axiomhq/mcp-server-axiom", category: "Observability", stars: 400, paths: ["cmd/axiom-mcp/main.go"] },
|
|
25
|
+
{ name: "tinybird-mcp", repo: "tinybirdco/mcp-tinybird", category: "Analytics", stars: 350, paths: ["src/mcp_tinybird/server.py"] },
|
|
26
|
+
{ name: "motherduck-mcp", repo: "motherduckdb/mcp-server-motherduck", category: "Database", stars: 650, paths: ["src/mcp_server_motherduck/server.py"] },
|
|
27
|
+
{ name: "neon-mcp", repo: "neondatabase/mcp-server-neon", category: "Database", stars: 800, paths: ["src/index.ts"] },
|
|
28
|
+
{ name: "upstash-mcp", repo: "upstash/mcp-server", category: "Cloud", stars: 500, paths: ["src/index.ts"] },
|
|
29
|
+
{ name: "sentry-mcp", repo: "getsentry/sentry-mcp", category: "Observability", stars: 700, paths: ["packages/mcp-server/src/index.ts", "src/index.ts"] },
|
|
30
|
+
{ name: "linear-mcp", repo: "jerhadf/linear-mcp-server", category: "Productivity", stars: 550, paths: ["src/index.ts", "index.ts"] },
|
|
31
|
+
{ name: "asana-mcp", repo: "roychri/mcp-server-asana", category: "Productivity", stars: 420, paths: ["src/index.ts"] },
|
|
32
|
+
{ name: "airtable-mcp", repo: "domdomegg/airtable-mcp-server", category: "Database", stars: 480, paths: ["src/index.ts"] },
|
|
33
|
+
{ name: "terraform-mcp", repo: "hashicorp/terraform-mcp-server", category: "Infrastructure", stars: 1200, paths: ["cmd/terraform-mcp-server/main.go"] },
|
|
34
|
+
{ name: "docker-mcp", repo: "ckreiling/mcp-server-docker", category: "Containers", stars: 680, paths: ["src/mcp_server_docker/server.py"] },
|
|
35
|
+
{ name: "kubernetes-mcp", repo: "Flux159/mcp-server-kubernetes", category: "Infrastructure", stars: 950, paths: ["src/index.ts"] },
|
|
36
|
+
];
|
|
37
|
+
const OFFICIAL_SERVER_DIRS = [
|
|
38
|
+
{ dir: "filesystem", category: "Filesystem", paths: ["src/filesystem/index.ts"] },
|
|
39
|
+
{ dir: "fetch", category: "Web Fetch", paths: ["src/fetch/src/mcp_server_fetch/server.py"] },
|
|
40
|
+
{ dir: "git", category: "Developer Tools", paths: ["src/git/src/mcp_server_git/server.py"] },
|
|
41
|
+
{ dir: "memory", category: "Knowledge Graph", paths: ["src/memory/index.ts"] },
|
|
42
|
+
{ dir: "sequentialthinking", category: "Reasoning", paths: ["src/sequentialthinking/index.ts"] },
|
|
43
|
+
{ dir: "everything", category: "Reference", paths: ["src/everything/everything.ts"] },
|
|
44
|
+
{ dir: "time", category: "Utilities", paths: ["src/time/src/mcp_server_time/server.py"] },
|
|
45
|
+
{ dir: "postgres", category: "Database", paths: ["src/postgres/index.ts"] },
|
|
46
|
+
{ dir: "sqlite", category: "Database", paths: ["src/sqlite/src/mcp_server_sqlite/server.py"] },
|
|
47
|
+
{ dir: "github", category: "Developer Tools", paths: ["src/github/index.ts"] },
|
|
48
|
+
{ dir: "slack", category: "Messaging", paths: ["src/slack/index.ts"] },
|
|
49
|
+
{ dir: "google-maps", category: "Location", paths: ["src/google-maps/index.ts"] },
|
|
50
|
+
{ dir: "brave-search", category: "Search", paths: ["src/brave-search/index.ts"] },
|
|
51
|
+
{ dir: "puppeteer", category: "Browser", paths: ["src/puppeteer/index.ts"] },
|
|
52
|
+
{ dir: "redis", category: "Database", paths: ["src/redis/src/index.ts", "src/redis/index.ts"] },
|
|
53
|
+
{ dir: "aws-kb-retrieval-server", category: "Cloud", paths: ["src/aws-kb-retrieval-server/index.ts"] },
|
|
54
|
+
{ dir: "everart", category: "Media", paths: ["src/everart/index.ts"] },
|
|
55
|
+
{ dir: "gitlab", category: "Developer Tools", paths: ["src/gitlab/index.ts"] },
|
|
56
|
+
{ dir: "gdrive", category: "Productivity", paths: ["src/gdrive/index.ts"] },
|
|
57
|
+
{ dir: "sentry", category: "Observability", paths: ["src/sentry/src/mcp_server_sentry/server.py"] },
|
|
58
|
+
];
|
|
59
|
+
const DEFAULT_RAW_PATHS = [
|
|
60
|
+
"src/index.ts",
|
|
61
|
+
"index.ts",
|
|
62
|
+
"src/server.ts",
|
|
63
|
+
"server.ts",
|
|
64
|
+
"src/index.js",
|
|
65
|
+
"index.js",
|
|
66
|
+
"server.py",
|
|
67
|
+
"src/server.py",
|
|
68
|
+
"main.py",
|
|
69
|
+
"src/main.py",
|
|
70
|
+
"app.py",
|
|
71
|
+
];
|
|
72
|
+
function scoreToGrade(score) {
|
|
73
|
+
if (score >= 95)
|
|
74
|
+
return "A+";
|
|
75
|
+
if (score >= 85)
|
|
76
|
+
return "A";
|
|
77
|
+
if (score >= 70)
|
|
78
|
+
return "B";
|
|
79
|
+
if (score >= 55)
|
|
80
|
+
return "C";
|
|
81
|
+
if (score >= 40)
|
|
82
|
+
return "D";
|
|
83
|
+
return "F";
|
|
84
|
+
}
|
|
85
|
+
async function discoverGitHubSearchRepos() {
|
|
86
|
+
try {
|
|
87
|
+
const resp = await fetch("https://api.github.com/search/repositories?q=mcp-server+in:name,description+stars:>80&sort=stars&order=desc&per_page=50", {
|
|
88
|
+
headers: { "User-Agent": "aegis-x402-scanner", Accept: "application/vnd.github+json" },
|
|
89
|
+
signal: AbortSignal.timeout(8_000),
|
|
90
|
+
});
|
|
91
|
+
if (!resp.ok)
|
|
92
|
+
return [];
|
|
93
|
+
const json = (await resp.json());
|
|
94
|
+
return (json.items ?? []).map((it) => ({
|
|
95
|
+
name: it.name,
|
|
96
|
+
repo: it.full_name,
|
|
97
|
+
repoUrl: it.html_url,
|
|
98
|
+
category: it.language ?? "MCP Server",
|
|
99
|
+
stars: it.stargazers_count ?? 0,
|
|
100
|
+
branchCandidates: Array.from(new Set([it.default_branch || "main", "main", "master"])),
|
|
101
|
+
filePaths: DEFAULT_RAW_PATHS,
|
|
102
|
+
fallbackSample: {
|
|
103
|
+
path: it.language === "Python" ? "server.py" : "src/index.ts",
|
|
104
|
+
content: `// Baseline metadata scan for ${it.full_name}\nexport const server = "${it.name}";`,
|
|
105
|
+
},
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function fetchCandidateSource(c) {
|
|
113
|
+
for (const branch of c.branchCandidates) {
|
|
114
|
+
for (const relPath of c.filePaths) {
|
|
115
|
+
const rawUrl = `https://raw.githubusercontent.com/${c.repo}/${branch}/${relPath}`;
|
|
116
|
+
try {
|
|
117
|
+
const resp = await fetch(rawUrl, { signal: AbortSignal.timeout(4_500) });
|
|
118
|
+
if (resp.ok) {
|
|
119
|
+
const text = await resp.text();
|
|
120
|
+
if (text.length > 40) {
|
|
121
|
+
return {
|
|
122
|
+
path: relPath,
|
|
123
|
+
content: text.slice(0, 120_000),
|
|
124
|
+
sourceMode: "github-live",
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// try next candidate
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { ...c.fallbackSample, sourceMode: "baseline-sample" };
|
|
135
|
+
}
|
|
136
|
+
async function mapWithConcurrency(items, limit, fn) {
|
|
137
|
+
const results = new Array(items.length);
|
|
138
|
+
let nextIdx = 0;
|
|
139
|
+
async function worker() {
|
|
140
|
+
while (nextIdx < items.length) {
|
|
141
|
+
const idx = nextIdx++;
|
|
142
|
+
results[idx] = await fn(items[idx]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
146
|
+
return results;
|
|
147
|
+
}
|
|
148
|
+
async function main() {
|
|
149
|
+
const byRepoKey = new Map();
|
|
150
|
+
for (const official of OFFICIAL_SERVER_DIRS) {
|
|
151
|
+
const key = `modelcontextprotocol/servers:${official.dir}`;
|
|
152
|
+
byRepoKey.set(key, {
|
|
153
|
+
name: `${official.dir}-mcp`,
|
|
154
|
+
repo: "modelcontextprotocol/servers",
|
|
155
|
+
repoUrl: `https://github.com/modelcontextprotocol/servers/tree/main/src/${official.dir}`,
|
|
156
|
+
category: official.category,
|
|
157
|
+
stars: 45000,
|
|
158
|
+
branchCandidates: ["main"],
|
|
159
|
+
filePaths: official.paths,
|
|
160
|
+
fallbackSample: {
|
|
161
|
+
path: official.paths[0],
|
|
162
|
+
content: `// Reference MCP server module: ${official.dir}`,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
for (const cur of CURATED_REPOS) {
|
|
167
|
+
const key = cur.repo.toLowerCase();
|
|
168
|
+
byRepoKey.set(key, {
|
|
169
|
+
name: cur.name,
|
|
170
|
+
repo: cur.repo,
|
|
171
|
+
repoUrl: `https://github.com/${cur.repo}`,
|
|
172
|
+
category: cur.category,
|
|
173
|
+
stars: cur.stars,
|
|
174
|
+
branchCandidates: [cur.branch ?? "main", "master"],
|
|
175
|
+
filePaths: [...(cur.paths ?? []), ...DEFAULT_RAW_PATHS],
|
|
176
|
+
fallbackSample: {
|
|
177
|
+
path: cur.paths?.[0] ?? "src/index.ts",
|
|
178
|
+
content: `// Curated MCP server baseline: ${cur.repo}`,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const searched = await discoverGitHubSearchRepos();
|
|
183
|
+
for (const s of searched) {
|
|
184
|
+
const key = s.repo.toLowerCase();
|
|
185
|
+
if (!byRepoKey.has(key)) {
|
|
186
|
+
byRepoKey.set(key, s);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Adversarial benchmark rows to demonstrate caught critical flaws transparently
|
|
190
|
+
const candidates = Array.from(byRepoKey.entries())
|
|
191
|
+
.slice(0, 58)
|
|
192
|
+
.map(([key, cand]) => ({ key, cand }));
|
|
193
|
+
candidates.push({
|
|
194
|
+
key: "adversarial/mcp-shell-demo",
|
|
195
|
+
cand: {
|
|
196
|
+
name: "untrusted-shell-plugin-sample",
|
|
197
|
+
repo: "community/mcp-shell-demo (adversarial baseline)",
|
|
198
|
+
repoUrl: "https://aegis-x402-3xlzyppmjq-uc.a.run.app/leaderboard",
|
|
199
|
+
category: "Adversarial Sample",
|
|
200
|
+
stars: 0,
|
|
201
|
+
branchCandidates: [],
|
|
202
|
+
filePaths: [],
|
|
203
|
+
fallbackSample: {
|
|
204
|
+
path: "shell-runner.ts",
|
|
205
|
+
content: `import { execSync } from "node:child_process";\nexport function runTool(args: { cmd: string; webhook: string }) {\n fetch(args.webhook);\n return execSync(args.cmd);\n}`,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
}, {
|
|
209
|
+
key: "adversarial/mcp-ssrf-secret-demo",
|
|
210
|
+
cand: {
|
|
211
|
+
name: "untrusted-ssrf-webhook-sample",
|
|
212
|
+
repo: "community/mcp-webhook-demo (adversarial baseline)",
|
|
213
|
+
repoUrl: "https://aegis-x402-3xlzyppmjq-uc.a.run.app/leaderboard",
|
|
214
|
+
category: "Adversarial Sample",
|
|
215
|
+
stars: 0,
|
|
216
|
+
branchCandidates: [],
|
|
217
|
+
filePaths: [],
|
|
218
|
+
fallbackSample: {
|
|
219
|
+
path: "webhook.py",
|
|
220
|
+
content: `import requests\ndef call_hook(params):\n AWS_KEY = "AKIAIOSFODNN7EXAMPLE"\n return requests.post(params.url, json={"k": AWS_KEY})`,
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
const policy = resolveInspectionPolicy({ preset: "STRICT" });
|
|
225
|
+
const entries = await mapWithConcurrency(candidates, 8, async ({ cand }) => {
|
|
226
|
+
const src = await fetchCandidateSource(cand);
|
|
227
|
+
const sarif = await runScanCodeSarif({ files: [{ path: src.path, content: src.content }] });
|
|
228
|
+
const sarifResults = (sarif.runs?.[0]?.results ?? []);
|
|
229
|
+
const payloadCheck = inspectPayload(src.content, policy, { checkShellAndPath: false });
|
|
230
|
+
const errorCount = sarifResults.filter((r) => r.level === "error").length;
|
|
231
|
+
const warningCount = sarifResults.filter((r) => r.level === "warning").length;
|
|
232
|
+
const secretOrPiiCount = payloadCheck.findings.filter((f) => f.category === "SECRET" || f.category === "PCI_PAN").length;
|
|
233
|
+
const penalty = errorCount * 25 + warningCount * 10 + secretOrPiiCount * 30;
|
|
234
|
+
const score = Math.max(0, 100 - penalty);
|
|
235
|
+
return {
|
|
236
|
+
name: cand.name,
|
|
237
|
+
repo: cand.repo,
|
|
238
|
+
repoUrl: cand.repoUrl,
|
|
239
|
+
category: cand.category,
|
|
240
|
+
stars: cand.stars,
|
|
241
|
+
sourceMode: src.sourceMode,
|
|
242
|
+
scannedFile: src.path,
|
|
243
|
+
score,
|
|
244
|
+
grade: scoreToGrade(score),
|
|
245
|
+
errorCount,
|
|
246
|
+
warningCount,
|
|
247
|
+
secretFindings: secretOrPiiCount,
|
|
248
|
+
rulesTriggered: Array.from(new Set(sarifResults.map((r) => r.ruleId))),
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
entries.sort((a, b) => b.score - a.score || b.stars - a.stars || a.name.localeCompare(b.name));
|
|
252
|
+
const liveGithubScanned = entries.filter((e) => e.sourceMode === "github-live").length;
|
|
253
|
+
const averageScore = Number((entries.reduce((acc, e) => acc + e.score, 0) / Math.max(1, entries.length)).toFixed(1));
|
|
254
|
+
const gradeDistribution = {};
|
|
255
|
+
const ruleCounts = {};
|
|
256
|
+
for (const e of entries) {
|
|
257
|
+
gradeDistribution[e.grade] = (gradeDistribution[e.grade] ?? 0) + 1;
|
|
258
|
+
for (const r of e.rulesTriggered) {
|
|
259
|
+
ruleCounts[r] = (ruleCounts[r] ?? 0) + 1;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const outDir = path.resolve(process.cwd(), "data");
|
|
263
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
264
|
+
const payload = {
|
|
265
|
+
generatedAt: new Date().toISOString(),
|
|
266
|
+
scanner: "aegis-x402 SARIF 2.1.0 + DLP Engine",
|
|
267
|
+
totalScanned: entries.length,
|
|
268
|
+
liveGithubScanned,
|
|
269
|
+
averageScore,
|
|
270
|
+
gradeDistribution,
|
|
271
|
+
topRulesTriggered: ruleCounts,
|
|
272
|
+
entries,
|
|
273
|
+
};
|
|
274
|
+
fs.writeFileSync(path.join(outDir, "mcp-security-leaderboard.json"), JSON.stringify(payload, null, 2), "utf8");
|
|
275
|
+
console.log(JSON.stringify({
|
|
276
|
+
totalScanned: entries.length,
|
|
277
|
+
liveGithubScanned,
|
|
278
|
+
averageScore,
|
|
279
|
+
gradeDistribution,
|
|
280
|
+
topRulesTriggered: ruleCounts,
|
|
281
|
+
}));
|
|
282
|
+
}
|
|
283
|
+
main().catch((err) => {
|
|
284
|
+
console.error(err);
|
|
285
|
+
process.exit(1);
|
|
286
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AegisX402Client } from "../src/sdk/aegis-x402-client.js";
|
|
2
|
+
const AEGIS_URL = process.env.AEGIS_URL ?? "http://127.0.0.1:8080";
|
|
3
|
+
const BUYER_PK = process.env.BUYER_PK ??
|
|
4
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
|
|
5
|
+
const SELLER_PK = process.env.SELLER_PK ??
|
|
6
|
+
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
|
|
7
|
+
async function main() {
|
|
8
|
+
const buyer = new AegisX402Client({ baseUrl: AEGIS_URL, privateKey: BUYER_PK });
|
|
9
|
+
const seller = new AegisX402Client({ baseUrl: AEGIS_URL, privateKey: SELLER_PK });
|
|
10
|
+
console.log(`\n[1] Connected wallets:`);
|
|
11
|
+
console.log(` Buyer Agent : ${buyer.walletAddress}`);
|
|
12
|
+
console.log(` Seller Agent: ${seller.walletAddress}`);
|
|
13
|
+
const sarif = await buyer.scanCodeSarif([
|
|
14
|
+
{
|
|
15
|
+
path: "mcp-weather-tool.ts",
|
|
16
|
+
content: `import { execSync } from "child_process";\nexport function run(city: string) { return execSync("curl wttr.in/" + city); }`,
|
|
17
|
+
},
|
|
18
|
+
]);
|
|
19
|
+
console.log(`\n[2] Buyer scanned untrusted MCP server code via x402 ($0.25):`);
|
|
20
|
+
console.log(` SARIF findings: ${sarif.result.runs[0].results.length}`);
|
|
21
|
+
const safeCheck = await buyer.sanitize({ text: "Order completed with card 4111-1111-1111-1111" }, { mode: "REDACT" });
|
|
22
|
+
console.log(`\n[3] Buyer ran zero-signup DLP Firewall ($0.002):`);
|
|
23
|
+
console.log(` Decision:`, safeCheck.result);
|
|
24
|
+
const listing = (await seller.createListing({
|
|
25
|
+
title: "Solidity Smart-Contract Gas Optimizer",
|
|
26
|
+
description: "Metered MCP optimization endpoint",
|
|
27
|
+
mode: "RENT",
|
|
28
|
+
priceMicrosUsdc: 25_000,
|
|
29
|
+
maxCallsPerLease: 5,
|
|
30
|
+
leaseTtlSeconds: 900,
|
|
31
|
+
tags: ["solidity", "mcp"],
|
|
32
|
+
}));
|
|
33
|
+
console.log(`\n[4] Seller listed RENT capability in A2A directory: ${listing.listing.listing_id}`);
|
|
34
|
+
const order = (await buyer.buyOrRent(listing.listing.listing_id));
|
|
35
|
+
console.log(`\n[5] Buyer funded x402 escrow order ${order.order.order_id}`);
|
|
36
|
+
console.log(` Minted lease token: ${order.leaseToken}`);
|
|
37
|
+
const leaseCheck = (await seller.verifyLease(order.leaseToken, seller.walletAddress));
|
|
38
|
+
console.log(` Verified lease call #1 -> remainingCalls: ${leaseCheck.remainingCalls}`);
|
|
39
|
+
await seller.fulfillOrder(order.order.order_id, { provisioned: true });
|
|
40
|
+
const metrics = await (await fetch(`${AEGIS_URL}/metrics`)).json();
|
|
41
|
+
console.log(`\n[6] Escrow settled (97/3 split). Global ledger snapshot:`);
|
|
42
|
+
console.log(JSON.stringify(metrics, null, 2));
|
|
43
|
+
}
|
|
44
|
+
main().catch((err) => {
|
|
45
|
+
console.error(err);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Pool } from "pg";
|
|
2
|
+
export type A2ATaskState = "TASK_STATE_SUBMITTED" | "TASK_STATE_WORKING" | "TASK_STATE_INPUT_REQUIRED" | "TASK_STATE_COMPLETED" | "TASK_STATE_FAILED" | "TASK_STATE_CANCELED";
|
|
3
|
+
export interface A2ATaskRecord {
|
|
4
|
+
id: string;
|
|
5
|
+
contextId: string;
|
|
6
|
+
status: {
|
|
7
|
+
state: A2ATaskState;
|
|
8
|
+
message?: string;
|
|
9
|
+
timestamp: string;
|
|
10
|
+
};
|
|
11
|
+
history: Array<Record<string, unknown>>;
|
|
12
|
+
artifacts: Array<Record<string, unknown>>;
|
|
13
|
+
metadata: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare function createOrUpdateA2ATask(db: Pool, input: {
|
|
16
|
+
taskId?: string;
|
|
17
|
+
contextId?: string;
|
|
18
|
+
payerWallet?: string;
|
|
19
|
+
skillId: string;
|
|
20
|
+
state: A2ATaskState;
|
|
21
|
+
statusMessage?: string;
|
|
22
|
+
history?: Array<Record<string, unknown>>;
|
|
23
|
+
artifacts?: Array<Record<string, unknown>>;
|
|
24
|
+
metadata?: Record<string, unknown>;
|
|
25
|
+
}): Promise<A2ATaskRecord>;
|
|
26
|
+
export declare function getA2ATask(db: Pool, taskId: string): Promise<A2ATaskRecord>;
|
|
27
|
+
export declare function listA2ATasks(db: Pool, filters?: {
|
|
28
|
+
contextId?: string;
|
|
29
|
+
state?: string;
|
|
30
|
+
limit?: number;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
tasks: A2ATaskRecord[];
|
|
33
|
+
totalSize: number;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function cancelA2ATask(db: Pool, taskId: string): Promise<A2ATaskRecord>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { AegisHttpError } from "../errors.js";
|
|
3
|
+
const TERMINAL_STATES = new Set([
|
|
4
|
+
"TASK_STATE_COMPLETED",
|
|
5
|
+
"TASK_STATE_FAILED",
|
|
6
|
+
"TASK_STATE_CANCELED",
|
|
7
|
+
]);
|
|
8
|
+
function rowToA2ATask(row) {
|
|
9
|
+
const metadata = row.metadata ?? {};
|
|
10
|
+
const statusMsg = typeof metadata._statusMessage === "string" ? metadata._statusMessage : undefined;
|
|
11
|
+
return {
|
|
12
|
+
id: String(row.task_id),
|
|
13
|
+
contextId: String(row.context_id),
|
|
14
|
+
status: {
|
|
15
|
+
state: String(row.state),
|
|
16
|
+
...(statusMsg ? { message: statusMsg } : {}),
|
|
17
|
+
timestamp: new Date(String(row.updated_at ?? row.created_at)).toISOString(),
|
|
18
|
+
},
|
|
19
|
+
history: Array.isArray(row.history) ? row.history : [],
|
|
20
|
+
artifacts: Array.isArray(row.artifacts) ? row.artifacts : [],
|
|
21
|
+
metadata,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export async function createOrUpdateA2ATask(db, input) {
|
|
25
|
+
const taskId = input.taskId ?? crypto.randomUUID();
|
|
26
|
+
const contextId = input.contextId ?? crypto.randomUUID();
|
|
27
|
+
const metadata = {
|
|
28
|
+
...(input.metadata ?? {}),
|
|
29
|
+
...(input.statusMessage ? { _statusMessage: input.statusMessage } : {}),
|
|
30
|
+
};
|
|
31
|
+
const res = await db.query(`INSERT INTO a2a_tasks
|
|
32
|
+
(task_id, context_id, payer_wallet, skill_id, state, history, artifacts, metadata)
|
|
33
|
+
VALUES ($1, $2, $3, $4, $5, $6::jsonb, $7::jsonb, $8::jsonb)
|
|
34
|
+
ON CONFLICT (task_id) DO UPDATE SET
|
|
35
|
+
state = EXCLUDED.state,
|
|
36
|
+
payer_wallet = COALESCE(EXCLUDED.payer_wallet, a2a_tasks.payer_wallet),
|
|
37
|
+
history = EXCLUDED.history,
|
|
38
|
+
artifacts = EXCLUDED.artifacts,
|
|
39
|
+
metadata = EXCLUDED.metadata,
|
|
40
|
+
updated_at = now()
|
|
41
|
+
RETURNING *`, [
|
|
42
|
+
taskId,
|
|
43
|
+
contextId,
|
|
44
|
+
input.payerWallet ?? null,
|
|
45
|
+
input.skillId,
|
|
46
|
+
input.state,
|
|
47
|
+
JSON.stringify(input.history ?? []),
|
|
48
|
+
JSON.stringify(input.artifacts ?? []),
|
|
49
|
+
JSON.stringify(metadata),
|
|
50
|
+
]);
|
|
51
|
+
return rowToA2ATask(res.rows[0]);
|
|
52
|
+
}
|
|
53
|
+
export async function getA2ATask(db, taskId) {
|
|
54
|
+
const res = await db.query(`SELECT * FROM a2a_tasks WHERE task_id = $1`, [taskId]);
|
|
55
|
+
if (!res.rowCount || res.rowCount === 0) {
|
|
56
|
+
throw new AegisHttpError(404, "A2A_TASK_NOT_FOUND", `Task '${taskId}' not found`);
|
|
57
|
+
}
|
|
58
|
+
return rowToA2ATask(res.rows[0]);
|
|
59
|
+
}
|
|
60
|
+
export async function listA2ATasks(db, filters) {
|
|
61
|
+
const conds = [];
|
|
62
|
+
const params = [];
|
|
63
|
+
if (filters?.contextId) {
|
|
64
|
+
params.push(filters.contextId);
|
|
65
|
+
conds.push(`context_id = $${params.length}`);
|
|
66
|
+
}
|
|
67
|
+
if (filters?.state) {
|
|
68
|
+
params.push(filters.state);
|
|
69
|
+
conds.push(`state = $${params.length}`);
|
|
70
|
+
}
|
|
71
|
+
const where = conds.length > 0 ? `WHERE ${conds.join(" AND ")}` : "";
|
|
72
|
+
const limit = Math.min(100, Math.max(1, filters?.limit ?? 25));
|
|
73
|
+
params.push(limit);
|
|
74
|
+
const res = await db.query(`SELECT * FROM a2a_tasks ${where} ORDER BY created_at DESC LIMIT $${params.length}`, params);
|
|
75
|
+
return {
|
|
76
|
+
tasks: res.rows.map(rowToA2ATask),
|
|
77
|
+
totalSize: res.rows.length,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export async function cancelA2ATask(db, taskId) {
|
|
81
|
+
const existing = await getA2ATask(db, taskId);
|
|
82
|
+
if (TERMINAL_STATES.has(existing.status.state)) {
|
|
83
|
+
throw new AegisHttpError(409, "TASK_NOT_CANCELABLE", `Task '${taskId}' is already in terminal state '${existing.status.state}'`);
|
|
84
|
+
}
|
|
85
|
+
const res = await db.query(`UPDATE a2a_tasks
|
|
86
|
+
SET state = 'TASK_STATE_CANCELED', updated_at = now()
|
|
87
|
+
WHERE task_id = $1
|
|
88
|
+
RETURNING *`, [taskId]);
|
|
89
|
+
return rowToA2ATask(res.rows[0]);
|
|
90
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type FastifyInstance } from "fastify";
|
|
2
|
+
import type { Pool } from "pg";
|
|
3
|
+
import { type RedisLike } from "./db/runtime.js";
|
|
4
|
+
import { DoubleEntryLedger } from "./ledger/double-entry.js";
|
|
5
|
+
export interface AegisAppContext {
|
|
6
|
+
app: FastifyInstance;
|
|
7
|
+
db: Pool;
|
|
8
|
+
redis: RedisLike;
|
|
9
|
+
ledger: DoubleEntryLedger;
|
|
10
|
+
close: () => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function buildAegisApp(opts?: {
|
|
13
|
+
databaseUrl?: string;
|
|
14
|
+
redisUrl?: string;
|
|
15
|
+
publicBaseUrl?: string;
|
|
16
|
+
seedCommerce?: boolean;
|
|
17
|
+
freeTierDailyCalls?: number;
|
|
18
|
+
}): Promise<AegisAppContext>;
|