๐ Django Firebase MCP
Django Firebase MCP is a comprehensive Django app that implements the Firebase Model Context Protocol (MCP) server. It enables AI agents to interact with Firebase services through a standardized protocol, enhancing the efficiency and flexibility of AI - Firebase integration.
๐ Quick Start
You can get up and running in under 5 minutes with the standalone Firebase agent for testing.
Prerequisites
- Python 3.11+
- A Firebase project with Admin SDK
- Git (optional)
- Redis (optional, for persistent state management)
1. Clone & Setup
git clone https://github.com/your-repo/django-firebase-mcp.git
cd django-firebase-mcp
2. Install Dependencies
pip install -r requirements.txt
3. Firebase Setup
Get Firebase Credentials
- Go to Firebase Console
- Select your project (or create a new one)
- Navigate to Project Settings โ Service Accounts
- Click "Generate new private key"
- Download the JSON file and save it as
credentials.json in the project root
Enable Firebase Services
Make sure these services are enabled in your Firebase project:
- Authentication (for user management)
- Firestore Database (for document storage)
- Cloud Storage (for file uploads)
4. Environment Configuration
Create a .env file in the project root:
# Firebase Configuration
SERVICE_ACCOUNT_KEY_PATH=credentials.json
FIREBASE_STORAGE_BUCKET=your-project-id.appspot.com
# MCP Configuration
MCP_TRANSPORT=http
MCP_HOST=127.0.0.1
MCP_PORT=8001
# Django Settings
DEBUG=True
SECRET_KEY=your-secret-key-here
โ ๏ธ Important Note
Replace your-project-id with your actual Firebase project ID.
5. State Management Setup
The Firebase MCP agent uses state management for conversation persistence. You can choose one option:
Option A: Redis (Recommended for Production)
Install and run Redis on port 6379:
choco install redis-64
redis-server
Add to your .env file:
# Redis Configuration
REDIS_URL=redis://localhost:6379
USE_REDIS=true
Option B: InMemorySaver (Quick Testing)
For quick testing without Redis, the agent will automatically use InMemorySaver. No additional setup is required.
Add to your .env file:
# Memory-based state (no persistence)
USE_REDIS=false
๐ก Usage Tip
InMemorySaver doesn't persist conversations between restarts, while Redis maintains state across sessions.
6. Quick Test with Standalone Agent
Test your setup immediately with the standalone Firebase agent:
python firebase_admin_mcp/standalone_firebase_agent.py
You should see:
๐ฅ Firebase MCP Agent Ready!
Type 'help' for available commands, 'quit' to exit.
>
Try these commands:
> List all Firebase collections
> Check Firebase health status
> help
> quit
7. Full Django Setup (Optional)
For full Django integration:
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver 8001
The MCP server will be available at: http://127.0.0.1:8001/mcp/
๐ ๏ธ Management Commands
Core Commands
python firebase_admin_mcp/standalone_firebase_agent.py
python manage.py runserver 8001
python manage.py run_mcp --transport stdio
python manage.py run_mcp --transport http --host 127.0.0.1 --port 8001
python manage.py run_standalone_agent
Testing Commands
python firebase_admin_mcp/tests/test_firebase_connection.py
python firebase_admin_mcp/tests/test_mcp_complete.py
python firebase_admin_mcp/tests/demo_firebase_agent.py
python firebase_admin_mcp/demo_standalone_agent.py
๐ง Available Tools
The MCP server provides 14 Firebase tools across three categories:
๐ Authentication (4 tools)
firebase_verify_token - Verify Firebase ID tokens
firebase_create_custom_token - Create custom auth tokens
firebase_get_user - Get user info by UID
firebase_delete_user - Delete user accounts
๐ Firestore Database (6 tools)
firestore_list_collections - List all collections
firestore_create_document - Create new documents
firestore_get_document - Retrieve documents
firestore_update_document - Update documents
firestore_delete_document - Delete documents
firestore_query_collection - Query with filters
๐๏ธ Cloud Storage (4 tools)
storage_list_files - List files with filtering
storage_upload_file - Upload files
storage_download_file - Download files
storage_delete_file - Delete files
๐งช Quick Testing
Test Server Health
curl http://127.0.0.1:8001/mcp/
Test a Firebase Tool
curl -X POST http://127.0.0.1:8001/mcp/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "firestore_list_collections",
"arguments": {}
},
"id": 1
}'
๐ป Usage Examples
LangChain Example
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from firebase_admin_mcp.tools.agents.firebase_mcp_client import ALL_FIREBASE_TOOLS
model = ChatOpenAI(model="gpt-4")
agent = create_react_agent(
model=model,
tools=ALL_FIREBASE_TOOLS,
prompt="You are a Firebase assistant with full database and storage access."
)
response = agent.invoke({
"messages": [{"role": "user", "content": "Show me all my Firestore collections"}]
})
๐ Documentation
This project includes comprehensive documentation:
๐ง Troubleshooting
Common Issues
| Problem |
Solution |
Default app does not exist error |
Verify credentials.json path in .env file |
| Server won't start |
Check if port 8001 is available: `netstat -an |
| Firebase connection fails |
Verify Firebase services are enabled in console |
| Import errors |
Ensure all dependencies installed: pip install -r requirements.txt |
| Redis connection fails |
Verify Redis is running: redis-cli ping (should return "PONG") |
| State not persisting between sessions |
Check Redis configuration or switch to Redis from InMemorySaver |
๐ฏ What's Next?
- Explore the Standalone Agent - Perfect for quick testing and demos
- Read the Full Documentation - See FIREBASE_ADMIN_MCP.md for complete details
- Integrate with Your AI Agents - Use the MCP tools in your applications
- Customize for Your Needs - Extend with additional Firebase operations
๐ Project Structure
django-firebase-mcp/
โโโ README.md # This file
โโโ FIREBASE_ADMIN_MCP.md # Complete documentation
โโโ STANDALONE_AGENT.md # Standalone agent guide
โโโ requirements.txt # Python dependencies
โโโ credentials.json # Firebase credentials (you create this)
โโโ .env # Environment variables (you create this)
โโโ manage.py # Django management
โโโ firebase_admin_mcp/ # Main MCP app
โ โโโ standalone_firebase_agent.py # Standalone agent
โ โโโ tools/ # Firebase MCP tools
โ โโโ management/commands/ # Django commands
โ โโโ tests/ # Test suite
โโโ django_firebase_mcp/ # Django project settings
๐ค Contributing
- Fork the repository
- Create a feature branch
- Test your changes
- Submit a pull request
๐ License
This project is under the MIT License. See the LICENSE file for details.
๐ฅ Ready to supercharge your AI agents with Firebase?
Start with the standalone agent, then explore the full documentation for advanced usage!