Skip to content

Add legacy MCP tools for recent and saved food collections#1

Open
tomerh2001 wants to merge 1 commit into
AdamWalt:mainfrom
tomerh2001:feat/legacy-food-collections
Open

Add legacy MCP tools for recent and saved food collections#1
tomerh2001 wants to merge 1 commit into
AdamWalt:mainfrom
tomerh2001:feat/legacy-food-collections

Conversation

@tomerh2001

Copy link
Copy Markdown

Summary

  • add MCP tools for recent foods, frequent foods, and My Foods
  • fetch those collections through the legacy diary-add AJAX endpoints with fresh CSRF headers
  • document the newer-route logout failure mode and the supported workaround in the README

Why

Newer account routes such as /food/mine, /meal/mine, and /food/new can redirect to /account/logout in this environment even while diary reads and authenticated API token fetches still work. That made simple account-level food list requests slow and brittle to answer manually.

This change gives the MCP first-class tools for those queries and documents the non-obvious legacy path that still behaves reliably.

Notes

I attempted to create a tracking issue in the fork first to follow the normal fork flow, but GitHub Issues are disabled on this repository, so there was no issue to link.

Verification

  • python -m py_compile src/mfp_mcp/server.py
  • exercised mfp_get_recent_foods, mfp_get_frequent_foods, and mfp_get_my_foods locally against a live authenticated session
  • confirmed the new tools returned expected counts and sample items from the account

@tomerh2001 tomerh2001 requested a review from AdamWalt as a code owner April 5, 2026 21:28
@AdamWalt

AdamWalt commented Apr 7, 2026

Copy link
Copy Markdown
Owner

~1,000 lines of new logic covering HTML parsing, write operations, and entry ID matching with no tests. The PR description mentions manual verification against a live session, which is great for smoke testing, but I'd like to see at least unit tests for the pure functions before merging:

  • normalize_food_collection_item — various shapes of the legacy JSON payload
  • resolve_weight_id — matching by label, falling back to selected/first option
  • find_replacement_entry — the progressive fallback logic (meal match, short_name match, name match, singleton)
  • meal_name_to_id / meal_id_to_name — edge cases like "snack" vs "snacks"

These don't need a live MFP session and would catch regressions if MFP changes their HTML structure.

@AdamWalt

AdamWalt commented Apr 7, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution — the code quality here is solid. The entry_id extraction, legacy AJAX endpoint discovery, and the replacement-entry matching logic are useful additions.

A few things I'd like addressed before approving:

  1. Blocker: Thread safety of the create_mfp_client monkey-patch (see comment)
  2. Requested: Unit tests for the pure helper functions (see comment)

Happy to re-review once those are addressed.

sgrimbly added a commit to sgrimbly/myfitnesspal-mcp-python that referenced this pull request Jun 8, 2026
Port the legacy add-page AJAX collections (PR AdamWalt#1 by tomerh2001, adapted):

- mfp_get_recent_foods, mfp_get_frequent_foods, mfp_get_my_foods
- Fetch via POST /food/load_{recent,most_used,my_foods} with meal/base_index/
  page params; these endpoints require X-Requested-With plus the page
  csrf-token meta as X-CSRF-Token (without the params the server returns 406).
- Parse the favorite rows into {name, food_id, default_serving, weight_id}.
  food_id is the classic /food/add id; My Foods are private and do not appear
  in mfp_search_food, so this is the only way to reach them.

Also ignore .DS_Store.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants