Skip to main content

A production-ready Django app implementing Firebase Model Context Protocol (MCP) server with 14 Firebase tools for AI agents. Features standalone agent, HTTP/stdio transport, LangChain integration, and complete Firebase service coverage (Auth, Firestore, Storage).

Project description

Django Firebase MCP

A comprehensive Django app that implements Firebase Model Context Protocol (MCP) server, enabling AI agents to interact with Firebase services through a standardized protocol.

๐Ÿš€ Quick Start

Get up and running in under 5 minutes with the standalone Firebase agent for testing.

Prerequisites

  • Python 3.11+
  • 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

  1. Go to Firebase Console
  2. Select your project (or create a new one)
  3. Navigate to Project Settings โ†’ Service Accounts
  4. Click "Generate new private key"
  5. 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: Replace your-project-id with your actual Firebase project ID.

5. State Management Setup

The Firebase MCP agent uses state management for conversation persistence. Choose one option:

Option A: Redis (Recommended for Production)

Install and run Redis on port 6379:

# Install Redis using Chocolatey
choco install redis-64

# Or download from: https://github.com/microsoftarchive/redis/releases
# Then run Redis server
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 required.

Add to your .env file:

# Memory-based state (no persistence)
USE_REDIS=false

Note: 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:

# Run the standalone 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:

# Apply migrations
python manage.py migrate

# Create superuser (optional)
python manage.py createsuperuser

# Run Django development server
python manage.py runserver 8001

The MCP server will be available at: http://127.0.0.1:8001/mcp/

๐Ÿ› ๏ธ Management Commands

Core Commands

# Run standalone Firebase agent (quick testing)
python firebase_admin_mcp/standalone_firebase_agent.py

# Run MCP server via Django
python manage.py runserver 8001

# Run MCP server in stdio mode (for MCP clients)
python manage.py run_mcp --transport stdio

# Run MCP server in HTTP mode
python manage.py run_mcp --transport http --host 127.0.0.1 --port 8001

# Run standalone agent via Django management command
python manage.py run_standalone_agent

Testing Commands

# Test Firebase connectivity
python firebase_admin_mcp/tests/test_firebase_connection.py

# Test MCP server completeness
python firebase_admin_mcp/tests/test_mcp_complete.py

# Demo Firebase agent
python firebase_admin_mcp/tests/demo_firebase_agent.py

# Demo standalone agent
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
  }'

๐Ÿค– AI Agent Integration

LangChain Example

from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

# Import Firebase tools
from firebase_admin_mcp.tools.agents.firebase_mcp_client import ALL_FIREBASE_TOOLS

# Create agent with Firebase capabilities
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."
)

# Use the agent
response = agent.invoke({
    "messages": [{"role": "user", "content": "Show me all my Firestore collections"}]
})

๐Ÿ“š Documentation

This project includes comprehensive documentation:

  • FIREBASE_ADMIN_MCP.md - Complete technical documentation

    • Detailed API reference
    • All tool specifications
    • Advanced configuration
    • Security considerations
    • Production deployment guide
  • STANDALONE_AGENT.md - Standalone agent documentation

    • Self-contained Firebase agent
    • Complete feature overview
    • Usage examples
    • Integration patterns

๐Ÿ”ง Troubleshooting

Common Issues

Problem: Default app does not exist error Solution: Verify credentials.json path in .env file

Problem: Server won't start Solution: Check if port 8001 is available: netstat -an | findstr :8001

Problem: Firebase connection fails Solution: Verify Firebase services are enabled in console

Problem: Import errors Solution: Ensure all dependencies installed: pip install -r requirements.txt

Problem: Redis connection fails Solution: Verify Redis is running: redis-cli ping (should return "PONG")

Problem: State not persisting between sessions Solution: Check Redis configuration or switch to Redis from InMemorySaver

๐ŸŽฏ What's Next?

  1. Explore the Standalone Agent - Perfect for quick testing and demos
  2. Read the Full Documentation - See FIREBASE_ADMIN_MCP.md for complete details
  3. Integrate with Your AI Agents - Use the MCP tools in your applications
  4. 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

  1. Fork the repository
  2. Create a feature branch
  3. Test your changes
  4. Submit a pull request

๐Ÿ“„ License

MIT License - see 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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_firebase_mcp-0.0.2.tar.gz (42.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_firebase_mcp-0.0.2-py3-none-any.whl (53.8 kB view details)

Uploaded Python 3

File details

Details for the file django_firebase_mcp-0.0.2.tar.gz.

File metadata

  • Download URL: django_firebase_mcp-0.0.2.tar.gz
  • Upload date:
  • Size: 42.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for django_firebase_mcp-0.0.2.tar.gz
Algorithm Hash digest
SHA256 05d69f562f68c7daa91afe805f827013a54b629928cc6d3bde8c6f103aa07d51
MD5 ca47240c26a232d549a3bcfd65e18ae7
BLAKE2b-256 4aee715d3e943efec1050e47b955737c4ca453c9f50b12f38ee46c4a202d5efd

See more details on using hashes here.

File details

Details for the file django_firebase_mcp-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_firebase_mcp-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ad216ffec29d434ecb9b61996a1fe281eb3f68ab68e178b4beee355c1dcceae6
MD5 4f5435e38801a69df2680b6f85e6eeb1
BLAKE2b-256 574d55386f44c56f4371a37532f03f8034d3b8feaf02ee0612e4697fe330a275

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page