"""
Expanded MCP Catalog — Free Open-Source Tools from GitHub
============================================================
Wires free, MIT/Apache-licensed MCPs we cloned from GitHub into the
x402 tool catalog. These tools are NOT redundant with our 221 native
tools. Each entry includes:
  - Tool ID (dot-notation: <service>.<tool>)
  - Description (user-facing)
  - Pricing (USD + atomic units for x402)
  - Category
  - Service identifier
  - Source repo
  - License

All tools are wrapped by the caching shield — calls are L1+L2 cached,
rate-limited, and run via stdio against the local clone. We retool
free data into $0.01-0.40/call agent-callable endpoints.
"""

# ════════════════════════════════════════════════════════════
# 1. Crypto Fear & Greed Index (kukapay/crypto-feargreed-mcp)
#    Source: Alternative.me public API (free, no key)
#    License: MIT
# ════════════════════════════════════════════════════════════

FEAR_GREED_TOOLS = [
    {
        "id": "sentiment.fear_greed_current",
        "name": "Fear & Greed Index — Current",
        "description": "Real-time Crypto Fear & Greed Index (0-100). Reads market sentiment: 0-24 extreme fear, 25-49 fear, 50 neutral, 51-74 greed, 75-100 extreme greed. Free Alternative.me API.",
        "category": "sentiment",
        "service": "fear-greed-mcp",
        "source_repo": "https://github.com/kukapay/crypto-feargreed-mcp",
        "license": "MIT",
        "price_usd": 0.01,
        "price_atoms": "10000",
        "trial_free": 5,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "get_current_fng_tool",
        "method": "MCP",
    },
    {
        "id": "sentiment.fear_greed_history",
        "name": "Fear & Greed Index — Historical",
        "description": "Historical Crypto Fear & Greed Index over N days. Returns daily values + classification. Trend analysis included (rising/falling/stable + average). Free Alternative.me API.",
        "category": "sentiment",
        "service": "fear-greed-mcp",
        "source_repo": "https://github.com/kukapay/crypto-feargreed-mcp",
        "license": "MIT",
        "price_usd": 0.02,
        "price_atoms": "20000",
        "trial_free": 3,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "get_historical_fng_tool",
        "params": ["days"],
        "method": "MCP",
    },
    {
        "id": "sentiment.fear_greed_trend",
        "name": "Fear & Greed Index — Trend Analysis",
        "description": "Analyze N-day trend in Crypto Fear & Greed Index. Returns latest value, average, direction (rising/falling/stable), and statistical breakdown. Free Alternative.me API.",
        "category": "sentiment",
        "service": "fear-greed-mcp",
        "source_repo": "https://github.com/kukapay/crypto-feargreed-mcp",
        "license": "MIT",
        "price_usd": 0.03,
        "price_atoms": "30000",
        "trial_free": 3,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "analyze_fng_trend",
        "params": ["days"],
        "method": "MCP",
    },
]


# ════════════════════════════════════════════════════════════
# 2. Crypto Technical Indicators (kukapay/crypto-indicators-mcp)
#    Source: Local computation, no API key
#    License: MIT
#    50+ indicators — exposed as 4 high-value bundled endpoints
#    + an "any indicator" lookup
# ════════════════════════════════════════════════════════════

CRYPTO_INDICATORS_TOOLS = [
    {
        "id": "analysis.ta_momentum",
        "name": "TA — Momentum Indicators",
        "description": "Momentum oscillators: RSI, MACD, Stochastic, Williams %R, ROC, Awesome Oscillator, CCI, MFI, KDJ. 12+ indicators in one call. Input: symbol/chain/interval. Returns computed values + overbought/oversold signals.",
        "category": "analysis",
        "service": "crypto-indicators-mcp",
        "source_repo": "https://github.com/kukapay/crypto-indicators-mcp",
        "license": "MIT",
        "price_usd": 0.05,
        "price_atoms": "50000",
        "trial_free": 3,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "rsi,macd,stochastic,williams_r,roc,awesome_oscillator,cci,mfi,kdj",
        "params": ["symbol", "chain", "interval"],
        "method": "MCP",
    },
    {
        "id": "analysis.ta_trend",
        "name": "TA — Trend Indicators",
        "description": "Trend following: SMA, EMA, DEMA, TEMA, TMA, WMA, VWMA, Rolling MA, MACD, Aroon, Parabolic SAR, Ichimoku Cloud, Qstick. 14+ indicators in one call.",
        "category": "analysis",
        "service": "crypto-indicators-mcp",
        "source_repo": "https://github.com/kukapay/crypto-indicators-mcp",
        "license": "MIT",
        "price_usd": 0.05,
        "price_atoms": "50000",
        "trial_free": 3,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "sma,ema,dema,tema,tma,wma,vwma,aroon,parabolic_sar,ichimoku",
        "params": ["symbol", "chain", "interval"],
        "method": "MCP",
    },
    {
        "id": "analysis.ta_volatility",
        "name": "TA — Volatility Indicators",
        "description": "Volatility bands & ranges: Bollinger Bands (and width), Donchian, Keltner, ATR, Chandelier Exit, True Range, Acceleration Bands, Ulcer Index, Moving Std Dev. 9+ indicators in one call.",
        "category": "analysis",
        "service": "crypto-indicators-mcp",
        "source_repo": "https://github.com/kukapay/crypto-indicators-mcp",
        "license": "MIT",
        "price_usd": 0.05,
        "price_atoms": "50000",
        "trial_free": 3,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "bollinger_bands,donchian,keltner,atr,chandelier,acceleration_bands,ulcer_index",
        "params": ["symbol", "chain", "interval"],
        "method": "MCP",
    },
    {
        "id": "analysis.ta_volume",
        "name": "TA — Volume Indicators",
        "description": "Volume analysis: OBV, VWAP, Chaikin Money Flow, Force Index, ADL, Ease of Movement, Negative Volume Index, Volume Price Trend, PVT, MFI. 10+ indicators in one call.",
        "category": "analysis",
        "service": "crypto-indicators-mcp",
        "source_repo": "https://github.com/kukapay/crypto-indicators-mcp",
        "license": "MIT",
        "price_usd": 0.05,
        "price_atoms": "50000",
        "trial_free": 3,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "obv,vwap,chaikin_money_flow,force_index,adl,ease_of_movement,nvi,pvt",
        "params": ["symbol", "chain", "interval"],
        "method": "MCP",
    },
    {
        "id": "analysis.ta_single",
        "name": "TA — Single Indicator Lookup",
        "description": "Run any single TA indicator by name. Returns raw computed value. Use when you need one specific indicator (e.g. just RSI, or just MACD). 50+ indicators available — see description for list.",
        "category": "analysis",
        "service": "crypto-indicators-mcp",
        "source_repo": "https://github.com/kukapay/crypto-indicators-mcp",
        "license": "MIT",
        "price_usd": 0.01,
        "price_atoms": "10000",
        "trial_free": 5,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "<indicator_name>",
        "params": ["indicator", "symbol", "chain", "interval"],
        "method": "MCP",
        "indicators_available": [
            "rsi",
            "macd",
            "stochastic",
            "williams_r",
            "roc",
            "awesome_oscillator",
            "cci",
            "mfi",
            "kdj",
            "sma",
            "ema",
            "dema",
            "tema",
            "tma",
            "wma",
            "vwma",
            "rolling_ma",
            "aroon",
            "parabolic_sar",
            "ichimoku",
            "qstick",
            "bollinger_bands",
            "bollinger_bands_width",
            "donchian",
            "keltner",
            "atr",
            "chandelier_exit",
            "true_range",
            "acceleration_bands",
            "ulcer_index",
            "moving_std_dev",
            "obv",
            "vwap",
            "chaikin_money_flow",
            "force_index",
            "adl",
            "ease_of_movement",
            "nvi",
            "pvt",
            "balance_of_power",
            "chande_forecast_oscillator",
            "mass_index",
            "moving_max",
            "moving_min",
            "moving_sum",
            "since_change",
            "triple_exponential_average",
            "triangular_moving_average",
            "typical_price",
            "vortex",
            "projection_oscillator",
            "percentage_price_oscillator",
            "percentage_volume_oscillator",
            "price_rate_of_change",
            "relative_strength_index",
        ],
    },
]


# ════════════════════════════════════════════════════════════
# 3. OpenZeppelin Contracts Wizard (OpenZeppelin/contracts-wizard)
#    Source: OpenZeppelin audited library
#    License: AGPL-3.0
#    Generates secure smart contract source code
# ════════════════════════════════════════════════════════════

CONTRACTS_WIZARD_TOOLS = [
    {
        "id": "security.generate_erc20",
        "name": "Generate ERC20 Contract (Solidity)",
        "description": "Generate secure ERC20 token source code using OpenZeppelin audited libraries. Returns ready-to-deploy .sol file. Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.20,
        "price_atoms": "200000",
        "trial_free": 3,
        "chains": ["ETHEREUM", "BASE", "BSC", "POLYGON", "ARBITRUM", "OPTIMISM", "AVALANCHE"],
        "underlying": "solidity-erc20",
        "params": ["name", "symbol", "decimals", "features"],
        "method": "MCP",
    },
    {
        "id": "security.generate_erc721",
        "name": "Generate ERC721 NFT Contract (Solidity)",
        "description": "Generate secure ERC721 NFT source code using OpenZeppelin audited libraries. Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.20,
        "price_atoms": "200000",
        "trial_free": 3,
        "chains": ["ETHEREUM", "BASE", "BSC", "POLYGON", "ARBITRUM", "OPTIMISM"],
        "underlying": "solidity-erc721",
        "params": ["name", "symbol", "features"],
        "method": "MCP",
    },
    {
        "id": "security.generate_erc1155",
        "name": "Generate ERC1155 Multi-Token Contract (Solidity)",
        "description": "Generate secure ERC1155 multi-token source code. Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.20,
        "price_atoms": "200000",
        "trial_free": 3,
        "chains": ["ETHEREUM", "BASE", "BSC", "POLYGON", "ARBITRUM"],
        "underlying": "solidity-erc1155",
        "params": ["features"],
        "method": "MCP",
    },
    {
        "id": "security.generate_stablecoin",
        "name": "Generate Stablecoin Contract (Solidity)",
        "description": "Generate audited stablecoin source code (RWA-compatible, with mint/burn/access control). Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.30,
        "price_atoms": "300000",
        "trial_free": 2,
        "chains": ["ETHEREUM", "BASE", "BSC", "POLYGON", "ARBITRUM"],
        "underlying": "solidity-stablecoin",
        "params": ["name", "symbol", "features"],
        "method": "MCP",
    },
    {
        "id": "security.generate_governor",
        "name": "Generate Governor/DAO Contract (Solidity)",
        "description": "Generate audited Governor (DAO) contract with voting, timelock, proposal lifecycle. Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.25,
        "price_atoms": "250000",
        "trial_free": 2,
        "chains": ["ETHEREUM", "BASE", "BSC", "POLYGON", "OPTIMISM"],
        "underlying": "solidity-governor",
        "params": ["name", "voting_delay", "voting_period", "quorum"],
        "method": "MCP",
    },
    {
        "id": "security.generate_account",
        "name": "Generate Smart Account Contract (Solidity)",
        "description": "Generate ERC-4337 smart account (account abstraction) source code. Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.25,
        "price_atoms": "250000",
        "trial_free": 2,
        "chains": ["ETHEREUM", "BASE", "BSC", "POLYGON", "OPTIMISM", "ARBITRUM"],
        "underlying": "solidity-account",
        "params": ["features"],
        "method": "MCP",
    },
    {
        "id": "security.generate_rwa",
        "name": "Generate RWA Token Contract (Solidity)",
        "description": "Generate Real World Asset token contract (compliant, with access control). Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.30,
        "price_atoms": "300000",
        "trial_free": 2,
        "chains": ["ETHEREUM", "BASE", "BSC", "POLYGON", "ARBITRUM"],
        "underlying": "solidity-rwa",
        "params": ["name", "symbol", "features"],
        "method": "MCP",
    },
    {
        "id": "security.generate_cairo_erc20",
        "name": "Generate Cairo ERC20 (Starknet)",
        "description": "Generate audited Cairo ERC20 for Starknet. Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.20,
        "price_atoms": "200000",
        "trial_free": 3,
        "chains": ["STARKNET"],
        "underlying": "cairo-erc20",
        "params": ["name", "symbol", "decimals"],
        "method": "MCP",
    },
    {
        "id": "security.generate_stylus_erc20",
        "name": "Generate Stylus ERC20 (Arbitrum Rust)",
        "description": "Generate audited Rust-based ERC20 for Arbitrum Stylus. Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.20,
        "price_atoms": "200000",
        "trial_free": 3,
        "chains": ["ARBITRUM"],
        "underlying": "stylus-erc20",
        "params": ["name", "symbol", "decimals"],
        "method": "MCP",
    },
    {
        "id": "security.generate_uniswap_hook",
        "name": "Generate Uniswap v4 Hook (Solidity)",
        "description": "Generate audited Uniswap v4 hook contract. Free. License: AGPL-3.0.",
        "category": "security",
        "service": "openzeppelin-wizard",
        "source_repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "price_usd": 0.30,
        "price_atoms": "300000",
        "trial_free": 2,
        "chains": ["ETHEREUM", "BASE", "ARBITRUM", "OPTIMISM", "POLYGON"],
        "underlying": "uniswap-hooks",
        "params": ["hook_type", "features"],
        "method": "MCP",
    },
]


# ════════════════════════════════════════════════════════════
# 4. Web3 Research MCP (aaronjmars/web3-research-mcp)
#    Source: CoinGecko + DefiLlama + web search
#    License: MIT
#    Free, fully local — uses Bright Data via env var
# ════════════════════════════════════════════════════════════

WEB3_RESEARCH_TOOLS = [
    {
        "id": "research.search_web",
        "name": "Web3 Research — Web Search",
        "description": "Search the web for crypto research with query. Returns top 5 results, type-filtered (web/news/images/videos). Free local index. Free, MIT licensed.",
        "category": "research",
        "service": "web3-research-mcp",
        "source_repo": "https://github.com/aaronjmars/web3-research-mcp",
        "license": "MIT",
        "price_usd": 0.05,
        "price_atoms": "50000",
        "trial_free": 3,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "search",
        "params": ["query", "search_type"],
        "method": "MCP",
    },
    {
        "id": "research.coingecko_search",
        "name": "CoinGecko — Search Tokens",
        "description": "Search CoinGecko for tokens by name/symbol. Returns id, name, symbol, market_cap_rank, image. Free public CoinGecko API.",
        "category": "research",
        "service": "web3-research-mcp",
        "source_repo": "https://github.com/aaronjmars/web3-research-mcp",
        "license": "MIT",
        "price_usd": 0.01,
        "price_atoms": "10000",
        "trial_free": 5,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC", "POLYGON", "ARBITRUM"],
        "underlying": "coingecko_search",
        "params": ["query"],
        "method": "MCP",
    },
    {
        "id": "research.coingecko_tickers",
        "name": "CoinGecko — Exchange Tickers",
        "description": "Get exchange tickers for a coin (price across CEXs/DEXs, volume, trust score). Free public CoinGecko API.",
        "category": "research",
        "service": "web3-research-mcp",
        "source_repo": "https://github.com/aaronjmars/web3-research-mcp",
        "license": "MIT",
        "price_usd": 0.02,
        "price_atoms": "20000",
        "trial_free": 3,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC", "POLYGON", "ARBITRUM"],
        "underlying": "coingecko_tickers",
        "params": ["coin_id"],
        "method": "MCP",
    },
    {
        "id": "research.defillama_protocols",
        "name": "DefiLlama — List Protocols",
        "description": "List all DeFi protocols tracked by DefiLlama. Free public API. Returns name, slug, TVL, chain, category.",
        "category": "research",
        "service": "web3-research-mcp",
        "source_repo": "https://github.com/aaronjmars/web3-research-mcp",
        "license": "MIT",
        "price_usd": 0.02,
        "price_atoms": "20000",
        "trial_free": 3,
        "chains": [
            "ETHEREUM",
            "BASE",
            "BSC",
            "POLYGON",
            "ARBITRUM",
            "OPTIMISM",
            "AVALANCHE",
            "FANTOM",
            "GNOSIS",
        ],
        "underlying": "defillama_protocols",
        "method": "MCP",
    },
    {
        "id": "research.defillama_protocol",
        "name": "DefiLlama — Protocol Details",
        "description": "Get detailed DeFi protocol info: TVL by chain, audit links, raises, investors, market cap. Free public DefiLlama API.",
        "category": "research",
        "service": "web3-research-mcp",
        "source_repo": "https://github.com/aaronjmars/web3-research-mcp",
        "license": "MIT",
        "price_usd": 0.03,
        "price_atoms": "30000",
        "trial_free": 3,
        "chains": ["ETHEREUM", "BASE", "BSC", "POLYGON", "ARBITRUM", "OPTIMISM", "AVALANCHE"],
        "underlying": "defillama_protocol",
        "params": ["slug"],
        "method": "MCP",
    },
    {
        "id": "research.defillama_fees",
        "name": "DefiLlama — Protocol Fees",
        "description": "Get protocol fees summary: 24h, 7d, 30d, all-time + change deltas. Free public DefiLlama API.",
        "category": "research",
        "service": "web3-research-mcp",
        "source_repo": "https://github.com/aaronjmars/web3-research-mcp",
        "license": "MIT",
        "price_usd": 0.02,
        "price_atoms": "20000",
        "trial_free": 3,
        "chains": ["ETHEREUM", "BASE", "BSC", "POLYGON", "ARBITRUM", "OPTIMISM", "AVALANCHE"],
        "underlying": "defillama_fees",
        "params": ["slug"],
        "method": "MCP",
    },
    {
        "id": "research.fetch_content",
        "name": "Web3 Research — Fetch URL",
        "description": "Fetch and return markdown content from any URL. Use for reading docs, blog posts, or papers. Free, MIT licensed.",
        "category": "research",
        "service": "web3-research-mcp",
        "source_repo": "https://github.com/aaronjmars/web3-research-mcp",
        "license": "MIT",
        "price_usd": 0.05,
        "price_atoms": "50000",
        "trial_free": 3,
        "chains": ["SOLANA", "ETHEREUM", "BASE", "BSC"],
        "underlying": "fetch_content",
        "params": ["url"],
        "method": "MCP",
    },
]


# ════════════════════════════════════════════════════════════
# Master list — all expanded MCP tools
# ════════════════════════════════════════════════════════════

EXTERNAL_MCP_TOOLS = FEAR_GREED_TOOLS + CRYPTO_INDICATORS_TOOLS + CONTRACTS_WIZARD_TOOLS + WEB3_RESEARCH_TOOLS


# ════════════════════════════════════════════════════════════
# Service-level metadata for the catalog UI
# ════════════════════════════════════════════════════════════

EXTERNAL_MCP_SERVICES = [
    {
        "id": "fear-greed-mcp",
        "name": "Crypto Fear & Greed Index",
        "repo": "https://github.com/kukapay/crypto-feargreed-mcp",
        "license": "MIT",
        "description": "Real-time and historical crypto market sentiment",
        "icon": "📊",
        "tools_count": len(FEAR_GREED_TOOLS),
        "free": True,
        "local_clone": "/root/.hermes/mcp-servers/crypto-feargreed-mcp",
    },
    {
        "id": "crypto-indicators-mcp",
        "name": "Technical Analysis Indicators",
        "repo": "https://github.com/kukapay/crypto-indicators-mcp",
        "license": "MIT",
        "description": "50+ technical indicators: momentum, trend, volatility, volume",
        "icon": "📈",
        "tools_count": len(CRYPTO_INDICATORS_TOOLS),
        "free": True,
        "local_clone": "/root/.hermes/mcp-servers/crypto-indicators-mcp",
    },
    {
        "id": "openzeppelin-wizard",
        "name": "OpenZeppelin Contracts Wizard",
        "repo": "https://github.com/OpenZeppelin/contracts-wizard",
        "license": "AGPL-3.0",
        "description": "Generate secure smart contracts from OpenZeppelin audited libraries",
        "icon": "🔒",
        "tools_count": len(CONTRACTS_WIZARD_TOOLS),
        "free": True,
        "local_clone": "/root/.hermes/mcp-servers/contracts-wizard",
    },
    {
        "id": "web3-research-mcp",
        "name": "Web3 Research",
        "repo": "https://github.com/aaronjmars/web3-research-mcp",
        "license": "MIT",
        "description": "Free local research: web search, CoinGecko, DefiLlama, URL fetcher",
        "icon": "🔬",
        "tools_count": len(WEB3_RESEARCH_TOOLS),
        "free": True,
        "local_clone": "/root/.hermes/mcp-servers/web3-research-mcp",
    },
]


if __name__ == "__main__":
    logger.info(f"Total external MCP tools: {len(EXTERNAL_MCP_TOOLS)}")
    logger.info(f"Services: {len(EXTERNAL_MCP_SERVICES)}")
    logger.info()
    for svc in EXTERNAL_MCP_SERVICES:
        logger.info(f"  {svc['icon']} {svc['name']}: {svc['tools_count']} tools ({svc['license']})")
