Skip to main content

MCP server for ANSES Ciqual French food composition database with SQL interface

Project description

ANSES Ciqual MCP Server

Python 3.9+ License: MIT MCP Protocol

An MCP (Model Context Protocol) server providing SQL access to the ANSES Ciqual French food composition database. Query nutritional data for over 3,000 foods with full-text search support.

ANSES Ciqual Database

Features

  • 🍎 Comprehensive Database: Access nutritional data for 3,185+ French foods
  • 🔍 SQL Interface: Query using standard SQL with full flexibility
  • 🌍 Bilingual Support: French and English food names
  • 🔤 Fuzzy Search: Built-in full-text search with typo tolerance
  • 📊 60+ Nutrients: Detailed composition including vitamins, minerals, macros, and more
  • 🔄 Auto-Updates: Automatically refreshes data yearly from ANSES (checks on startup)
  • 🔒 Read-Only: Safe queries with no risk of data modification
  • 💾 Lightweight: ~10MB SQLite database with efficient indexing

Installation

Via pip

pip install ciqual-mcp

Via uvx (recommended)

uvx ciqual-mcp

From source

git clone https://github.com/zzgael/ciqual-mcp.git
cd ciqual-mcp
pip install -e .

MCP Client Configuration

Claude Desktop

Add to your Claude Desktop configuration:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "ciqual": {
      "command": "uvx",
      "args": ["ciqual-mcp"]
    }
  }
}

Zed

Add to your Zed settings:

{
  "assistant": {
    "version": "2",
    "mcp": {
      "servers": {
        "ciqual": {
          "command": "uvx",
          "args": ["ciqual-mcp"]
        }
      }
    }
  }
}

Cline (VSCode Extension)

Add to your VSCode settings (settings.json):

{
  "cline.mcpServers": {
    "ciqual": {
      "command": "uvx",
      "args": ["ciqual-mcp"]
    }
  }
}

Continue.dev

Add to your Continue config (~/.continue/config.json):

{
  "mcpServers": [
    {
      "name": "ciqual",
      "command": "uvx",
      "args": ["ciqual-mcp"]
    }
  ]
}

Usage

As an MCP Server

The server implements the Model Context Protocol and exposes a single query function:

# Start the server standalone (for testing)
ciqual-mcp

Direct Python Usage

from ciqual_mcp.data_loader import initialize_database

# Initialize/update the database
initialize_database()

# Then use SQLite directly
import sqlite3
conn = sqlite3.connect("~/.ciqual/ciqual.db")
cursor = conn.execute("SELECT * FROM foods WHERE alim_nom_eng LIKE '%apple%'")

Database Schema

Tables

foods - Food items

  • alim_code (INTEGER, PK): Unique food identifier
  • alim_nom_fr (TEXT): French name
  • alim_nom_eng (TEXT): English name
  • alim_grp_code (TEXT): Food group code

nutrients - Nutrient definitions

  • const_code (INTEGER, PK): Unique nutrient identifier
  • const_nom_fr (TEXT): French name
  • const_nom_eng (TEXT): English name
  • unit (TEXT): Measurement unit (g/100g, mg/100g, etc.)

composition - Nutritional values

  • alim_code (INTEGER): Food identifier
  • const_code (INTEGER): Nutrient identifier
  • teneur (REAL): Value per 100g
  • code_confiance (TEXT): Confidence level (A/B/C/D)

foods_fts - Full-text search

Virtual table for fuzzy matching with French/English names

Common Nutrient Codes

Category Code Nutrient Unit
Energy 327 Energy kJ/100g
328 Energy kcal/100g
Macros 25000 Protein g/100g
31000 Carbohydrates g/100g
40000 Fat g/100g
34100 Fiber g/100g
32000 Sugars g/100g
Minerals 10110 Sodium mg/100g
10200 Calcium mg/100g
10260 Iron mg/100g
10190 Potassium mg/100g
Vitamins 55400 Vitamin C mg/100g
56400 Vitamin D µg/100g
51330 Vitamin B12 µg/100g

Example Queries

Basic Search

-- Find foods by name
SELECT * FROM foods WHERE alim_nom_eng LIKE '%orange%';

-- Fuzzy search (handles typos)
SELECT * FROM foods_fts WHERE foods_fts MATCH 'orang*';

Nutritional Queries

-- Get vitamin C content for oranges
SELECT f.alim_nom_eng, c.teneur as vitamin_c_mg
FROM foods f
JOIN composition c ON f.alim_code = c.alim_code
WHERE f.alim_nom_eng LIKE '%orange%' 
  AND c.const_code = 55400;

-- Find foods highest in protein
SELECT f.alim_nom_eng, c.teneur as protein_g
FROM foods f
JOIN composition c ON f.alim_code = c.alim_code
WHERE c.const_code = 25000
ORDER BY c.teneur DESC
LIMIT 10;

-- Compare macros for different foods
SELECT 
    f.alim_nom_eng as food,
    MAX(CASE WHEN c.const_code = 25000 THEN c.teneur END) as protein_g,
    MAX(CASE WHEN c.const_code = 31000 THEN c.teneur END) as carbs_g,
    MAX(CASE WHEN c.const_code = 40000 THEN c.teneur END) as fat_g,
    MAX(CASE WHEN c.const_code = 328 THEN c.teneur END) as calories_kcal
FROM foods f
JOIN composition c ON f.alim_code = c.alim_code
WHERE f.alim_nom_eng IN ('Apple, raw', 'Banana, raw', 'Orange, raw')
  AND c.const_code IN (25000, 31000, 40000, 328)
GROUP BY f.alim_code, f.alim_nom_eng;

Dietary Restrictions

-- Find low-sodium foods (<100mg/100g)
SELECT f.alim_nom_eng, c.teneur as sodium_mg
FROM foods f
JOIN composition c ON f.alim_code = c.alim_code
WHERE c.const_code = 10110 
  AND c.teneur < 100
ORDER BY c.teneur ASC;

-- High-fiber foods (>5g/100g)
SELECT f.alim_nom_eng, c.teneur as fiber_g
FROM foods f
JOIN composition c ON f.alim_code = c.alim_code
WHERE c.const_code = 34100 
  AND c.teneur > 5
ORDER BY c.teneur DESC;

Data Source

Data is sourced from the official ANSES Ciqual database:

The database is automatically updated yearly when the server starts (data hasn't changed since 2020, so yearly updates are sufficient).

Requirements

  • Python 3.9 or higher
  • 50MB free disk space (for database)
  • Internet connection (for initial data download)

License

MIT License - See LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development

Running Tests

# Install development dependencies
pip install -e .
pip install pytest pytest-asyncio

# Run unit tests
python -m pytest tests/test_server.py -v

# Run functional tests (requires database)
python -m pytest tests/test_functional.py -v

Building for Distribution

# Build the package
python -m build

# Upload to PyPI
python -m twine upload dist/*

Troubleshooting

Database not initializing

  • Check internet connection
  • Ensure write permissions to ~/.ciqual/ directory
  • Try manual initialization: python -m ciqual_mcp.data_loader

XML parsing errors

  • The tool handles malformed XML automatically with recovery mode
  • If issues persist, delete ~/.ciqual/ciqual.db and restart

Credits

Developed by GPT Workbench team.

Data provided by ANSES (Agence nationale de sécurité sanitaire de l'alimentation, de l'environnement et du travail).

Citation

If you use this tool in your research, please cite:

@software{ciqual_mcp,
  title = {ANSES Ciqual MCP Server},
  author = {GPT Workbench Team},
  year = {2024},
  url = {https://github.com/gpt-workbench/ciqual-mcp}
}

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

ciqual_mcp-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

ciqual_mcp-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file ciqual_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: ciqual_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ciqual_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd1797840ce6b124991d05a5ce1346fb122c7f5269dc6389a4bcf25a6670d383
MD5 e357be6f6e081b74f075461462cf7c76
BLAKE2b-256 62dc57ee9c08699317b1b0ce22ede0e03d06f84dc2f5bdbb3109feda8d32ae5d

See more details on using hashes here.

File details

Details for the file ciqual_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ciqual_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ciqual_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa33f45a886c7a445a50b3bd980d93bbae911111770d94b2437e52b1681454e2
MD5 75910d270eddcc2c65b87513ddab6cfa
BLAKE2b-256 d5c2e0c1c2b99ef9cc52bc59ae804c61c13563bc7cb0dc05180763c5036315ed

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