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.py
using the@mcp.tool()
decorator - Use the
DefiLlamaClient
class inclient.py
for API interactions - 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
- 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.