Skip to main content
Glama

FCP Gemini Server

Gemini 3-powered reference implementation of the Food Context Protocol

License Python Coverage

Protocol Spec · Try the API · Documentation


Overview

This is the reference implementation of the Food Context Protocol (FCP) in Python. It demonstrates how to implement FCP's 43 tools, dual transport (MCP + REST), and Gemini 3 integration.

For the protocol specification, see: Food-Context-Protocol/fcp

Development Disclosure: Development assisted by AI coding tools (Claude Code, GitHub Copilot, Cursor/Codex, Jules, Firebase Studio, Gemini API) for implementation. Core architecture, design, and functionality are original work.

⚠️ Legal Disclaimer: FCP provides AI-generated food information FOR INFORMATIONAL PURPOSES ONLY. This is not medical, nutritional, or health advice. Do not rely on AI for allergen detection, food safety, or drug-food interactions without verification. See LEGAL.md for complete disclaimers.

Related MCP server: macro-cache

Features

  • ✅ 43 MCP Tools - Nutrition, recipes, safety, inventory, planning

  • ✅ Dual Transport - MCP stdio + REST HTTP API

  • ✅ 100% Test Coverage - 2,981 passing tests

  • ✅ Gemini 3 Integration - 15+ features (multimodal, grounding, thinking, Live API)

  • ✅ Type-Safe - Pydantic schemas for all inputs/outputs

  • ✅ Auto-Generated SDKs - Python + TypeScript via Fern

Quick Start

Prerequisites

Installation

# Clone repository
git clone https://github.com/Food-Context-Protocol/fcp-gemini-server.git
cd fcp-gemini-server

# Install dependencies
make install

# Configure
cp .env.example .env
# Edit .env and add your GEMINI_API_KEY

Run

# HTTP Server (for web/mobile apps)
make dev-http
# Server runs on http://localhost:8080

# MCP Server (for Claude Desktop, CLI tools)
make run-mcp

# Run tests
make test

Try It

# Health check
curl http://localhost:8080/health

# Analyze a meal photo
curl -X POST http://localhost:8080/analyze \
  -H "Content-Type: application/json" \
  -d '{
    "image_url": "https://images.unsplash.com/photo-1546069901-ba9599a7e63c"
  }'

# Check food recalls
curl "http://localhost:8080/mcp/check_food_recalls?food_item=romaine+lettuce"

# List all MCP tools
curl http://localhost:8080/mcp/tools

MCP Client Integrations

Claude Desktop

See CLAUDE.md for full setup instructions.

{
  "mcpServers": {
    "fcp": {
      "command": "uv",
      "args": ["--directory", "/path/to/fcp-gemini-server", "run", "python", "-m", "fcp.server"],
      "env": {
        "GEMINI_API_KEY": "your_key",
        "FCP_TOKEN": "your_token"
      }
    }
  }
}

Gemini CLI Extension

Install the FCP extension for the Gemini CLI:

# Install extension
gemini extensions install ./gemini-extension

# Configure with your credentials
gemini extensions config fcp

# Use it
gemini
> /fcp:recent 5
> /fcp:search "that amazing ramen"
> /fcp:profile month

See gemini-extension/README.md for all available commands.

Architecture

┌─────────────┐
│   Clients   │  (CLI, Web, Mobile, Claude Desktop)
└──────┬──────┘
       │
       │  FCP Protocol (MCP stdio or REST HTTP)
       │
┌──────▼──────────────────────────────┐
│   FCP Server (This Repo)            │
│   - 43 Tool Implementations          │
│   - Pydantic Schema Validation      │
│   - Rate Limiting & Security        │
└──────┬──────────────────────────────┘
       │
       │  Google AI Python SDK
       │
┌──────▼──────────────────────────────┐
│   Gemini 3 Flash & Pro              │
│   - Multimodal Vision               │
│   - Function Calling                │
│   - Google Search Grounding         │
│   - Extended Thinking               │
│   - Code Execution                  │
│   - Live API                        │
└─────────────────────────────────────┘

Project Structure

server/
├── src/fcp/
│   ├── tools/               # 43 MCP tool implementations
│   │   ├── nutrition/       # Meal analysis, logging
│   │   ├── recipes/         # Recipe search, scaling
│   │   ├── safety/          # Recall checks, allergens
│   │   ├── inventory/       # Pantry management
│   │   └── planning/        # Meal suggestions
│   ├── routes/              # REST API endpoints
│   │   └── schemas.py       # Pydantic response models
│   ├── services/            # External service clients
│   │   ├── gemini/          # Gemini 3 integration
│   │   ├── database.py      # SQLite persistence
│   │   └── fda.py           # OpenFDA integration
│   ├── security/            # Auth, rate limiting, validation
│   └── api.py               # FastAPI application
├── tests/                   # 100% branch coverage
│   ├── unit/                # Fast, hermetic tests
│   └── integration/         # E2E workflow tests
├── docs/                    # Implementation docs
└── Makefile                 # Common commands

Gemini 3 Integration

Multimodal Vision

# Analyze food photo
from fcp.services.gemini import GeminiClient

client = GeminiClient()
result = await client.analyze_image(
    image_url="https://example.com/food.jpg",
    prompt="Extract nutrition information"
)

Function Calling

# Structured extraction with typed schemas
tools = [
    types.Tool(function_declarations=[
        types.FunctionDeclaration(
            name="log_meal",
            description="Log a meal with nutrition data",
            parameters=MealLogSchema
        )
    ])
]

Google Search Grounding

# Real-time FDA recall checks
response = await client.generate_content(
    prompt="Check if romaine lettuce has recalls",
    config=types.GenerateContentConfig(
        tools=[types.Tool(google_search_retrieval={})]
    )
)

Available Commands

make install          # Install dependencies (uv sync)
make test             # Run tests with 100% coverage
make test-quick       # Run tests without coverage
make dev-http         # Start HTTP API with hot-reload
make run-mcp          # Start MCP stdio server
make lint             # Lint code with ruff
make format           # Format code with ruff
make typecheck        # Type check with mypy
make coverage         # Generate coverage report
make sdk              # Regenerate OpenAPI spec + SDKs

Configuration

Required Environment Variables

Variable

Description

GEMINI_API_KEY

Google Gemini API key from ai.google.dev

Optional Environment Variables

Variable

Description

Default

DATABASE_BACKEND

Database backend (sqlite or firestore)

sqlite

DEMO_MODE

Enable demo mode (no auth required)

false

DATABASE_URL

SQLite database path (sqlite backend only)

sqlite:///data/fcp.db

GOOGLE_CLOUD_PROJECT

GCP project ID (firestore backend only)

-

LOG_LEVEL

Logging level

INFO

RATE_LIMIT_PER_MINUTE

API rate limit

60

See .env.example for complete configuration options.

Database Backend Selection

The server supports two database backends:

SQLite (default) - Best for local development:

# Uses local SQLite database at data/fcp.db
DATABASE_BACKEND=sqlite
make dev-http

Cloud Firestore - For production on Cloud Run:

# Install Firestore dependencies
uv sync --extra firestore

# Configure GCP project
export DATABASE_BACKEND=firestore
export GOOGLE_CLOUD_PROJECT=your-project-id

# For local testing, use service account credentials
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json

# Or use gcloud CLI default credentials
gcloud auth application-default login

# Start server
make dev-http

The backend is selected automatically based on the DATABASE_BACKEND environment variable. All 43 MCP tools work identically with either backend.

Testing

# Run all tests with coverage (enforces 100%)
make test

# Run specific test file
pytest tests/unit/tools/test_nutrition.py -v

# Run core integration tests (backend-agnostic, sqlite)
RUN_INTEGRATION=1 DATABASE_BACKEND=sqlite pytest tests/integration/ -m "core and integration"

# Run external integration tests (USDA/FDA/maps/places), opt-in
RUN_INTEGRATION=1 RUN_EXTERNAL_INTEGRATION=1 DATABASE_BACKEND=sqlite pytest tests/integration/ -m "external and integration"

# Run full integration suite
RUN_INTEGRATION=1 RUN_EXTERNAL_INTEGRATION=1 DATABASE_BACKEND=sqlite pytest tests/integration/

# Watch mode during development
pytest-watch

Deployment

See docs/deployment-guide.md for deployment to:

  • Google Cloud Run

  • Docker containers

  • Kubernetes

  • Local servers

Quick deploy to Cloud Run with Firestore:

gcloud run deploy fcp-api \
  --source . \
  --region us-central1 \
  --allow-unauthenticated \
  --set-env-vars GEMINI_API_KEY=your-key,DATABASE_BACKEND=firestore,GOOGLE_CLOUD_PROJECT=your-project-id

Note: Cloud Run automatically uses Application Default Credentials, so no service account key is needed. Ensure the Cloud Run service account has Firestore permissions (roles/datastore.user).

Contributing

We welcome contributions! See the main CONTRIBUTING.md for:

  • Code of conduct

  • Development workflow

  • Testing requirements

  • Pull request process

Protocol Specification

This implementation follows the Food Context Protocol specification:

📖 View Specification

License

Apache-2.0 - See LICENSE for software license and LEGAL.md for disclaimers


Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      C
      maintenance
      Enables AI agents and LLMs to retrieve precise food chemistry and nutrition data from USDA, Open Food Facts, and IFCT, evaluate recipes, optimize macros, look up barcodes, and detect ultra-processed foods through MCP tools.
      9
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables Claude to act as the memory and reasoning layer for nutrition tracking, letting users log meals from label photos or descriptions, save foods, recipes, meal-prep containers, and restaurant orders, record weigh-ins, and query targets, progress, and projections as tool calls. All writes are previewed with dry runs, checked for plausibility, and reversible.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables users to log meals, retrieve daily nutrition summaries, receive nutrition recommendations, and resolve ambiguous food entries through standardized MCP tool calls. It supports voice-driven macro tracking and conversational disambiguation for Alexa+ and other MCP-compliant agents.
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables MCP-capable AI assistants to read and safely update a self-hosted pantry, food diary, recipes, training history, Garmin data, shopping needs, and reminders through typed tools with server-enforced guardrails.
      MIT