Skip to main content
Glama
zzgael

ANSES Ciqual MCP Server

by zzgael

query

Execute SQL queries to retrieve comprehensive nutritional data from the ANSES Ciqual French food composition database, enabling analysis of over 3,000 foods and 60+ nutrients in single queries.

Instructions

Execute SQL query on ANSES Ciqual French food composition database.

IMPORTANT: Get ALL nutrients in ONE query! Don't make multiple queries for the same food.

EXAMPLE - Get complete nutrition for a food: SELECT f.alim_nom_eng, n.const_nom_eng, c.teneur, n.unit FROM foods f JOIN composition c ON f.alim_code = c.alim_code JOIN nutrients n ON c.const_code = n.const_code WHERE f.alim_code = 23000; -- Returns ALL 60+ nutrients in one query!

SCHEMA: • foods: 3,185+ foods with French/English names

  • alim_code (PK), alim_nom_fr, alim_nom_eng, alim_grp_code

• nutrients: ~60+ nutrients with units

  • const_code (PK), const_nom_fr, const_nom_eng, unit

• composition: nutritional values per 100g

  • alim_code, const_code, teneur (value), code_confiance (A/B/C/D)

• foods_fts: full-text search for fuzzy matching

  • Use: WHERE foods_fts MATCH 'search term'

COMMON QUERIES:

  1. Search foods: SELECT * FROM foods_fts WHERE foods_fts MATCH 'cake';

  2. Get ALL nutrients: JOIN all 3 tables, no WHERE clause on nutrients

  3. Get specific nutrients: Use IN clause with multiple codes at once

KEY NUTRIENT CODES: Energy: 327 (kJ), 328 (kcal) Macros: 25000 (protein g), 31000 (carbs g), 40000 (fat g), 34100 (fiber g), 32000 (sugars g) Minerals: 10110 (sodium mg), 10200 (calcium mg), 10260 (iron mg), 10190 (potassium mg) Vitamins: 55400 (vit C mg), 56400 (vit D µg), 51330 (vit B12 µg), 56310 (vit E mg)

The database is read-only. Use SELECT queries only.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'query' tool handler: an async function decorated with @mcp.tool() that executes read-only SQL SELECT queries on the ANSES Ciqual SQLite database. Includes input validation, error handling, and detailed docstring describing database schema and usage examples.
    @mcp.tool()
    async def query(sql: str) -> list[dict]:
        """Execute SQL query on ANSES Ciqual French food composition database.
        
        IMPORTANT: Get ALL nutrients in ONE query! Don't make multiple queries for the same food.
        
        EXAMPLE - Get complete nutrition for a food:
        SELECT f.alim_nom_eng, n.const_nom_eng, c.teneur, n.unit
        FROM foods f
        JOIN composition c ON f.alim_code = c.alim_code
        JOIN nutrients n ON c.const_code = n.const_code
        WHERE f.alim_code = 23000;  -- Returns ALL 60+ nutrients in one query!
        
        SCHEMA:
        • foods: 3,185+ foods with French/English names
          - alim_code (PK), alim_nom_fr, alim_nom_eng, alim_grp_code
        
        • nutrients: ~60+ nutrients with units
          - const_code (PK), const_nom_fr, const_nom_eng, unit
        
        • composition: nutritional values per 100g
          - alim_code, const_code, teneur (value), code_confiance (A/B/C/D)
        
        • foods_fts: full-text search for fuzzy matching
          - Use: WHERE foods_fts MATCH 'search term'
        
        COMMON QUERIES:
        1. Search foods: SELECT * FROM foods_fts WHERE foods_fts MATCH 'cake';
        2. Get ALL nutrients: JOIN all 3 tables, no WHERE clause on nutrients
        3. Get specific nutrients: Use IN clause with multiple codes at once
        
        KEY NUTRIENT CODES:
        Energy: 327 (kJ), 328 (kcal)
        Macros: 25000 (protein g), 31000 (carbs g), 40000 (fat g), 34100 (fiber g), 32000 (sugars g)
        Minerals: 10110 (sodium mg), 10200 (calcium mg), 10260 (iron mg), 10190 (potassium mg)
        Vitamins: 55400 (vit C mg), 56400 (vit D µg), 51330 (vit B12 µg), 56310 (vit E mg)
        
        The database is read-only. Use SELECT queries only.
        """
        
        # Ensure database exists
        if not DB_PATH.exists():
            logger.warning("Database not found at %s", DB_PATH)
            return [{"error": "Database not initialized. Please run the server first to download data."}]
        
        # Validate SQL query (basic safety check)
        sql_lower = sql.strip().lower()
        if not sql_lower.startswith(('select', 'with')):
            return [{"error": "Only SELECT queries are allowed for safety."}]
        
        # Connect with read-only mode
        try:
            logger.debug("Executing query: %s", sql[:100] + '...' if len(sql) > 100 else sql)
            conn = sqlite3.connect(f"file:{DB_PATH}?mode=ro", uri=True)
            conn.row_factory = sqlite3.Row
            
            # Execute query with timeout
            conn.execute("PRAGMA query_only = ON")
            conn.execute("PRAGMA temp_store = MEMORY")
            cursor = conn.execute(sql)
            results = [dict(row) for row in cursor.fetchall()]
            logger.debug("Query returned %d rows", len(results))
            return results
            
        except sqlite3.OperationalError as e:
            logger.error("SQL operational error: %s", e)
            if "no such table" in str(e):
                return [{"error": f"Table not found. Available tables: foods, nutrients, composition, foods_fts, food_groups"}]
            elif "read-only" in str(e) or "readonly" in str(e):
                return [{"error": "Database is read-only. Only SELECT queries are allowed."}]
            else:
                return [{"error": f"SQL error: {str(e)}"}]
        except sqlite3.Error as e:
            logger.error("Database error: %s", e)
            return [{"error": f"Database error: {str(e)}"}]
        except Exception as e:
            logger.error("Unexpected error: %s", e)
            return [{"error": f"Unexpected error: {str(e)}"}]
        finally:
            if 'conn' in locals():
                conn.close()
  • Database schema description in the tool docstring, detailing tables, columns, and usage for the 'query' tool.
    SCHEMA:
    • foods: 3,185+ foods with French/English names
      - alim_code (PK), alim_nom_fr, alim_nom_eng, alim_grp_code
    
    • nutrients: ~60+ nutrients with units
      - const_code (PK), const_nom_fr, const_nom_eng, unit
    
    • composition: nutritional values per 100g
      - alim_code, const_code, teneur (value), code_confiance (A/B/C/D)
    
    • foods_fts: full-text search for fuzzy matching
      - Use: WHERE foods_fts MATCH 'search term'
    
    COMMON QUERIES:
    1. Search foods: SELECT * FROM foods_fts WHERE foods_fts MATCH 'cake';
    2. Get ALL nutrients: JOIN all 3 tables, no WHERE clause on nutrients
    3. Get specific nutrients: Use IN clause with multiple codes at once
    
    KEY NUTRIENT CODES:
    Energy: 327 (kJ), 328 (kcal)
    Macros: 25000 (protein g), 31000 (carbs g), 40000 (fat g), 34100 (fiber g), 32000 (sugars g)
    Minerals: 10110 (sodium mg), 10200 (calcium mg), 10260 (iron mg), 10190 (potassium mg)
    Vitamins: 55400 (vit C mg), 56400 (vit D µg), 51330 (vit B12 µg), 56310 (vit E mg)
    
    The database is read-only. Use SELECT queries only.
    """
  • src/server.py:26-26 (registration)
    Registration of the 'query' tool via FastMCP @mcp.tool() decorator on the handler function.
    @mcp.tool()
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It clearly states the database is read-only and restricts usage to SELECT queries, which informs the agent about safety and limitations. It also provides context on database structure (tables like foods, nutrients, composition), example queries, and performance tips (e.g., avoiding multiple queries), adding significant value beyond any structured fields.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (e.g., IMPORTANT, EXAMPLE, SCHEMA, COMMON QUERIES, KEY NUTRIENT CODES) and uses bullet points for readability. It is appropriately sized for a complex tool, but some parts (like the detailed schema listing) could be slightly condensed. Every sentence adds value, such as performance advice and database constraints, making it efficient overall.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (executing SQL queries on a specific database), no annotations, 0% schema coverage, but with an output schema present, the description is highly complete. It covers purpose, usage guidelines, behavioral traits (read-only, SELECT-only), parameter semantics with examples, database structure, and common queries. The output schema handles return values, so the description doesn't need to explain them, making it fully adequate for the agent's needs.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0% description coverage for the single parameter 'sql', so the description must compensate. It adds substantial meaning by explaining that 'sql' should be an SQL query for the ANSES Ciqual database, providing example queries, schema details (tables and columns), and usage tips. However, it doesn't explicitly define the 'sql' parameter's syntax or constraints beyond examples, leaving some room for interpretation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states the tool's purpose: 'Execute SQL query on ANSES Ciqual French food composition database.' It specifies the verb ('Execute SQL query'), the resource ('ANSES Ciqual French food composition database'), and distinguishes it from potential alternatives by emphasizing 'Get ALL nutrients in ONE query! Don't make multiple queries for the same food.' This is specific and clear, with no siblings to differentiate from.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool: for executing SQL queries on the specified database. It includes detailed examples (e.g., 'EXAMPLE - Get complete nutrition for a food'), common queries (e.g., 'Search foods', 'Get ALL nutrients'), and key constraints ('The database is read-only. Use SELECT queries only.'). This covers when to use it, how to use it effectively, and what not to do, with no alternatives mentioned as there are no sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zzgael/ciqual-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server