NutriScan MCP server in Codex
Nutrition MCP for Codex
Add NutriScan to Codex and the agent can analyze meals, fetch earlier scans and read your credit balance while it writes and tests code. Four lines in config.toml, with the key read from your environment.
The test key is free and returns a sample result. Credit packs start at $49, with no subscription.
[mcp_servers.nutriscan]
url = "https://platform-api.nutriscan.app/mcp"
bearer_token_env_var = "NUTRISCAN_KEY"
tool_timeout_sec = 120Goes in ~/.codex/config.toml. Keep tool_timeout_sec: a scan can take up to 95 seconds.
What can Codex do with NutriScan?
It can run real scans as part of a coding task and use the answers in the code, the data files and the tests it writes.
Generate models from a real result
Have Codex call analyze_meal with your test key and write a Pydantic model or a TypeScript type from the JSON it gets back, with the same field names and units as the API.
Fill in nutrition for a menu file
Point Codex at a menu or recipe file and have it scan each dish as text, such as pancakes with butter and syrup, Kartoffelsalat or quiche lorraine, then write calories and macros back to the file. This needs a live key, about 65 credits a dish.
Check credits before a batch
Ask Codex to call get_usage first and stop if credits_left is lower than the batch needs. The check is free.
How do you set it up?
3 steps, and you need nothing but a free test key to start.
Every option in the MCP server docs, including curl.
Get a test key
Sign in at platform.nutriscan.app with your email and a 6-digit code. The test key is free.
Set the environment variable
Codex reads the key from the variable named in
bearer_token_env_var, so export it in the shell you start Codex from, or in your shell profile.export NUTRISCAN_KEY="ns_test_..."Add the server to config.toml
Add this block to
~/.codex/config.toml. Codex stops a tool after 60 seconds by default and a scan can take 95, so keeptool_timeout_sec = 120.[mcp_servers.nutriscan] url = "https://platform-api.nutriscan.app/mcp" bearer_token_env_var = "NUTRISCAN_KEY" tool_timeout_sec = 120
How do you check that it works?
Run codex mcp list. The list shows nutriscan with its URL.
Then start Codex and ask it to check your NutriScan credits, which is a free call. With a test key, every scan returns the same sample, grilled chicken with rice and salad at 515 kcal, which confirms the key and the connection.
Example prompts
Write them as you would to a colleague. The agent picks the tool.
"Call analyze_meal for '150 g grilled chicken breast' and write a Pydantic model for the result."
One food, sent as text with an amount.
"For each dish in menu.json, run a text scan and add calories, protein_g, carbs_g and fat_g."
A batch. Ask it to call get_usage first.
"Scan 'une part de quiche lorraine et une salade verte' in French and print the NutriScore and its reason."
language set to fr.
"How many NutriScan credits do I have left?"
get_usage, free.
Troubleshooting
The error codes are listed on errors.
Every call fails with HTTP 401
No key reached the server. NUTRISCAN_KEY was not set in the environment Codex started from. Export it and start Codex again.
A scan stops after 60 seconds
tool_timeout_sec is missing, so Codex uses its 60 second default. Set it to 120.
Calls return invalid_api_key or key_revoked
The variable is set but the key is wrong or revoked. Copy a current key from the console.
What does it cost?
The same credits as the REST API, and nothing for the MCP server itself.
No MCP fee, no seats and no subscription. A scan with a live key costs the same credits as a REST call, about 65 for a typical plate, so a 40-dish menu file is about 2,600 credits, about $2.60. get_scan and get_usage are free, and test scans cost nothing. Build with the test key, since an agent that retries in a loop spends credits fast.
Common questions
Every tool argument and error is in the MCP server docs.
Why set tool_timeout_sec to 120?
Codex stops a tool after 60 seconds by default, and a NutriScan scan can take up to 95 seconds. 120 leaves room for the slowest scans.
Where does Codex keep the API key?
Nowhere. bearer_token_env_var tells Codex which environment variable to read, so config.toml holds only the variable name.
Can Codex look up a food by barcode?
No. There is no barcode or food search tool. Send the food as text with an amount, such as "150 g grilled chicken breast".
Let Codex code against real nutrition data
Sign in with your email, add four lines to config.toml with the test key, and buy credits when you want real scans.
- Test key at sign-up
- Packs from $49
- No subscription
- Credits never expire

