jayeshchowdary/defillama-mcp
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
-
Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh -
Clone and navigate to the project:
cd defillama-mcp -
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:
- Create tool functions in
server.pyusing the@mcp.tool()decorator - Use the
DefiLlamaClientclass inclient.pyfor API interactions - Update the
get_server_infotool 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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- 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.