web3-systemic-agent 1.0.2__py3-none-any.whl

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.
@@ -0,0 +1,511 @@
1
+ Metadata-Version: 2.4
2
+ Name: web3-systemic-agent
3
+ Version: 1.0.2
4
+ Summary: Autonomous Web3 Security and Governance Auditor MCP Server with Two-Stage Hybrid LLM Pipeline and x402 Micropayments
5
+ Author: RafaCoelho33
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://web3-systemic-agent.onrender.com
8
+ Project-URL: Repository, https://github.com/RafaCoelho33/web3-systemic-agent
9
+ Keywords: mcp,model-context-protocol,web3,base,ethereum,security,honeypot,dao,x402,smart-contracts
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Security
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.11
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: web3>=8.0.0
21
+ Requires-Dist: pydantic>=2.13.4
22
+ Requires-Dist: fastapi>=0.141.1
23
+ Requires-Dist: uvicorn>=0.49.0
24
+ Requires-Dist: httpx>=0.28.1
25
+ Requires-Dist: openai>=3.39.0
26
+ Requires-Dist: google-genai>=2.33.0
27
+ Requires-Dist: python-dotenv>=1.2.2
28
+ Requires-Dist: aiosqlite>=0.20.0
29
+ Requires-Dist: x402[evm,httpx]>=2.0.0
30
+ Requires-Dist: jsonschema>=4.0.0
31
+ Dynamic: license-file
32
+
33
+ # Web3 Condition-Action Trigger Agent
34
+ ### Autonomous Web3 Security & Governance Auditor with Two-Stage Hybrid LLM Pipeline & x402 Bazaar Micropayments
35
+
36
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
37
+ [![PyPI version](https://img.shields.io/pypi/v/web3-systemic-agent.svg)](https://pypi.org/project/web3-systemic-agent/)
38
+ [![Base](https://img.shields.io/badge/network-Base%20Mainnet%20%7C%20Sepolia-0052FF.svg)](https://base.org)
39
+ [![x402 Protocol](https://img.shields.io/badge/payment-x402%20(EIP--3009%20USDC)-2775C9.svg)](https://x402.org)
40
+ [![MCP Server](https://img.shields.io/badge/MCP-2024--11--05-brightgreen.svg)](https://modelcontextprotocol.io)
41
+ [![Glama MCP](https://glama.ai/mcp/servers/@RafaCoelho33/web3-systemic-agent/badges/score.svg)](https://glama.ai/mcp/servers/@RafaCoelho33/web3-systemic-agent)
42
+ [![mcptry](https://mcptry.com/badge/io.github.RafaCoelho33/web3-systemic-agent)](https://mcptry.com/servers/io.github.RafaCoelho33/web3-systemic-agent)
43
+ [![M8ven Score](https://m8ven.ai/badge/mcp/rafacoelho33/web3-systemic-agent)](https://m8ven.ai/mcp/rafacoelho33/web3-systemic-agent?s=readme)
44
+ [![Gemini 2.5/3.5](https://img.shields.io/badge/LLM-Google%20Gemini-orange.svg)](https://ai.google.dev/)
45
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
46
+
47
+ An autonomous Web3 agent engineered for real-time smart contract monitoring, DEX honeypot detection, and DAO governance security. Features a **two-stage hybrid architecture** that combines zero-cost deterministic on-chain gatekeeping with structured Gemini LLM evaluations, monetized Agent-to-Agent (A2A) via **x402 gasless USDC micropayments** on Base.
48
+
49
+ Operates natively as both a high-throughput **FastAPI REST Service** and a **Model Context Protocol (MCP) Server** compatible with Claude Desktop, Cursor, Smithery, Glama, and Coinbase AgentKit.
50
+
51
+ ---
52
+
53
+ ## ๐ŸŒ Live Production Service
54
+
55
+ The service is continuously deployed and operational in production on [Render](https://render.com):
56
+
57
+ * **Base URL:** [`https://web3-systemic-agent.onrender.com`](https://web3-systemic-agent.onrender.com)
58
+ * **MCP Discovery / Streamable-HTTP:** [`https://web3-systemic-agent.onrender.com/mcp`](https://web3-systemic-agent.onrender.com/mcp)
59
+ * **A2A Agent Card:** [`https://web3-systemic-agent.onrender.com/.well-known/agent-card.json`](https://web3-systemic-agent.onrender.com/.well-known/agent-card.json)
60
+ * **x402 Discovery Metadata:** [`https://web3-systemic-agent.onrender.com/.well-known/x402`](https://web3-systemic-agent.onrender.com/.well-known/x402)
61
+ * **x402 Pricing Tiers:** `0.005 USDC` (`/token/check`) ยท `0.01 USDC` (`/preflight`) ยท `0.015 USDC` (`/audit`, `/evaluate`) ยท `0.25 USDC` (`/audit/deep`) โ€” EIP-3009 Gasless
62
+ * **Default Production Network:** Base Mainnet (`eip155:8453`) & Base Sepolia (`eip155:84532`)
63
+ * **Agent Recipient Wallet (`PAY_TO_ADDRESS`):** [`0x2b7F1fd931f7f28f89e0f688Dd5Bb7a620c24b63`](https://basescan.org/address/0x2b7F1fd931f7f28f89e0f688Dd5Bb7a620c24b63)
64
+
65
+ ### Canonical API Endpoints
66
+
67
+ | Method | Route | Description | x402 Micropayment |
68
+ | :--- | :--- | :--- | :--- |
69
+ | `GET` | `/` | Service discovery, payment parameters, and endpoint directory | Free |
70
+ | `GET` | `/health` | Uptime probe, multi-chain RPC connectivity, LLM status | Free |
71
+ | `GET` | `/.well-known/x402` | x402 v2 service specification and Bazaar discovery resources | Free |
72
+ | `GET` | `/.well-known/agent-card.json` | Agent-to-Agent (A2A) discovery card and capability manifest | Free |
73
+ | `GET` | `/.well-known/owners.json` | Verified project ownership metadata (GitHub + payout wallet) | Free |
74
+ | `GET` | `/feed/recent` | Recent autonomous security audits and discovery feed | Free |
75
+ | `GET` | `/report/{chain_id}/{address}` | Public security audit report lookup by chain ID and contract address | Free |
76
+ | `GET` | `/mcp` | MCP server discovery, transport metadata, tools manifest | Free |
77
+ | `POST` | `/mcp` | MCP JSON-RPC 2.0 execution endpoint (streamable-http) | Free / 402 for Deep Audit |
78
+ | `POST` | `/rules/validate` | Static deterministic rule pre-validation and syntax check | Free |
79
+ | `GET` / `POST` | `/token/check` | Fast static token honeypot, selector & proxy screening (`TokenCheckResponse`) | **0.005 USDC** |
80
+ | `GET` / `POST` | `/preflight` | Pre-sign firewall: Permit2/approval decode, EIP-712, IPI & `eth_call` simulation | **0.01 USDC** |
81
+ | `GET` / `POST` | `/audit` | Simplified one-shot Smart Contract Audit (`QuickAuditRequest`) | **0.015 USDC** |
82
+ | `GET` / `POST` | `/evaluate` | Two-stage hybrid evaluation (`ConditionRulePayload` + Gemini LLM) | **0.015 USDC** |
83
+ | `GET` / `POST` | `/audit/deep` | Deep Tier Pro Audit: EIP-1967 proxy resolution + Sourcify/Etherscan source + LLM | **0.25 USDC** |
84
+ | `POST` | `/rules/evaluate-batch` | Synchronous batch evaluation for up to 50 rules | Free / Sub-rules gated |
85
+ | `POST` | `/rules/enqueue` | Asynchronous evaluation queue returning unique `job_id` | Free |
86
+ | `GET` | `/jobs/{job_id}` | Asynchronous job status inspection and results retrieval | Free |
87
+
88
+ ---
89
+
90
+ ## ๐Ÿ”Œ Model Context Protocol (MCP) Server
91
+
92
+ The agent provides a first-class **Model Context Protocol (MCP)** server (`src/mcp_server.py`) implementing protocol specification `2024-11-05`. It exposes **6 tools** (5 free Stage 1 on-chain analysis tools + 1 paid Stage 2 deep semantic audit tool), **4 MCP Resources**, and **3 MCP Prompts**:
93
+
94
+ ```
95
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
96
+ โ”‚ MCP Server Registry (v1.0.2) โ”‚
97
+ โ”‚ 6 Tools ยท 4 Resources ยท 3 Prompts โ”‚
98
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
99
+ โ”‚
100
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
101
+ โ–ผ โ–ผ
102
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
103
+ โ”‚ STAGE 1: 5 FREE TOOLS โ”‚ โ”‚ STAGE 2: PAID AUDIT โ”‚
104
+ โ”‚ (Deterministic / $0.00) โ”‚ โ”‚ ($0.015 / $0.25 via x402) โ”‚
105
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
106
+ โ”‚ โ”‚
107
+ โ”œโ”€โ”€ scan_contract_selectors โ”€โ”€โ”€> Discovers EVM selectors & high-risk backdoors โ”‚
108
+ โ”œโ”€โ”€ check_token_honeypot โ”€โ”€โ”€> Static bytecode analysis for tax & blacklist traps โ”‚
109
+ โ”œโ”€โ”€ scan_dao_proposals โ”€โ”€โ”€> Ingests Snapshot DAO proposals & calldata payloads โ”‚
110
+ โ”œโ”€โ”€ preflight_tx_firewall โ”€โ”€โ”€> Permit2/EIP-712/IPI firewall & eth_call simulation โ”‚
111
+ โ””โ”€โ”€ inspect_proxy_and_source โ”€โ”€โ”€> EIP-1967/Beacon proxy slots & Sourcify/Etherscan โ”‚
112
+ โ”‚
113
+ โ””โ”€โ”€โ”€ (Upsell Recommendation Triggered) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
114
+ โ–ผ
115
+ deep_semantic_audit
116
+ (Two-Stage Gatekeeping + Gemini LLM Reasoning)
117
+ ```
118
+
119
+ ### 1. Free Stage 1 Tools (5 Tools โ€” `$0.00`)
120
+
121
+ #### `scan_contract_selectors`
122
+ * **Purpose:** Free deterministic bytecode inspection on Base or any EVM network. Discovers 4-byte function selectors and flags high-privilege administrative backdoors (`transferOwnership`, `upgradeTo`, `mint`, `selfdestruct`).
123
+ * **Parameters:**
124
+ * `target_address` *(string, required)*: Hex EVM smart contract address.
125
+ * `chain_id` *(integer, default 8453)*: EVM Chain ID (8453 for Base Mainnet, 84532 for Base Sepolia, 42161 for Arbitrum One).
126
+ * `bytecode_override` *(string, optional)*: Raw contract runtime bytecode hex string for offline analysis.
127
+ * **Returns:** Contract status, bytecode size, extracted selectors, flagged high-risk capabilities, risk level (`HIGH`, `LOW`, `EOA`), and upsell recommendation.
128
+
129
+ #### `check_token_honeypot`
130
+ * **Purpose:** Free static bytecode analysis for DEX honeypots, rugpull traps, and malicious token contracts:
131
+ * Blacklist manipulation (`isBlacklisted`, `setBlacklist`, `addToBlacklist`)
132
+ * Arbitrary transfer taxes & 100% sell fee traps (`setTax`, `setFee`, `setSellFee`)
133
+ * Trading freeze and pause backdoors (`pause`, `setTrading`, `enableTrading`)
134
+ * EVM `SELFDESTRUCT` (opcode `0xff`) drainage traps
135
+ * **Parameters:**
136
+ * `token_address` *(string, required)*: Hex EVM address of token contract.
137
+ * `chain_id` *(integer, default 8453)*: EVM Chain ID.
138
+ * `bytecode_override` *(string, optional)*: Raw token runtime bytecode for offline analysis.
139
+ * **Returns:** `is_honeypot_suspect` boolean, numeric `risk_score` (0.0 to 10.0), active threat categories, detailed risk flags, and audit upsell guidance.
140
+
141
+ #### `scan_dao_proposals`
142
+ * **Purpose:** Free scanner for recent Snapshot DAO governance proposals (Arbitrum, Aave, ENS, etc.). Extracts proposed execution targets, native Wei value transfers, and 4-byte calldata to detect governance hijack attempts.
143
+ * **Parameters:**
144
+ * `space_id` *(string, default "arbitrumfoundation.eth")*: Snapshot DAO space ENS domain.
145
+ * `limit` *(integer, default 3)*: Maximum proposals to fetch.
146
+ * `use_curated_offline` *(boolean, default false)*: If true, returns verified realistic curated proposals without outbound network calls.
147
+ * **Returns:** Proposal IDs, natural language titles, execution targets, calldata payloads, and audit recommendations.
148
+
149
+ #### `preflight_tx_firewall`
150
+ * **Purpose:** Free pre-sign transaction security firewall evaluating EVM transaction risks, calldata decoding, unlimited ERC-20/Permit2/`setApprovalForAll` approvals, EIP-712 typed-data phishing, Indirect Prompt Injection (IPI) in untrusted metadata, and simulated state changes via `eth_call`.
151
+ * **Parameters:**
152
+ * `to_address` *(string, optional)* / `target_address` *(string, optional)*: Target contract or recipient EVM address.
153
+ * `from_address` *(string, optional)*: Optional sender EVM address.
154
+ * `calldata` *(string, default "0x")*: Hex transaction calldata.
155
+ * `value_wei` *(integer, default 0)*: Transaction value in Wei.
156
+ * `chain_id` *(integer, default 8453)*: EVM Chain ID.
157
+ * `eip712_typed_data` *(object, optional)*: EIP-712 typed data payload to inspect before signing.
158
+ * `untrusted_text` *(string, optional)*: Untrusted text or proposal description to scan for Indirect Prompt Injection.
159
+ * `run_simulation` *(boolean, default true)*: Whether to execute `eth_call` simulation on-chain.
160
+ * **Returns:** `verdict` (`ALLOW`, `BLOCK`, `MANUAL_REVIEW`), `risk_score` (0.0 to 10.0), `flagged_issues`, `approval_risks`, `eip712_findings`, `prompt_injection_detected`, `reasons`, and `summary`.
161
+
162
+ #### `inspect_proxy_and_source`
163
+ * **Purpose:** Free EIP-1967 / EIP-1822 / Beacon proxy storage slot inspector and verified Solidity source resolver. Probes on-chain `implementation`, `admin`, `beacon`, `owner()`, and `paused()` states via `AsyncWeb3` and queries Sourcify / Etherscan v2 without invoking any LLM.
164
+ * **Parameters:**
165
+ * `target_address` *(string, required)*: Hex EVM address of smart contract or proxy to inspect.
166
+ * `chain_id` *(integer, default 8453)*: EVM Chain ID (8453, 84532, 42161).
167
+ * `fetch_verified_source` *(boolean, default true)*: Whether to query Sourcify/Etherscan v2 for verified source metadata.
168
+ * `offline_mode` *(boolean, default false)*: If true, returns a deterministic clean offline structure without making RPC or HTTP calls.
169
+ * **Returns:** `is_proxy`, `implementation_address`, `admin_address`, `beacon_address`, `owner_address`, `is_paused`, `source_verified`, `source_provider`, `contract_names`, `security_warnings`, and `recommendation`.
170
+
171
+ ### 2. Paid Stage 2 Tool (1 Tool โ€” x402 USDC)
172
+
173
+ #### `deep_semantic_audit`
174
+ * **Purpose:** Two-stage autonomous security and governance audit. Executes deterministic on-chain gatekeeping followed by structured Google Gemini LLM reasoning crossing natural language claims with actual bytecode, proxy state, verified Solidity source, and calldata reality.
175
+ * **Parameters:**
176
+ * `target_address` *(string, required)*: Hex EVM smart contract address.
177
+ * `proposal_description` *(string, required)*: Natural language claim or governance proposal explanation.
178
+ * `policy_prompt` *(string, optional)*: Security policy or criteria to audit against.
179
+ * `calldata` *(string, default "0x")*: Transaction hex calldata being executed.
180
+ * `chain_id` *(integer, default 8453)*: EVM Chain ID.
181
+ * `risk_threshold` *(number, default 7.0)*: Threshold (0.0 to 10.0) above which intervention is warranted.
182
+ * `resolve_proxy` *(boolean, default false)*: If true, resolves EIP-1967/1822 proxy implementation state.
183
+ * `fetch_verified_source` *(boolean, default false)*: If true, retrieves verified Solidity source code from Sourcify/Etherscan.
184
+ * `x402_payment_header` *(string, optional)*: Base64-encoded EIP-3009 transfer authorization satisfying `$0.015 USDC` (standard) or `$0.25 USDC` (when `resolve_proxy=True` or `fetch_verified_source=True`).
185
+ * **Pricing & Micropayment Flow:**
186
+ * Standard tier: **`$0.015 USDC`** ยท Deep Proxy + Verified Source tier: **`$0.25 USDC`** (EIP-3009 on Base).
187
+ * If invoked without payment credentials, returns a structured HTTP 402 payment challenge with the exact recipient address, amount, and instructions without charging.
188
+ * If `x402_payment_header` is supplied (or `X402_BUYER_PRIVATE_KEY` is configured in the environment), the audit executes immediately and returns a deterministic policy result (`APPROVE`, `MANUAL_REVIEW`, or `REJECT`) with risk scores and flagged issues.
189
+
190
+ ### 3. MCP Resources (4 Resources)
191
+
192
+ | Resource URI | MIME Type | Description |
193
+ | :--- | :--- | :--- |
194
+ | `web3://x402/pricing` | `application/json` | Live x402 USDC pricing tiers (`/token/check`, `/preflight`, `/audit`, `/audit/deep`), payout address, and supported networks |
195
+ | `web3://security/selectors-catalog` | `application/json` | Static catalog of known 4-byte EVM administrative selectors, high-risk keywords, and DEX honeypot/rugpull signatures |
196
+ | `web3://feed/dao-curated-proposals` | `application/json` | Deterministic curated dataset of Snapshot DAO governance proposals with extracted on-chain target contracts and calldata |
197
+ | `web3://feed/recent-audits` | `application/json` | Most recent autonomous contract and governance security evaluations recorded in `AgentStorage` |
198
+
199
+ ### 4. MCP Prompts (3 Prompts)
200
+
201
+ | Prompt Name | Arguments | Workflow |
202
+ | :--- | :--- | :--- |
203
+ | `audit-token-before-swap` | `token_address` *(required)*, `chain_id` *(optional)* | Guided pre-swap ERC-20 check: `check_token_honeypot` -> `scan_contract_selectors` -> `inspect_proxy_and_source` -> conditional `deep_semantic_audit` |
204
+ | `pre-sign-transaction-firewall` | `to_address` *(required)*, `calldata` *(optional)* | Pre-sign security check: `preflight_tx_firewall` + `inspect_proxy_and_source` before signing |
205
+ | `audit-dao-governance-space` | `space_id` *(optional)* | Snapshot DAO governance workflow: `scan_dao_proposals` -> `preflight_tx_firewall` / `inspect_proxy_and_source` -> conditional `deep_semantic_audit` |
206
+
207
+ ---
208
+
209
+ ## ๐Ÿ› ๏ธ MCP Client Configuration & Installation
210
+
211
+ ### One-Command Execution (`uvx` / `pip`)
212
+
213
+ Run the MCP server directly without manual cloning:
214
+
215
+ ```bash
216
+ # Run directly with uvx (Zero manual setup)
217
+ uvx --from git+https://github.com/RafaCoelho33/web3-systemic-agent web3-systemic-agent --dry-run
218
+ ```
219
+
220
+ ### Claude Desktop
221
+
222
+ Add the server to your `claude_desktop_config.json`:
223
+
224
+ * **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
225
+ * **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
226
+
227
+ ```json
228
+ {
229
+ "mcpServers": {
230
+ "web3-systemic-agent": {
231
+ "command": "python",
232
+ "args": ["-m", "src.mcp_server"],
233
+ "cwd": "/path/to/web3-systemic-agent",
234
+ "env": {
235
+ "WEB3_AGENT_URL": "https://web3-systemic-agent.onrender.com",
236
+ "X402_BUYER_PRIVATE_KEY": ""
237
+ }
238
+ }
239
+ }
240
+ }
241
+ ```
242
+
243
+ ### Cursor IDE
244
+
245
+ Create or edit `.cursor/mcp.json` in your project root or user config:
246
+
247
+ ```json
248
+ {
249
+ "mcpServers": {
250
+ "web3-systemic-agent": {
251
+ "command": "python",
252
+ "args": ["-m", "src.mcp_server"],
253
+ "env": {
254
+ "WEB3_AGENT_URL": "https://web3-systemic-agent.onrender.com"
255
+ }
256
+ }
257
+ }
258
+ }
259
+ ```
260
+
261
+ ### Smithery (`smithery.yaml`)
262
+
263
+ Install directly via [Smithery.ai](https://smithery.ai):
264
+
265
+ ```bash
266
+ smithery run web3-systemic-agent
267
+ ```
268
+
269
+ Or reference the local manifest:
270
+ ```yaml
271
+ startCommand:
272
+ type: stdio
273
+ configSchema:
274
+ type: object
275
+ properties:
276
+ web3AgentUrl:
277
+ type: string
278
+ default: "https://web3-systemic-agent.onrender.com"
279
+ x402BuyerPrivateKey:
280
+ type: string
281
+ commandFunction:
282
+ python: "python -m src.mcp_server"
283
+ ```
284
+
285
+ ### Glama (`glama.json`)
286
+
287
+ Verified for the [Glama MCP Directory](https://glama.ai/mcp):
288
+
289
+ ```json
290
+ {
291
+ "$schema": "https://glama.ai/mcp/schemas/server.json",
292
+ "name": "web3-systemic-agent",
293
+ "maintainers": ["RafaCoelho33"],
294
+ "homepage": "https://web3-systemic-agent.onrender.com",
295
+ "repository": "https://github.com/RafaCoelho33/web3-systemic-agent",
296
+ "capabilities": {
297
+ "tools": true,
298
+ "resources": true,
299
+ "prompts": true
300
+ }
301
+ }
302
+ ```
303
+
304
+ ### Coinbase AgentKit / Streamable-HTTP
305
+
306
+ Connect via HTTP streaming to the remote MCP endpoint without local installation:
307
+
308
+ ```python
309
+ import httpx
310
+
311
+ # Ingest tools manifest via Streamable-HTTP
312
+ async with httpx.AsyncClient() as client:
313
+ resp = await client.get("https://web3-systemic-agent.onrender.com/mcp")
314
+ tools = resp.json()["tools"]
315
+ ```
316
+
317
+ ---
318
+
319
+ ## ๐Ÿ›ฐ๏ธ Autonomous Discovery, On-Chain Identity & IDE Integrations (v1.0.2)
320
+
321
+ ### Active Multi-Channel Contract Hunter (`scripts/active_contract_hunter.py`)
322
+
323
+ Autonomous discovery engine (`src/discovery_hunter.py` -> `ActiveContractHunter`) that proactively hunts newly deployed contracts, DEX tokens, and DAO governance payloads across **5 zero-API-key, zero-gas channels** with FIFO deduplication (`2048` cache entries) and deterministic Stage 1->2 triage:
324
+
325
+ 1. **`base_blocks`**: Newly deployed smart contracts on Base Mainnet (`scan_recent_blocks`).
326
+ 2. **`dex_pools`**: Newly created Aerodrome & Uniswap v3 `PoolCreated` pools (`scan_pool_events`).
327
+ 3. **`geckoterminal_base`**: GeckoTerminal public New Pools API (`/api/v2/networks/base/new_pools`).
328
+ 4. **`dexscreener_base`**: DexScreener public Latest Token Profiles API filtered to Base (`chainId == "base"`).
329
+ 5. **`snapshot_daos`**: Active Snapshot DAO governance proposals with extracted on-chain execution targets.
330
+
331
+ ```bash
332
+ # Dry-run offline simulation across all 5 discovery channels
333
+ python scripts/active_contract_hunter.py --dry-run --once
334
+
335
+ # Continuous live multi-channel daemon with webhook alerting
336
+ python scripts/active_contract_hunter.py --continuous --poll-interval 60 --webhook-url https://discord.com/api/webhooks/...
337
+ ```
338
+
339
+ ### ERC-8004 On-Chain Identity (`scripts/register_erc8004_agent.py`)
340
+
341
+ Generates, validates, and ABI-encodes the **ERC-8004 ("Trustless Agents")** registration manifest (`https://eips.ethereum.org/EIPS/eip-8004#registration-v1`) for indexing on Base Mainnet (`8004scan.io` / `8004agents.ai`), including `data:application/json;base64,...` `agentURI` encoding and `register(string)` calldata (`0xf2c298be`):
342
+
343
+ ```bash
344
+ python scripts/register_erc8004_agent.py --dry-run
345
+ ```
346
+
347
+ ### Cursor Rules (`.cursorrules`) & OpenClaw / ClawHub Skill (`integrations/openclaw/SKILL.md`)
348
+
349
+ * **`.cursorrules`**: Drop-in Cursor IDE rule file instructing AI coding assistants to invoke free Stage 1 MCP tools (`preflight_tx_firewall`, `check_token_honeypot`, `scan_contract_selectors`, `inspect_proxy_and_source`, `scan_dao_proposals`) before recommending contract interactions or transaction signatures, escalating to paid `deep_semantic_audit` only on flagged risk.
350
+ * **`integrations/openclaw/SKILL.md`**: Ready-to-publish OpenClaw / ClawHub skill manifest wiring both the Streamable-HTTP/stdio MCP tools and the x402-gated HTTP REST endpoints (`/token/check`, `/preflight`, `/audit`, `/audit/deep`).
351
+
352
+ ---
353
+
354
+ ## ๐Ÿ—๏ธ Two-Stage Architecture & x402 Micropayments
355
+
356
+ ```mermaid
357
+ flowchart TD
358
+ Client["Client / Agent / MCP Tool"] -->|POST /audit, /evaluate or deep_semantic_audit| Gate["x402 Payment Gatekeeper\n(EIP-3009 Gasless USDC)"]
359
+ Gate -->|No / Invalid Payment Header| R402["HTTP 402 Payment Required\n(0.015 USDC -> PAY_TO_ADDRESS)"]
360
+ Gate -->|Valid EIP-3009 Authorization| S1["Stage 1: ChainInspector (AsyncWeb3)\nBytecode Cache + Native Balance + Selectors"]
361
+ S1 -->|Condition Fails| ShortCircuit["Deterministic Short-Circuit\n(llm_invoked=False, LLM Cost = $0.00)"]
362
+ S1 -->|RPC Connectivity Error| Err503["HTTP 503 Unavailable\n(Payment NOT Settled / No Charge)"]
363
+ S1 -->|Condition Passes| S2["Stage 2: GeminiSemanticEvaluator\nStructured JSON Schema + Failover Models"]
364
+ S2 --> Policy["enforce_decision_policy\nDeterministic Escalation: REJECT / MANUAL / APPROVE"]
365
+ ShortCircuit --> Settle["Settle Payment via x402 Facilitator\nLog to SQLite Ledger (data/agent.db)"]
366
+ Policy --> Settle
367
+ Settle --> Resp["HTTP 200 OK: FinalAgentResponse + PaymentReceipt"]
368
+ ```
369
+
370
+ ### Proven Live On-Chain Settlements (Base Mainnet)
371
+
372
+ Real **EIP-3009 (`transferWithAuthorization`)** USDC settlements executed on **Base Mainnet (Chain ID: `8453`)** via the Coinbase CDP x402 Facilitator and indexed in the **x402 Bazaar**:
373
+
374
+ | Endpoint | Settled Amount | Transaction Hash | Status |
375
+ | :--- | :--- | :--- | :--- |
376
+ | `POST /audit` | `0.015 USDC` | [`0x2ee54ab1bf34...`](https://basescan.org/tx/0x2ee54ab1bf344998c4e5f4ebb9b30fa0a3d96accb1be813beefd0863e3e5ccc0) | `Success` (Gasless EIP-3009) |
377
+ | `POST /evaluate` | `0.015 USDC` | [`0xecc0a97196f7...`](https://basescan.org/tx/0xecc0a97196f7f4a27379e266e10bd652bb4672c278f58376d0bc6cd49f5eb0ff) | `Success` (Gasless EIP-3009) |
378
+ | `POST /audit` | `0.05 USDC` | [`0xbcc7ebd3d956...`](https://basescan.org/tx/0xbcc7ebd3d9561f01ae1e190a35509a7a70163c42115cba5588db35c34e0b0f10) | `Success` (Gasless EIP-3009) |
379
+
380
+ ### Proven Live On-Chain Settlements (Base Sepolia)
381
+
382
+ The x402 A2A settlement cycle using **EIP-3009 (`transferWithAuthorization`)** has been verified and settled on **Base Sepolia (Chain ID: `84532`)** with zero gas ETH consumed by the buyer or agent:
383
+
384
+ | Metric | Transaction 1 (Direct Settlement) | Transaction 2 (Live Mempool Capture) | Transaction 3 (Production Render) |
385
+ | :--- | :--- | :--- | :--- |
386
+ | **Transaction Hash** | [`0xa02872819cef...`](https://sepolia.basescan.org/tx/0xa02872819cef168637efe50d917441fd196cd03b4baafc7b9ff3dc624f18fc0d) | [`0x6aa7c671469d...`](https://sepolia.basescan.org/tx/0x6aa7c671469d2d9a2e0a8eb3682d285394795a2da369573214f7eaad6759b647) | [`0x63ea962e6f0d...`](https://sepolia.basescan.org/tx/0x63ea962e6f0d83b73116cfc4f084b6f9495c47fa020f8db703508b5fbd06e6b5) |
387
+ | **Settlement Method** | Direct EIP-3009 call | Live mempool/block scan | `POST https://web3-systemic-agent.onrender.com/evaluate` |
388
+ | **On-Chain Status** | `Success` (Block `54583500`) | `Success` (Block `54644484`) | `Success` |
389
+ | **Agent Wallet (`PAY_TO_ADDRESS`)** | [`0x2b7F1fd931...`](https://sepolia.basescan.org/address/0x2b7F1fd931f7f28f89e0f688Dd5Bb7a620c24b63#tokentxns) | [`0x2b7F1fd931...`](https://sepolia.basescan.org/address/0x2b7F1fd931f7f28f89e0f688Dd5Bb7a620c24b63#tokentxns) | [`0x2b7F1fd931...`](https://sepolia.basescan.org/address/0x2b7F1fd931f7f28f89e0f688Dd5Bb7a620c24b63#tokentxns) |
390
+ | **Buyer Wallet (A2A Agent)** | [`0x4EbC7529d8...`](https://sepolia.basescan.org/address/0x4EbC7529d8c948ed1245A8106F2834969dbCec2b#tokentxns) | [`0x4EbC7529d8...`](https://sepolia.basescan.org/address/0x4EbC7529d8c948ed1245A8106F2834969dbCec2b#tokentxns) | [`0x4EbC7529d8...`](https://sepolia.basescan.org/address/0x4EbC7529d8c948ed1245A8106F2834969dbCec2b#tokentxns) |
391
+ | **x402 Facilitator (Gas Sponsor)** | [`0xd407e409E3...`](https://sepolia.basescan.org/address/0xd407e409E34E0b9afb99EcCeb609bDbcD5e7f1bf) (`https://x402.org/facilitator`) | [`0xd407e409E3...`](https://sepolia.basescan.org/address/0xd407e409E34E0b9afb99EcCeb609bDbcD5e7f1bf) (`https://x402.org/facilitator`) | [`0xd407e409E3...`](https://sepolia.basescan.org/address/0xd407e409E34E0b9afb99EcCeb609bDbcD5e7f1bf) (`https://x402.org/facilitator`) |
392
+ | **USDC Token Contract** | [`0x036CbD5384...`](https://sepolia.basescan.org/token/0x036CbD53842c5426634e7929541eC2318f3dCF7e) | [`0x036CbD5384...`](https://sepolia.basescan.org/token/0x036CbD53842c5426634e7929541eC2318f3dCF7e) | [`0x036CbD5384...`](https://sepolia.basescan.org/token/0x036CbD53842c5426634e7929541eC2318f3dCF7e) |
393
+ | **Settled Amount** | `0.01 USDC` | `0.01 USDC` | `0.05 USDC` |
394
+ | **Gas Cost (Buyer / Server)** | `0.00 ETH` (Gasless EIP-3009) | `0.00 ETH` (Gasless EIP-3009) | `0.00 ETH` (Gasless EIP-3009) |
395
+
396
+ ---
397
+
398
+ ## ๐Ÿ“ Repository Structure
399
+
400
+ ```
401
+ โ”œโ”€โ”€ src/
402
+ โ”‚ โ”œโ”€โ”€ api.py # FastAPI service, x402 middleware, REST, A2A & MCP endpoints
403
+ โ”‚ โ”œโ”€โ”€ mcp_server.py # MCP server (6 tools, 4 resources, 3 prompts โ€” stdio & HTTP)
404
+ โ”‚ โ”œโ”€โ”€ engine.py # ConditionAgentEngine two-stage orchestrator
405
+ โ”‚ โ”œโ”€โ”€ chain_inspector.py # Stage 1 deterministic on-chain gatekeeper with FIFO cache
406
+ โ”‚ โ”œโ”€โ”€ preflight_firewall.py # Pre-sign tx firewall: Permit2, EIP-712, IPI & eth_call sim
407
+ โ”‚ โ”œโ”€โ”€ source_resolver.py # EIP-1967/Beacon proxy resolver & Sourcify/Etherscan lookup
408
+ โ”‚ โ”œโ”€โ”€ discovery_hunter.py # ActiveContractHunter 5-channel autonomous discovery engine
409
+ โ”‚ โ”œโ”€โ”€ semantic_evaluator.py # Stage 2 Gemini/OpenAI LLM evaluator with cooldown failovers
410
+ โ”‚ โ”œโ”€โ”€ schemas.py # Pydantic v2 strict schemas and contracts
411
+ โ”‚ โ”œโ”€โ”€ x402_payment.py # x402 protocol, EIP-3009 signatures, replay defense
412
+ โ”‚ โ”œโ”€โ”€ governance_connector.py # Snapshot GraphQL connector & Discord/Slack dispatcher
413
+ โ”‚ โ”œโ”€โ”€ storage.py # Asynchronous SQLite ledger with automatic secret redaction
414
+ โ”‚ โ”œโ”€โ”€ task_worker.py # In-memory background task worker pool
415
+ โ”‚ โ””โ”€โ”€ report.py # Telemetry CLI reporting token costs, revenue, net profit
416
+ โ”œโ”€โ”€ scripts/
417
+ โ”‚ โ”œโ”€โ”€ active_contract_hunter.py # 5-channel Active Contract Hunter CLI (--dry-run / --continuous)
418
+ โ”‚ โ”œโ”€โ”€ register_erc8004_agent.py # ERC-8004 Trustless Agent manifest & calldata generator
419
+ โ”‚ โ”œโ”€โ”€ block_contract_scanner.py # Autonomous Base Mainnet block deployment scanner
420
+ โ”‚ โ”œโ”€โ”€ dex_pool_monitor.py # Uniswap v3 & Aerodrome pool event monitor & honeypot engine
421
+ โ”‚ โ”œโ”€โ”€ governance_listener.py # Snapshot DAO sentinel bot
422
+ โ”‚ โ”œโ”€โ”€ client_agent_x402.py # Standalone A2A client with real on-chain settlement
423
+ โ”‚ โ””โ”€โ”€ setup_buyer_wallet.py # Wallet generation and USDC balance inspection utility
424
+ โ”œโ”€โ”€ integrations/
425
+ โ”‚ โ””โ”€โ”€ openclaw/SKILL.md # OpenClaw / ClawHub agent skill definition
426
+ โ”œโ”€โ”€ tests/ # Automated unit, security, and integration test suite
427
+ โ”œโ”€โ”€ .cursorrules # Cursor IDE security policy enforcing Stage 1 MCP checks
428
+ โ”œโ”€โ”€ smithery.yaml # Smithery MCP registry manifest
429
+ โ”œโ”€โ”€ glama.json # Glama MCP directory configuration
430
+ โ”œโ”€โ”€ Dockerfile # Production Docker container definition
431
+ โ”œโ”€โ”€ docker-compose.yml # Local containerized orchestration
432
+ โ””โ”€โ”€ .env.example # Environment configuration template
433
+ ```
434
+
435
+ ---
436
+
437
+ ## โšก Quickstart & Setup
438
+
439
+ ### 1. Installation
440
+
441
+ ```bash
442
+ git clone https://github.com/RafaCoelho33/web3-systemic-agent.git
443
+ cd web3-systemic-agent
444
+
445
+ # Install core and development dependencies
446
+ pip install -r requirements-dev.txt
447
+ ```
448
+
449
+ ### 2. Configuration (`.env`)
450
+
451
+ Copy the template and provide your API keys:
452
+
453
+ ```bash
454
+ cp .env.example .env
455
+ ```
456
+
457
+ Key environment variables:
458
+ ```env
459
+ # Server
460
+ PORT=8000
461
+ PUBLIC_EVALUATE_ONLY=true
462
+
463
+ # Google Gemini API
464
+ GEMINI_API_KEY=your_gemini_api_key_here
465
+ GEMINI_MODEL=gemini-3.5-flash-lite
466
+ GEMINI_FAILOVER_MODELS=gemini-3.5-flash-lite,gemini-3.1-flash-lite,gemini-2.5-flash-lite,gemini-2.0-flash
467
+
468
+ # x402 Micropayment Protocol
469
+ PAY_TO_ADDRESS=0x2b7F1fd931f7f28f89e0f688Dd5Bb7a620c24b63
470
+ X402_ENABLED=true
471
+ X402_NETWORK=eip155:8453
472
+ X402_PRICE_EVALUATE=0.015
473
+ X402_USE_LIVE_FACILITATOR=true
474
+ ```
475
+
476
+ ### 3. Verify MCP Server Offline
477
+
478
+ ```bash
479
+ python src/mcp_server.py --dry-run
480
+ ```
481
+
482
+ Expected output:
483
+ ```
484
+ === Web3 Systemic Agent MCP Server Self-Test ===
485
+ [1/9] Registered 6 MCP tools: scan_contract_selectors, check_token_honeypot, scan_dao_proposals, deep_semantic_audit, preflight_tx_firewall, inspect_proxy_and_source
486
+ [2/9] Tool 'scan_contract_selectors' OK: risk_level=LOW, selectors=1, cost=$0.00
487
+ [3/9] Tool 'check_token_honeypot' OK: is_honeypot=True, score=7.5, cost=$0.00
488
+ [4/9] Tool 'scan_dao_proposals' OK: count=1, cost=$0.00
489
+ [5/9] Tool 'preflight_tx_firewall' OK: verdict=MANUAL_REVIEW, risk_score=7.5, cost=$0.00
490
+ [6/9] Tool 'inspect_proxy_and_source' OK: is_proxy=False, source_verified=False, cost=$0.00
491
+ [7/9] Tool 'deep_semantic_audit' OK: status=payment_required, status_code=402, price_usdc=0.05
492
+ [8/9] MCP resources/list & resources/read OK: 4 resources verified
493
+ [9/9] MCP prompts/list & prompts/get OK: 3 prompts verified
494
+ === All MCP self-tests PASSED successfully ===
495
+ ```
496
+
497
+ ### 4. Run the Full Test Suite
498
+
499
+ ```bash
500
+ pytest
501
+ ```
502
+
503
+ ---
504
+
505
+ ## ๐Ÿ“œ License
506
+
507
+ This project is licensed under the **[Apache License 2.0](LICENSE)** (`SPDX-License-Identifier: Apache-2.0`).
508
+
509
+ * **Copyright:** Copyright (c) 2026 [RafaCoelho33](https://github.com/RafaCoelho33). All rights reserved under Apache-2.0 terms (including trademark protection under Section 6 and mandatory attribution under Section 4).
510
+
511
+ <!-- mcp-name: io.github.RafaCoelho33/web3-systemic-agent -->
@@ -0,0 +1,29 @@
1
+ scripts/active_contract_hunter.py,sha256=Q-RA8XCppJGKFeNe8BDA72EqsLAF_dQstiGlafqXmwE,9318
2
+ scripts/block_contract_scanner.py,sha256=FQY8fwM7HMG39u2Y9kzjkQb8FJkB9u7c9Yoj9tr5qvk,31561
3
+ scripts/client_agent_x402.py,sha256=o9HBojD-aAfFqQ56qFcTf-ih72YhJA6ccJLOWRi5OGI,26364
4
+ scripts/dex_pool_monitor.py,sha256=ruCTErCQwn9Dw1U5t9IhkZbgXCzm2qLNWgHxKJsq-vo,53429
5
+ scripts/governance_daemon.py,sha256=qt3Zgej1AMlCHYTqNZ91-ujd2d6xobjcKX66nQ14BxQ,28461
6
+ scripts/governance_listener.py,sha256=zU_M9q3G2zKeUHkM015qSRxZMfZYJnn8a1DQidtpzSg,6858
7
+ scripts/register_erc8004_agent.py,sha256=tSm7lWvEBYwmesMhx67EV6nGnOn2LHFlbtTjkw7zVeg,11403
8
+ scripts/setup_buyer_wallet.py,sha256=U9Emk22OoNYD40AIeTIfpQ275XtYFvbIDovdfdsUxmQ,6585
9
+ src/api.py,sha256=rfaC_QH3mSg2k07SAYjlyl6sMafVf0kqCGv3FBsrvyg,220272
10
+ src/chain_inspector.py,sha256=1mKn4-Erv-xLBbQdeJBJ8eIDdcx-7hyvjb3Lze3mUJk,10112
11
+ src/discovery_hunter.py,sha256=rqK0yq3GUNVdbWGpcfh0nyVn7uUefmRhroauL86MurY,38159
12
+ src/engine.py,sha256=FcUfNXktj0xRQ3r5UoETflMQmyA5VcxstXvaLnOvACA,10543
13
+ src/governance_connector.py,sha256=UZqb2T_XEPbOltPI2NFeL-bATdjvqgNIZzSqQv-fyiU,21102
14
+ src/mcp_server.py,sha256=7w5ulpu29qsGipiJgkXQQCFtuls7L4z8ungVkzYeAKM,90958
15
+ src/preflight_firewall.py,sha256=YApF1hjnPai3wlV3XZSj1UUl6nwZJlw9_4ZgVJzHvj0,24098
16
+ src/report.py,sha256=5QU8lF6f1s6fckAlwAwlFrOtfzrMnhYXwWkYj8kKmS8,5232
17
+ src/schemas.py,sha256=3mM2BGRXGR6CrgR2WkSc8llUCKtDOtp2vGbKRp10FkA,15335
18
+ src/semantic_evaluator.py,sha256=m8FLzsJWdvGowqBxvqeBrwSM0yCyttwZhHongLdk050,40107
19
+ src/source_resolver.py,sha256=PfOtDUE8WAQUUgpBPgujJuet2IYdQo34KbaPwVGt4SM,33566
20
+ src/storage.py,sha256=qxpI3LX9JCq76vqCGtBEgRskGI6ibe7mLFh0qo7qIrs,35000
21
+ src/task_worker.py,sha256=nvMurlYzKr9jc3xHuotRu-lJno3BqLhkO7p_C8Ze8A4,11313
22
+ src/test_cache_and_telemetry.py,sha256=esf1k3Y00uB94oZfL4akCMbJpspNZR1iXD6isLJtm9c,19380
23
+ src/x402_payment.py,sha256=0eqmkzOHbyDD1-aErk5j7RDmnN4jeGK6Zyz2_FpzNe8,62657
24
+ web3_systemic_agent-1.0.2.dist-info/licenses/LICENSE,sha256=F_qXYpwxZBKUUtKEUyXODigsKyPPSQALP5JKtVACcxI,11342
25
+ web3_systemic_agent-1.0.2.dist-info/METADATA,sha256=o23OpOszQSz_HVIfmEazqcRGradtLLpdmugQyNof4WE,32331
26
+ web3_systemic_agent-1.0.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
27
+ web3_systemic_agent-1.0.2.dist-info/entry_points.txt,sha256=lEs4d0yuqlR8fEmv6B7PGJIwSU0prPlt3f0IVnm-9uA,106
28
+ web3_systemic_agent-1.0.2.dist-info/top_level.txt,sha256=2u1B708VEAisYx1t_BY-Ya_-RVnGzeibiEH429s02AM,12
29
+ web3_systemic_agent-1.0.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ web3-systemic-agent = src.mcp_server:main
3
+ web3-systemic-agent-mcp = src.mcp_server:main