defillama-mcp

jayeshchowdary/defillama-mcp

3.2

If you are the rightful owner of defillama-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The DefiLlama MCP Server is a high-performance server designed for seamless integration with the DefiLlama API, utilizing FastMCP and managed with uv for efficient package management.

DefiLlama MCP Server

A custom Model Context Protocol (MCP) server for DefiLlama API integration, built with FastMCP and managed with uv.

Features

  • šŸš€ Built with FastMCP for high-performance MCP server implementation
  • šŸ“¦ Package management with uv for fast dependency resolution
  • šŸ”§ Clean, modular architecture ready for tool expansion
  • šŸ›”ļø Type-safe with Pydantic models
  • šŸ“ Comprehensive logging and error handling

Project Structure

defillama-mcp/
ā”œā”€ā”€ src/
│   └── defillama_mcp/
│       ā”œā”€ā”€ __init__.py
│       ā”œā”€ā”€ server.py          # Main MCP server implementation
│       ā”œā”€ā”€ config.py          # Configuration settings
│       └── client.py          # DefiLlama API client
ā”œā”€ā”€ tests/                     # Test files (to be added)
ā”œā”€ā”€ pyproject.toml            # Project configuration and dependencies
└── README.md

Prerequisites

  • Python 3.10 or higher
  • uv package manager

Installation

  1. Install uv (if not already installed):

    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  2. Clone and navigate to the project:

    cd defillama-mcp
    
  3. Install dependencies:

    uv sync
    

Usage

Running the MCP Server

# Activate the virtual environment
uv run python -m defillama_mcp.server

# Or run directly with uv
uv run src/defillama_mcp/server.py

Development

# Install development dependencies
uv sync --dev

# Run tests (when implemented)
uv run pytest

# Format code
uv run black src/
uv run isort src/

# Lint code
uv run flake8 src/

Configuration

The server can be configured through environment variables or a .env file:

# DefiLlama API settings
DEFILLAMA_API_BASE_URL=https://api.llama.fi
DEFILLAMA_API_TIMEOUT=30

# Server settings
SERVER_NAME=DefiLlama MCP Server
SERVER_VERSION=0.1.0
LOG_LEVEL=INFO

# Optional API key
API_KEY=your_api_key_here

Adding Tools

This foundational structure is designed to be extended with DefiLlama API tools. To add new tools:

  1. Create tool functions in server.py using the @mcp.tool() decorator
  2. Use the DefiLlamaClient class in client.py for API interactions
  3. Update the get_server_info tool to reflect the number of available tools

Example tool structure:

@mcp.tool()
async def get_protocol_tvl(protocol: str) -> Dict[str, Any]:
    """Get TVL data for a specific protocol."""
    async with DefiLlamaClient() as client:
        data = await client.get(f"/tvl/{protocol}")
        return data

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For issues and questions, please open an issue on the GitHub repository.