cronometer-api-mcp 0.2.5__tar.gz → 0.2.6__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.
Files changed (26) hide show
  1. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/PKG-INFO +3 -3
  2. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/README.md +2 -2
  3. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/pyproject.toml +1 -1
  4. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/server.json +2 -2
  5. cronometer_api_mcp-0.2.6/src/cronometer_api_mcp/barcode.py +60 -0
  6. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/src/cronometer_api_mcp/client.py +36 -2
  7. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/src/cronometer_api_mcp/server.py +14 -0
  8. cronometer_api_mcp-0.2.6/tests/test_barcode.py +68 -0
  9. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/tests/test_client.py +69 -1
  10. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/tests/test_custom_food_edit.py +64 -0
  11. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/uv.lock +9 -9
  12. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/.dockerignore +0 -0
  13. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/.env.example +0 -0
  14. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/.github/dependabot.yml +0 -0
  15. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/.github/workflows/ci.yml +0 -0
  16. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/.github/workflows/docker.yml +0 -0
  17. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/.github/workflows/publish.yml +0 -0
  18. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/.gitignore +0 -0
  19. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/.python-version +0 -0
  20. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/Dockerfile +0 -0
  21. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/LICENSE +0 -0
  22. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/src/cronometer_api_mcp/__init__.py +0 -0
  23. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/tests/test_relative_dates.py +0 -0
  24. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/tests/test_server_import.py +0 -0
  25. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/tests/test_timezone.py +0 -0
  26. {cronometer_api_mcp-0.2.5 → cronometer_api_mcp-0.2.6}/tests/test_totp.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cronometer-api-mcp
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: MCP server for Cronometer nutrition data using the mobile REST API
5
5
  Author: Randy
6
6
  License-Expression: MIT
@@ -154,8 +154,8 @@ cached session, so it also overrides a stale cached timezone.
154
154
  |------|-------------|
155
155
  | `add_food_entry` | Log a food serving to the diary |
156
156
  | `remove_food_entry` | Remove one or more diary entries |
157
- | `add_custom_food` | Create a custom food with specified nutrition |
158
- | `update_custom_food` | Edit a custom food in place: name, nutrition, or serving size |
157
+ | `add_custom_food` | Create a custom food with specified nutrition and optional barcodes |
158
+ | `update_custom_food` | Edit a custom food in place: name, nutrition, serving size, or barcodes |
159
159
  | `delete_custom_food` | Retire a custom food so it leaves search and the Custom Foods list (existing diary entries are kept) |
160
160
  | `add_recipe` | Create a recipe from existing foods referenced by ID and gram weight |
161
161
  | `import_recipe` | Create a recipe from a free-text ingredient list; Cronometer matches each line to a database food and converts the amount to grams |
@@ -134,8 +134,8 @@ cached session, so it also overrides a stale cached timezone.
134
134
  |------|-------------|
135
135
  | `add_food_entry` | Log a food serving to the diary |
136
136
  | `remove_food_entry` | Remove one or more diary entries |
137
- | `add_custom_food` | Create a custom food with specified nutrition |
138
- | `update_custom_food` | Edit a custom food in place: name, nutrition, or serving size |
137
+ | `add_custom_food` | Create a custom food with specified nutrition and optional barcodes |
138
+ | `update_custom_food` | Edit a custom food in place: name, nutrition, serving size, or barcodes |
139
139
  | `delete_custom_food` | Retire a custom food so it leaves search and the Custom Foods list (existing diary entries are kept) |
140
140
  | `add_recipe` | Create a recipe from existing foods referenced by ID and gram weight |
141
141
  | `import_recipe` | Create a recipe from a free-text ingredient list; Cronometer matches each line to a database food and converts the amount to grams |
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cronometer-api-mcp"
7
- version = "0.2.5"
7
+ version = "0.2.6"
8
8
  description = "MCP server for Cronometer nutrition data using the mobile REST API"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/rwestergren/cronometer-api-mcp",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.2.5",
9
+ "version": "0.2.6",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "pypi",
13
13
  "identifier": "cronometer-api-mcp",
14
- "version": "0.2.5",
14
+ "version": "0.2.6",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
@@ -0,0 +1,60 @@
1
+ """Product barcode (EAN, UPC and GTIN) validation for custom foods."""
2
+
3
+ import re
4
+
5
+
6
+ def normalize_barcodes(barcodes: list[str]) -> list[str]:
7
+ """Validate product barcodes and return them as bare digit strings.
8
+
9
+ Accepts the GTIN family the app's scanner reads -- EAN-13, UPC-A (12),
10
+ EAN-8 or UPC-E (8) and GTIN-14 -- including the spaces or dashes the
11
+ digits are printed with under the bars ("0 12345 67890 5"). The check
12
+ digit is verified, so a digit misread off a label is rejected instead of
13
+ saved as a code that never scans. Duplicates are dropped. Bare digit
14
+ strings are what get_food reports for branded foods (["602652270284"]).
15
+ """
16
+ normalized: list[str] = []
17
+ for raw in barcodes:
18
+ code = re.sub(r"[\s-]", "", str(raw))
19
+ if not (code.isascii() and code.isdigit()) or len(code) not in (8, 12, 13, 14):
20
+ raise ValueError(
21
+ f"barcode {raw!r} must be 8, 12, 13 or 14 digits (EAN, UPC or GTIN)"
22
+ )
23
+ if not _has_valid_check_digit(code):
24
+ raise ValueError(
25
+ f"barcode {raw!r} has the wrong check digit (last digit); "
26
+ f"re-check the digits"
27
+ )
28
+ if code not in normalized:
29
+ normalized.append(code)
30
+ return normalized
31
+
32
+
33
+ def _gtin_check_digit(body: str) -> int:
34
+ """GS1 check digit for `body`: weights 3, 1, 3, ... from the right."""
35
+ total = sum(int(d) * (1 if i % 2 else 3) for i, d in enumerate(reversed(body)))
36
+ return -total % 10
37
+
38
+
39
+ def _has_valid_check_digit(code: str) -> bool:
40
+ if _gtin_check_digit(code[:-1]) == int(code[-1]):
41
+ return True
42
+ # An 8-digit code that isn't a valid EAN-8 can still be UPC-E, whose check
43
+ # digit is the one of the 12-digit UPC-A it abbreviates.
44
+ return (
45
+ len(code) == 8
46
+ and code[0] in "01"
47
+ and _gtin_check_digit(_expand_upc_e(code)) == int(code[-1])
48
+ )
49
+
50
+
51
+ def _expand_upc_e(code: str) -> str:
52
+ """The UPC-A digits (check digit excluded) a UPC-E code abbreviates."""
53
+ system, d = code[0], code[1:7]
54
+ if d[5] in "012":
55
+ return system + d[0:2] + d[5] + "0000" + d[2:5]
56
+ if d[5] == "3":
57
+ return system + d[0:3] + "00000" + d[3:5]
58
+ if d[5] == "4":
59
+ return system + d[0:4] + "00000" + d[4]
60
+ return system + d[0:5] + "0000" + d[5]
@@ -27,6 +27,8 @@ from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
27
27
 
28
28
  import httpx
29
29
 
30
+ from .barcode import normalize_barcodes
31
+
30
32
  logger = logging.getLogger(__name__)
31
33
 
32
34
  BASE_URL = "https://mobile.cronometer.com"
@@ -659,6 +661,7 @@ class CronometerClient:
659
661
  extra_nutrients: dict[int, float] | None = None,
660
662
  serving_name: str = "1 serving",
661
663
  serving_grams: float = 100.0,
664
+ barcodes: list[str] | None = None,
662
665
  ) -> dict:
663
666
  """Create a custom food in Cronometer.
664
667
 
@@ -676,9 +679,14 @@ class CronometerClient:
676
679
  Must not reuse an ID already written by the named macro args
677
680
  above; doing so raises ValueError rather than silently
678
681
  duplicating or shadowing an entry.
682
+ barcodes: Product barcodes (EAN/UPC/GTIN) to attach; scanning one
683
+ in the app finds this food. Spaces and dashes are stripped and
684
+ the check digit verified; a bad code raises ValueError.
679
685
 
680
686
  Returns {"food_id": int, "measure_id": int | None}.
681
687
  """
688
+ barcodes = normalize_barcodes(barcodes or [])
689
+
682
690
  # Cronometer stores nutrients per 100g -- normalize from per-serving.
683
691
  scale = 100.0 / serving_grams if serving_grams > 0 else 1.0
684
692
 
@@ -728,19 +736,35 @@ class CronometerClient:
728
736
  "defaultMeasureId": 0,
729
737
  "comments": None,
730
738
  "alternateId": None,
739
+ # The first measure becomes the server-assigned default.
731
740
  "measures": [
732
741
  {
733
742
  "id": 0,
734
743
  "name": serving_name,
735
744
  "value": serving_grams,
736
745
  "amount": 1.0,
737
- "type": "Atomic",
738
- }
746
+ "type": "Weight",
747
+ },
748
+ {
749
+ "id": 0,
750
+ "name": "g",
751
+ "value": 1.0,
752
+ "amount": 1.0,
753
+ "type": "Weight",
754
+ },
755
+ {
756
+ "id": 0,
757
+ "name": "oz",
758
+ "value": _OZ_GRAMS,
759
+ "amount": 1.0,
760
+ "type": "Weight",
761
+ },
739
762
  ],
740
763
  "labelType": "AMERICAN_2016",
741
764
  "nutrients": nutrients,
742
765
  "properties": {},
743
766
  "foodTags": [],
767
+ "barcodes": barcodes,
744
768
  },
745
769
  "config": {"call_version": 1},
746
770
  }
@@ -831,6 +855,7 @@ class CronometerClient:
831
855
  serving_name: str | None = None,
832
856
  serving_grams: float | None = None,
833
857
  serving_quantity: float | None = None,
858
+ barcodes: list[str] | None = None,
834
859
  ) -> dict:
835
860
  """Edit a user-created custom food in place.
836
861
 
@@ -851,6 +876,9 @@ class CronometerClient:
851
876
  reason. A quantity set without serving_grams keeps the total weight,
852
877
  so the per-unit weight changes.
853
878
 
879
+ barcodes replaces the food's whole barcode list ([] clears it) and is
880
+ validated like create_custom_food's.
881
+
854
882
  Returns {"food_id": int, "name": str}.
855
883
  """
856
884
  if extra_nutrients:
@@ -882,9 +910,15 @@ class CronometerClient:
882
910
  if v is not None and not (math.isfinite(v) and v > 0):
883
911
  raise ValueError(f"{label} must be a positive number, got {v!r}")
884
912
 
913
+ if barcodes is not None:
914
+ barcodes = normalize_barcodes(barcodes)
915
+
885
916
  with self._food_lock(food_id):
886
917
  food = self._get_custom_food(food_id)
887
918
 
919
+ if barcodes is not None:
920
+ food["barcodes"] = barcodes
921
+
888
922
  if name is not None:
889
923
  old_name = food.get("name")
890
924
  food["name"] = name
@@ -563,6 +563,7 @@ def get_food_details(food_id: int) -> str:
563
563
  "name": data.get("name"),
564
564
  "default_measure_id": data.get("defaultMeasureId"),
565
565
  "measures": measures,
566
+ "barcodes": data.get("barcodes", []),
566
567
  "nutrients": data.get("nutrients", []),
567
568
  }
568
569
  )
@@ -589,6 +590,7 @@ def add_custom_food(
589
590
  extra_nutrients: dict[int, float] | None = None,
590
591
  serving_name: str = "1 serving",
591
592
  serving_grams: float = 100.0,
593
+ barcodes: list[str] | None = None,
592
594
  ) -> str:
593
595
  """Create a custom food in Cronometer with specified nutrition.
594
596
 
@@ -613,6 +615,12 @@ def add_custom_food(
613
615
  named macro args already cover.
614
616
  serving_name: Name for the serving size (default "1 serving").
615
617
  serving_grams: Weight of one serving in grams (default 100).
618
+ barcodes: Product barcodes (EAN-13, UPC-A, EAN-8, UPC-E or GTIN-14),
619
+ e.g. the digits printed under the bars on the package; spaces and
620
+ dashes are ignored. Scanning one of them in the Cronometer app
621
+ then finds this food (search_foods does not match barcodes). The
622
+ check digit is verified, so a misread digit is rejected rather
623
+ than saved.
616
624
  """
617
625
  try:
618
626
  client = _get_client()
@@ -629,6 +637,7 @@ def add_custom_food(
629
637
  extra_nutrients=extra_nutrients,
630
638
  serving_name=serving_name,
631
639
  serving_grams=serving_grams,
640
+ barcodes=barcodes,
632
641
  )
633
642
 
634
643
  # Fetch back to get the server-assigned measure_id
@@ -663,6 +672,7 @@ def update_custom_food(
663
672
  serving_name: str | None = None,
664
673
  serving_grams: float | None = None,
665
674
  serving_quantity: float | None = None,
675
+ barcodes: list[str] | None = None,
666
676
  ) -> str:
667
677
  """Edit an existing custom food (one you created) in place.
668
678
 
@@ -703,6 +713,9 @@ def update_custom_food(
703
713
  gives "3 cookies = 30 g". To keep the per-unit weight, also pass
704
714
  serving_grams (45 here). Check the result with get_food_details,
705
715
  which lists each measure's quantity.
716
+ barcodes: Replaces the food's barcodes (see add_custom_food for the
717
+ accepted formats); pass [] to remove them all. To add one, pass
718
+ the current barcodes from get_food_details plus the new one.
706
719
  """
707
720
  try:
708
721
  client = _get_client()
@@ -721,6 +734,7 @@ def update_custom_food(
721
734
  serving_name=serving_name,
722
735
  serving_grams=serving_grams,
723
736
  serving_quantity=serving_quantity,
737
+ barcodes=barcodes,
724
738
  )
725
739
  return _ok({"food_id": result["food_id"], "name": result["name"]})
726
740
  except Exception as e:
@@ -0,0 +1,68 @@
1
+ """Tests for barcode validation of custom foods.
2
+
3
+ normalize_barcodes accepts the GTIN family (EAN-13, UPC-A, EAN-8, UPC-E,
4
+ GTIN-14), strips the spaces and dashes codes are printed with, and verifies
5
+ the GS1 check digit so a misread digit is rejected rather than saved.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import pytest
11
+
12
+ from cronometer_api_mcp.barcode import normalize_barcodes
13
+
14
+
15
+ @pytest.mark.parametrize(
16
+ ("raw", "expected"),
17
+ [
18
+ ("4006381333931", "4006381333931"), # EAN-13
19
+ ("602652270284", "602652270284"), # UPC-A (from a real get_food)
20
+ ("0 49000 05010 3", "049000050103"), # UPC-A as printed on a label
21
+ ("9638-5074", "96385074"), # EAN-8
22
+ # UPC-E, one per expansion rule (the sixth digit picks it). The first
23
+ # three aren't valid EAN-8s, so only the UPC-E check accepts them;
24
+ # under rule 5-9 the two check digits always coincide.
25
+ ("04252614", "04252614"), # -> UPC-A 042100005264
26
+ ("01234531", "01234531"), # -> UPC-A 012300000451
27
+ ("01234543", "01234543"), # -> UPC-A 012340000053
28
+ ("01234565", "01234565"), # -> UPC-A 012345000065
29
+ ("10012345678902", "10012345678902"), # GTIN-14
30
+ ],
31
+ )
32
+ def test_normalize_barcodes_accepts_gtin_family(raw, expected):
33
+ assert normalize_barcodes([raw]) == [expected]
34
+
35
+
36
+ @pytest.mark.parametrize(
37
+ "raw",
38
+ [
39
+ "4006381333932", # EAN-13, last digit off by one
40
+ "602652270285", # UPC-A, wrong check digit
41
+ "04252615", # neither a valid EAN-8 nor a valid UPC-E
42
+ "24252618", # UPC-E check digit, but UPC-E only has number systems 0, 1
43
+ "01234566", # rule 5-9: wrong check digit as EAN-8 and as UPC-E
44
+ ],
45
+ )
46
+ def test_normalize_barcodes_rejects_wrong_check_digit(raw):
47
+ with pytest.raises(ValueError, match="check digit"):
48
+ normalize_barcodes([raw])
49
+
50
+
51
+ @pytest.mark.parametrize(
52
+ "raw",
53
+ [
54
+ "",
55
+ "12345", # no GTIN has 5 digits
56
+ "400638133393a",
57
+ "4006381333931", # full-width digits: isdigit() but not ASCII
58
+ ],
59
+ )
60
+ def test_normalize_barcodes_rejects_malformed(raw):
61
+ with pytest.raises(ValueError, match="must be 8, 12, 13 or 14 digits"):
62
+ normalize_barcodes([raw])
63
+
64
+
65
+ def test_normalize_barcodes_drops_duplicates():
66
+ assert normalize_barcodes(["4006381333931", "4006 3813 3393 1"]) == [
67
+ "4006381333931"
68
+ ]
@@ -868,10 +868,40 @@ def test_import_recipe_rejects_blank_input(tmp_path, monkeypatch):
868
868
 
869
869
 
870
870
  # ---------------------------------------------------------------------------
871
- # create_custom_food: extra_nutrients
871
+ # create_custom_food
872
872
  # ---------------------------------------------------------------------------
873
873
 
874
874
 
875
+ @pytest.mark.parametrize("serving_grams", [100.0, 200.0])
876
+ def test_create_custom_food_supports_weight_units(tmp_path, serving_grams):
877
+ client, state = make_cold_client(tmp_path, [{"result": "SUCCESS", "id": 555}])
878
+
879
+ client.create_custom_food(
880
+ "Test Food",
881
+ calories=200,
882
+ protein_g=10,
883
+ fat_g=5,
884
+ carbs_g=20,
885
+ serving_name="plate",
886
+ serving_grams=serving_grams,
887
+ )
888
+
889
+ data = state["payloads"][0]["data"]
890
+ serving, grams, ounces = data["measures"]
891
+ assert [m["name"] for m in data["measures"]] == ["plate", "g", "oz"]
892
+ assert all(m["type"] == "Weight" for m in data["measures"])
893
+ assert all(m["amount"] == 1.0 for m in data["measures"])
894
+ assert serving["value"] == serving_grams
895
+ assert grams["value"] == 1.0
896
+ assert ounces["value"] == pytest.approx(28.3495231)
897
+
898
+ nutrients = {n["id"]: n["amount"] for n in data["nutrients"]}
899
+ assert nutrients[208] == 200 * 100 / serving_grams
900
+ assert nutrients[203] == 10 * 100 / serving_grams
901
+ assert nutrients[204] == 5 * 100 / serving_grams
902
+ assert nutrients[205] == 20 * 100 / serving_grams
903
+
904
+
875
905
  def test_create_custom_food_extra_nutrients_payload(tmp_path):
876
906
  """extra_nutrients are appended, normalized to per-100g like the macros."""
877
907
  client, state = make_cold_client(tmp_path, [{"result": "SUCCESS", "id": 555}])
@@ -908,6 +938,44 @@ def test_create_custom_food_extra_nutrients_overlap_raises(tmp_path):
908
938
  )
909
939
 
910
940
 
941
+ # ---------------------------------------------------------------------------
942
+ # create_custom_food: barcodes
943
+ # ---------------------------------------------------------------------------
944
+
945
+
946
+ def _create_test_food(client, **kwargs):
947
+ return client.create_custom_food(
948
+ "Test Food", calories=200, protein_g=10, fat_g=5, carbs_g=20, **kwargs
949
+ )
950
+
951
+
952
+ def test_create_custom_food_sends_normalized_barcodes(tmp_path):
953
+ """Barcodes go out as the food's `barcodes` list of bare digit strings,
954
+ the shape get_food reports for branded foods."""
955
+ client, state = make_cold_client(tmp_path, [{"result": "SUCCESS", "id": 555}])
956
+
957
+ _create_test_food(client, barcodes=["0 49000 05010 3", "4006381333931"])
958
+
959
+ data = state["payloads"][0]["data"]
960
+ assert data["barcodes"] == ["049000050103", "4006381333931"]
961
+
962
+
963
+ def test_create_custom_food_without_barcodes_sends_empty_list(tmp_path):
964
+ client, state = make_cold_client(tmp_path, [{"result": "SUCCESS", "id": 555}])
965
+
966
+ _create_test_food(client)
967
+
968
+ assert state["payloads"][0]["data"]["barcodes"] == []
969
+
970
+
971
+ def test_create_custom_food_bad_barcode_raises_before_request(tmp_path):
972
+ client, state = make_cold_client(tmp_path, [{"result": "SUCCESS", "id": 555}])
973
+
974
+ with pytest.raises(ValueError, match="check digit"):
975
+ _create_test_food(client, barcodes=["4006381333932"])
976
+ assert state["payloads"] == []
977
+
978
+
911
979
  def test_enrich_diary_no_servings_skips_lookup(tmp_path):
912
980
  client = _enrich_client(tmp_path)
913
981
  calls = {"n": 0}
@@ -168,6 +168,34 @@ def test_update_custom_food_serving_overrides_measure_and_scale(tmp_path):
168
168
  assert nutrients_by_id(state["payloads"][1])[208] == 200.0 # 400 per 200 g
169
169
 
170
170
 
171
+ def test_update_custom_food_preserves_weight_units(tmp_path):
172
+ food = custom_food()
173
+ food["measures"][0]["type"] = "Weight"
174
+ weight_units = [
175
+ {"id": 901, "name": "g", "amount": 1, "value": 1, "type": "Weight"},
176
+ {
177
+ "id": 902,
178
+ "name": "oz",
179
+ "amount": 1,
180
+ "value": 28.3495231,
181
+ "type": "Weight",
182
+ },
183
+ ]
184
+ food["measures"].extend(dict(unit) for unit in weight_units)
185
+ client, state = make_cold_client(tmp_path, [food, OK])
186
+
187
+ client.update_custom_food(
188
+ FOOD_ID, serving_name="plate", serving_grams=200, calories=400
189
+ )
190
+
191
+ data = state["payloads"][1]["data"]
192
+ assert data["defaultMeasureId"] == 900
193
+ assert data["measures"][0]["id"] == 900
194
+ assert data["measures"][0]["value"] == 200
195
+ assert data["measures"][1:] == weight_units
196
+ assert nutrients_by_id(state["payloads"][1])[208] == 200
197
+
198
+
171
199
  def weight_default_food() -> dict:
172
200
  """A food first saved as "400 g": its default measure is 400 units of a
173
201
  Weight measure, which the app renders as "400 <name>"."""
@@ -358,6 +386,42 @@ def test_update_custom_food_extra_nutrients(tmp_path):
358
386
  client2.update_custom_food(FOOD_ID, extra_nutrients={204: 1.0})
359
387
 
360
388
 
389
+ def test_update_custom_food_replaces_barcodes(tmp_path):
390
+ """barcodes replaces the whole list, normalized; nothing else changes."""
391
+ client, state = make_cold_client(tmp_path, [custom_food(barcodes=["96385074"]), OK])
392
+
393
+ client.update_custom_food(FOOD_ID, barcodes=["0 49000 05010 3"])
394
+
395
+ data = state["payloads"][1]["data"]
396
+ assert data["barcodes"] == ["049000050103"]
397
+ assert data["nutrients"] == custom_food()["nutrients"]
398
+ assert data["measures"] == custom_food()["measures"]
399
+
400
+
401
+ def test_update_custom_food_empty_barcodes_clears_them(tmp_path):
402
+ client, state = make_cold_client(tmp_path, [custom_food(barcodes=["96385074"]), OK])
403
+
404
+ client.update_custom_food(FOOD_ID, barcodes=[])
405
+
406
+ assert state["payloads"][1]["data"]["barcodes"] == []
407
+
408
+
409
+ def test_update_custom_food_keeps_barcodes_when_not_passed(tmp_path):
410
+ client, state = make_cold_client(tmp_path, [custom_food(barcodes=["96385074"]), OK])
411
+
412
+ client.update_custom_food(FOOD_ID, name="Renamed")
413
+
414
+ assert state["payloads"][1]["data"]["barcodes"] == ["96385074"]
415
+
416
+
417
+ def test_update_custom_food_rejects_bad_barcode_before_fetch(tmp_path):
418
+ client, state = make_cold_client(tmp_path, [])
419
+
420
+ with pytest.raises(ValueError, match="check digit"):
421
+ client.update_custom_food(FOOD_ID, barcodes=["4006381333932"])
422
+ assert state["payloads"] == []
423
+
424
+
361
425
  def test_update_custom_food_refuses_database_foods(tmp_path):
362
426
  """Only user-created foods may be edited; a database food is rejected
363
427
  before anything is sent to add_food."""
@@ -306,7 +306,7 @@ wheels = [
306
306
 
307
307
  [[package]]
308
308
  name = "mcp"
309
- version = "2.2.0"
309
+ version = "2.3.0"
310
310
  source = { registry = "https://pypi.org/simple" }
311
311
  dependencies = [
312
312
  { name = "anyio" },
@@ -324,22 +324,22 @@ dependencies = [
324
324
  { name = "typing-inspection" },
325
325
  { name = "uvicorn", marker = "sys_platform != 'emscripten'" },
326
326
  ]
327
- sdist = { url = "https://files.pythonhosted.org/packages/76/31/ac54fb0fdd5b37de704486e288bba4fbbb463f24cfcfedbede407b854513/mcp-2.2.0.tar.gz", hash = "sha256:2dc37ecb1974becdcebdbf7561e7c15a07dbbf20ba21ba16c3593b3038b3afbd", size = 4084129, upload-time = "2026-09-07T16:06:23.439Z" }
327
+ sdist = { url = "https://files.pythonhosted.org/packages/9d/8d/e0d339616f4810e9051d4aba6887afab289ab1f81875fe908b606cdfd0e3/mcp-2.3.0.tar.gz", hash = "sha256:8b147a50441cf059dc88c684e0aeed3687f0aa0f39c6cde7b90330effd2b34d8", size = 4171955, upload-time = "2026-10-02T22:06:56.091Z" }
328
328
  wheels = [
329
- { url = "https://files.pythonhosted.org/packages/1b/ff/8e7eade68b8a28f7da0ed1085544341b51f9c935dbf6b95c76b7edfea6a0/mcp-2.2.0-py3-none-any.whl", hash = "sha256:bde982589473a060ae145e3406e9a5333fe538c97229ba841f5a7f92be004f81", size = 365656, upload-time = "2026-09-07T16:06:19.711Z" },
329
+ { url = "https://files.pythonhosted.org/packages/20/d7/4a2878f128df729db3ca04e71bfce26405cc2e0c9ebe19c592feeb4c61b9/mcp-2.3.0-py3-none-any.whl", hash = "sha256:dd0c44c089d16453e8ae31a3877a0054d7a2314caaa81f5e0541b9b1734b2377", size = 368664, upload-time = "2026-10-02T22:06:52.119Z" },
330
330
  ]
331
331
 
332
332
  [[package]]
333
333
  name = "mcp-types"
334
- version = "2.2.0"
334
+ version = "2.3.0"
335
335
  source = { registry = "https://pypi.org/simple" }
336
336
  dependencies = [
337
337
  { name = "pydantic" },
338
338
  { name = "typing-extensions" },
339
339
  ]
340
- sdist = { url = "https://files.pythonhosted.org/packages/ae/91/762d7755d971aff8a28d75f7961656148edf27875c8026e6385aaab08ae7/mcp_types-2.2.0.tar.gz", hash = "sha256:d3ed53703ddd10d9c6399f29d322bb66f3f67ab41348ac8556ba23e07fedefad", size = 65892, upload-time = "2026-09-07T16:06:25.187Z" }
340
+ sdist = { url = "https://files.pythonhosted.org/packages/9e/2d/7c251e34207f6c51000312fc8839111ac45cfe02023f90b44e7f1051dd8e/mcp_types-2.3.0.tar.gz", hash = "sha256:d1e46549edb35ee19a94940fcee6d1addd7e589ab7ea92dda83f5d84781fc362", size = 65898, upload-time = "2026-10-02T22:06:57.863Z" }
341
341
  wheels = [
342
- { url = "https://files.pythonhosted.org/packages/8f/d7/6ffba5d8cd5dd9b8a19478875c50e04945314ba5074e84d749283f27f62d/mcp_types-2.2.0-py3-none-any.whl", hash = "sha256:ea476b73ee86709ab5abc9452385ed36cc05907e582355622e294595c9a04f13", size = 69106, upload-time = "2026-09-07T16:06:21.461Z" },
342
+ { url = "https://files.pythonhosted.org/packages/ce/48/32583066b155bb5d4507e7887dc88ee23118cc4de8e2a12870c49719e2a8/mcp_types-2.3.0-py3-none-any.whl", hash = "sha256:968efdbdaedfab06adae40d378a34395f1090c5921d4be3c9cde283aaf76d91d", size = 69108, upload-time = "2026-10-02T22:06:54.099Z" },
343
343
  ]
344
344
 
345
345
  [[package]]
@@ -643,11 +643,11 @@ wheels = [
643
643
 
644
644
  [[package]]
645
645
  name = "tzdata"
646
- version = "2026.4"
646
+ version = "2026.5"
647
647
  source = { registry = "https://pypi.org/simple" }
648
- sdist = { url = "https://files.pythonhosted.org/packages/e4/31/3d74fa778a63b98b7374323befcc0be5ab3bd94afd4096a0124e7379152c/tzdata-2026.4.tar.gz", hash = "sha256:f1b8bd365d8d210c55353f4d7f8d6d8561c0ba50d704b700d195a9424bba0d79", size = 199350, upload-time = "2026-09-12T12:56:03.251Z" }
648
+ sdist = { url = "https://files.pythonhosted.org/packages/d9/68/f1b440335057bfce71b6e50a9d09445aa2ecbd08359a337976627b8409e7/tzdata-2026.5.tar.gz", hash = "sha256:8cc73c0a0bfca7dbfa59235d60b2eff82231dee33f53d206db1acd9173cfc0a7", size = 200404, upload-time = "2026-10-03T09:23:14.143Z" }
649
649
  wheels = [
650
- { url = "https://files.pythonhosted.org/packages/f9/bc/8737e8d54cf51106118039b83f485a4783112fab49ea9d044b234978a46e/tzdata-2026.4-py2.py3-none-any.whl", hash = "sha256:c2169a8b0a7a5e9674da5a135ccdfb2b3e671b333ed9fed17b41f73c34476e81", size = 347494, upload-time = "2026-09-12T12:56:01.67Z" },
650
+ { url = "https://files.pythonhosted.org/packages/94/21/1e5995a1c920cce14e4bffae20c665ec10e7ed03ab25e006cd741092b718/tzdata-2026.5-py2.py3-none-any.whl", hash = "sha256:b683bd1b6659ddcd810ff02ad09ba821d4bf1065072805063eb35c49617905ac", size = 347996, upload-time = "2026-10-03T09:23:12.535Z" },
651
651
  ]
652
652
 
653
653
  [[package]]