ciqual-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2024-01-09
9
+
10
+ ### Added
11
+ - Initial release
12
+ - SQL query interface for ANSES Ciqual database
13
+ - Automatic database initialization and updates
14
+ - Full-text search support with fuzzy matching
15
+ - Comprehensive test suite (unit and functional)
16
+ - Support for 3,185+ foods and 67 nutrients
17
+ - Bilingual support (French and English)
18
+ - Read-only database access for safety
19
+ - Auto-update mechanism (yearly checks)
20
+ - MCP server implementation with FastMCP
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 GPT Workbench
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ include README.md
2
+ include LICENSE
3
+ include CHANGELOG.md
4
+ recursive-include src *.py
5
+ recursive-include tests *.py
6
+ global-exclude *.pyc
7
+ global-exclude __pycache__
8
+ global-exclude *.db
9
+ global-exclude *.sqlite*
@@ -0,0 +1,354 @@
1
+ Metadata-Version: 2.4
2
+ Name: ciqual-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server for ANSES Ciqual French food composition database with SQL interface
5
+ Author-email: GPT Workbench Team <contact@gpt-workbench.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/gpt-workbench/ciqual-mcp
8
+ Project-URL: Bug Reports, https://github.com/gpt-workbench/ciqual-mcp/issues
9
+ Project-URL: Source, https://github.com/gpt-workbench/ciqual-mcp
10
+ Keywords: mcp,ciqual,anses,nutrition,food,database,sql
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Database
20
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: fastmcp>=0.1.0
26
+ Requires-Dist: lxml>=4.9.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
29
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # ANSES Ciqual MCP Server
33
+
34
+ <div align="center">
35
+
36
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
37
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
38
+ [![MCP Protocol](https://img.shields.io/badge/MCP-1.0-green.svg)](https://modelcontextprotocol.io/)
39
+
40
+ 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.
41
+
42
+ ![ANSES Ciqual Database](assets/ciqual-banner.jpg)
43
+
44
+ </div>
45
+
46
+ ## Features
47
+
48
+ - 🍎 **Comprehensive Database**: Access nutritional data for 3,185+ French foods
49
+ - 🔍 **SQL Interface**: Query using standard SQL with full flexibility
50
+ - 🌍 **Bilingual Support**: French and English food names
51
+ - 🔤 **Fuzzy Search**: Built-in full-text search with typo tolerance
52
+ - 📊 **60+ Nutrients**: Detailed composition including vitamins, minerals, macros, and more
53
+ - 🔄 **Auto-Updates**: Automatically refreshes data yearly from ANSES (checks on startup)
54
+ - 🔒 **Read-Only**: Safe queries with no risk of data modification
55
+ - 💾 **Lightweight**: ~10MB SQLite database with efficient indexing
56
+
57
+ ## Installation
58
+
59
+ ### Via pip
60
+ ```bash
61
+ pip install ciqual-mcp
62
+ ```
63
+
64
+ ### Via uvx (recommended)
65
+ ```bash
66
+ uvx ciqual-mcp
67
+ ```
68
+
69
+ ### From source
70
+ ```bash
71
+ git clone https://github.com/zzgael/ciqual-mcp.git
72
+ cd ciqual-mcp
73
+ pip install -e .
74
+ ```
75
+
76
+ ## MCP Client Configuration
77
+
78
+ ### Claude Desktop
79
+
80
+ Add to your Claude Desktop configuration:
81
+
82
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
83
+ **Windows**: `%APPDATA%/Claude/claude_desktop_config.json`
84
+ **Linux**: `~/.config/Claude/claude_desktop_config.json`
85
+
86
+ ```json
87
+ {
88
+ "mcpServers": {
89
+ "ciqual": {
90
+ "command": "uvx",
91
+ "args": ["ciqual-mcp"]
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ ### Zed
98
+
99
+ Add to your Zed settings:
100
+
101
+ ```json
102
+ {
103
+ "assistant": {
104
+ "version": "2",
105
+ "mcp": {
106
+ "servers": {
107
+ "ciqual": {
108
+ "command": "uvx",
109
+ "args": ["ciqual-mcp"]
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ ### Cline (VSCode Extension)
118
+
119
+ Add to your VSCode settings (`settings.json`):
120
+
121
+ ```json
122
+ {
123
+ "cline.mcpServers": {
124
+ "ciqual": {
125
+ "command": "uvx",
126
+ "args": ["ciqual-mcp"]
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ ### Continue.dev
133
+
134
+ Add to your Continue config (`~/.continue/config.json`):
135
+
136
+ ```json
137
+ {
138
+ "mcpServers": [
139
+ {
140
+ "name": "ciqual",
141
+ "command": "uvx",
142
+ "args": ["ciqual-mcp"]
143
+ }
144
+ ]
145
+ }
146
+ ```
147
+
148
+ ## Usage
149
+
150
+ ### As an MCP Server
151
+
152
+ The server implements the Model Context Protocol and exposes a single `query` function:
153
+
154
+ ```bash
155
+ # Start the server standalone (for testing)
156
+ ciqual-mcp
157
+ ```
158
+
159
+ ### Direct Python Usage
160
+
161
+ ```python
162
+ from ciqual_mcp.data_loader import initialize_database
163
+
164
+ # Initialize/update the database
165
+ initialize_database()
166
+
167
+ # Then use SQLite directly
168
+ import sqlite3
169
+ conn = sqlite3.connect("~/.ciqual/ciqual.db")
170
+ cursor = conn.execute("SELECT * FROM foods WHERE alim_nom_eng LIKE '%apple%'")
171
+ ```
172
+
173
+ ## Database Schema
174
+
175
+ ### Tables
176
+
177
+ #### `foods` - Food items
178
+ - `alim_code` (INTEGER, PK): Unique food identifier
179
+ - `alim_nom_fr` (TEXT): French name
180
+ - `alim_nom_eng` (TEXT): English name
181
+ - `alim_grp_code` (TEXT): Food group code
182
+
183
+ #### `nutrients` - Nutrient definitions
184
+ - `const_code` (INTEGER, PK): Unique nutrient identifier
185
+ - `const_nom_fr` (TEXT): French name
186
+ - `const_nom_eng` (TEXT): English name
187
+ - `unit` (TEXT): Measurement unit (g/100g, mg/100g, etc.)
188
+
189
+ #### `composition` - Nutritional values
190
+ - `alim_code` (INTEGER): Food identifier
191
+ - `const_code` (INTEGER): Nutrient identifier
192
+ - `teneur` (REAL): Value per 100g
193
+ - `code_confiance` (TEXT): Confidence level (A/B/C/D)
194
+
195
+ #### `foods_fts` - Full-text search
196
+ Virtual table for fuzzy matching with French/English names
197
+
198
+ ### Common Nutrient Codes
199
+
200
+ | Category | Code | Nutrient | Unit |
201
+ |----------|------|----------|------|
202
+ | **Energy** | 327 | Energy | kJ/100g |
203
+ | | 328 | Energy | kcal/100g |
204
+ | **Macros** | 25000 | Protein | g/100g |
205
+ | | 31000 | Carbohydrates | g/100g |
206
+ | | 40000 | Fat | g/100g |
207
+ | | 34100 | Fiber | g/100g |
208
+ | | 32000 | Sugars | g/100g |
209
+ | **Minerals** | 10110 | Sodium | mg/100g |
210
+ | | 10200 | Calcium | mg/100g |
211
+ | | 10260 | Iron | mg/100g |
212
+ | | 10190 | Potassium | mg/100g |
213
+ | **Vitamins** | 55400 | Vitamin C | mg/100g |
214
+ | | 56400 | Vitamin D | µg/100g |
215
+ | | 51330 | Vitamin B12 | µg/100g |
216
+
217
+ ## Example Queries
218
+
219
+ ### Basic Search
220
+ ```sql
221
+ -- Find foods by name
222
+ SELECT * FROM foods WHERE alim_nom_eng LIKE '%orange%';
223
+
224
+ -- Fuzzy search (handles typos)
225
+ SELECT * FROM foods_fts WHERE foods_fts MATCH 'orang*';
226
+ ```
227
+
228
+ ### Nutritional Queries
229
+ ```sql
230
+ -- Get vitamin C content for oranges
231
+ SELECT f.alim_nom_eng, c.teneur as vitamin_c_mg
232
+ FROM foods f
233
+ JOIN composition c ON f.alim_code = c.alim_code
234
+ WHERE f.alim_nom_eng LIKE '%orange%'
235
+ AND c.const_code = 55400;
236
+
237
+ -- Find foods highest in protein
238
+ SELECT f.alim_nom_eng, c.teneur as protein_g
239
+ FROM foods f
240
+ JOIN composition c ON f.alim_code = c.alim_code
241
+ WHERE c.const_code = 25000
242
+ ORDER BY c.teneur DESC
243
+ LIMIT 10;
244
+
245
+ -- Compare macros for different foods
246
+ SELECT
247
+ f.alim_nom_eng as food,
248
+ MAX(CASE WHEN c.const_code = 25000 THEN c.teneur END) as protein_g,
249
+ MAX(CASE WHEN c.const_code = 31000 THEN c.teneur END) as carbs_g,
250
+ MAX(CASE WHEN c.const_code = 40000 THEN c.teneur END) as fat_g,
251
+ MAX(CASE WHEN c.const_code = 328 THEN c.teneur END) as calories_kcal
252
+ FROM foods f
253
+ JOIN composition c ON f.alim_code = c.alim_code
254
+ WHERE f.alim_nom_eng IN ('Apple, raw', 'Banana, raw', 'Orange, raw')
255
+ AND c.const_code IN (25000, 31000, 40000, 328)
256
+ GROUP BY f.alim_code, f.alim_nom_eng;
257
+ ```
258
+
259
+ ### Dietary Restrictions
260
+ ```sql
261
+ -- Find low-sodium foods (<100mg/100g)
262
+ SELECT f.alim_nom_eng, c.teneur as sodium_mg
263
+ FROM foods f
264
+ JOIN composition c ON f.alim_code = c.alim_code
265
+ WHERE c.const_code = 10110
266
+ AND c.teneur < 100
267
+ ORDER BY c.teneur ASC;
268
+
269
+ -- High-fiber foods (>5g/100g)
270
+ SELECT f.alim_nom_eng, c.teneur as fiber_g
271
+ FROM foods f
272
+ JOIN composition c ON f.alim_code = c.alim_code
273
+ WHERE c.const_code = 34100
274
+ AND c.teneur > 5
275
+ ORDER BY c.teneur DESC;
276
+ ```
277
+
278
+ ## Data Source
279
+
280
+ Data is sourced from the official ANSES Ciqual database:
281
+ - Website: https://ciqual.anses.fr/
282
+ - Data portal: https://www.data.gouv.fr/fr/datasets/table-de-composition-nutritionnelle-des-aliments-ciqual/
283
+
284
+ The database is automatically updated yearly when the server starts (data hasn't changed since 2020, so yearly updates are sufficient).
285
+
286
+ ## Requirements
287
+
288
+ - Python 3.9 or higher
289
+ - 50MB free disk space (for database)
290
+ - Internet connection (for initial data download)
291
+
292
+ ## License
293
+
294
+ MIT License - See LICENSE file for details
295
+
296
+ ## Contributing
297
+
298
+ Contributions are welcome! Please feel free to submit a Pull Request.
299
+
300
+ ## Development
301
+
302
+ ### Running Tests
303
+
304
+ ```bash
305
+ # Install development dependencies
306
+ pip install -e .
307
+ pip install pytest pytest-asyncio
308
+
309
+ # Run unit tests
310
+ python -m pytest tests/test_server.py -v
311
+
312
+ # Run functional tests (requires database)
313
+ python -m pytest tests/test_functional.py -v
314
+ ```
315
+
316
+ ### Building for Distribution
317
+
318
+ ```bash
319
+ # Build the package
320
+ python -m build
321
+
322
+ # Upload to PyPI
323
+ python -m twine upload dist/*
324
+ ```
325
+
326
+ ## Troubleshooting
327
+
328
+ ### Database not initializing
329
+ - Check internet connection
330
+ - Ensure write permissions to `~/.ciqual/` directory
331
+ - Try manual initialization: `python -m ciqual_mcp.data_loader`
332
+
333
+ ### XML parsing errors
334
+ - The tool handles malformed XML automatically with recovery mode
335
+ - If issues persist, delete `~/.ciqual/ciqual.db` and restart
336
+
337
+ ## Credits
338
+
339
+ Developed by [GPT Workbench](https://github.com/gpt-workbench) team.
340
+
341
+ Data provided by ANSES (Agence nationale de sécurité sanitaire de l'alimentation, de l'environnement et du travail).
342
+
343
+ ## Citation
344
+
345
+ If you use this tool in your research, please cite:
346
+
347
+ ```bibtex
348
+ @software{ciqual_mcp,
349
+ title = {ANSES Ciqual MCP Server},
350
+ author = {GPT Workbench Team},
351
+ year = {2024},
352
+ url = {https://github.com/gpt-workbench/ciqual-mcp}
353
+ }
354
+ ```