search_crypto
Search for cryptocurrencies by name or symbol to identify and retrieve market data for trading and portfolio management.
Instructions
Searches for cryptocurrencies by name or symbol.
Args:
query: Search term (e.g., 'bitcoin', 'BTC', 'ethereum')
Returns:
Formatted string with search results
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Implementation Reference
- tools/crypto_data.py:122-151 (handler)The handler function for the 'search_crypto' tool. It uses the CoinGecko API to search for cryptocurrencies matching the input query and returns a formatted string with the top 10 results including name, symbol, ID, and market cap rank.def search_crypto(query: str) -> str: """ Searches for cryptocurrencies by name or symbol. Args: query: Search term (e.g., 'bitcoin', 'BTC', 'ethereum') Returns: Formatted string with search results """ try: data = cg.search(query=query) coins = data.get('coins', []) if not coins: return f"No results found for '{query}'" summary = [f"=== SEARCH RESULTS FOR '{query}' ===\n"] for coin in coins[:10]: summary.append( f"β’ {coin.get('name')} ({coin.get('symbol', 'N/A').upper()})" f" - ID: {coin.get('id')} - Rank #{coin.get('market_cap_rank', 'N/A')}" ) summary.append("\nUse the 'id' with get_crypto_market_data() for detailed info") return "\n".join(summary) except Exception as e: logger.error(f"CoinGecko search error: {e}") return f"Error searching for '{query}': {str(e)}"
- server.py:415-418 (registration)Registers 'search_crypto' as an MCP tool in the server.py file, along with other cryptocurrency tools, using the register_tools helper function.register_tools( [get_crypto_price, get_crypto_market_data, get_trending_crypto, search_crypto], "Cryptocurrency" )
- server.py:21-21 (registration)Import statement for the search_crypto function in server.py, necessary for its registration.from tools.crypto_data import get_crypto_price, get_crypto_market_data, get_trending_crypto, search_crypto