Skip to content

flet-mcp: token-efficient get_api, ranked icon search, agent tool fixes#6654

Merged
FeodorFitsner merged 3 commits into
flet-0.86from
feature/flet-mcp-agent-tools
Jul 7, 2026
Merged

flet-mcp: token-efficient get_api, ranked icon search, agent tool fixes#6654
FeodorFitsner merged 3 commits into
flet-0.86from
feature/flet-mcp-agent-tools

Conversation

@FeodorFitsner

@FeodorFitsner FeodorFitsner commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Fix #6655

What

Overhauls flet-mcp's tool outputs for LLM-agent consumption — smaller, correct, and searchable — based on token/trace analysis of real agent sessions in Flet Studio.

get_api

  • Default response is compact signature-style text (~44% smaller than the JSON encoding, tokenizes better); format="json" escape hatch for programmatic consumers; errors stay JSON
  • Member docstrings trimmed to their first sentence; member=<name> drill-down returns full docs; query=<substring> filters members walking base classes (e.g. TextField's border props live on FormFieldControl)
  • Event handler types unwrapped: Optional[EventHandler[TapEvent[GestureDetector]]]on_tap(TapEvent); Optional[X]X?; field(...) defaults unwrapped
  • Bug fix: fields member section (dataclass types, event payloads) was dropped from responses — TextStyle returned a bare one-liner
  • Bug fix: name collisions resolved by ranked candidates instead of dict last-wins — Text/Image/Rect were silently shadowed by canvas shapes; dotted names (canvas.Text, flet_map.Camera) select alternates, and responses note them
  • Sphinx :attr:/:class: roles stripped from rendered docstrings

Other tools

  • get_example pages large examples per file (largest bundled example is 111k chars); get_doc capped with a narrowing hint
  • search_enum_members ranked exact → prefix → substring with Material style variants (_OUTLINED/_ROUNDED/_SHARP) collapsed — "remove" now surfaces REMOVE, not five BOOKMARK_REMOVE variants

Icon search

  • Bug fix: find_icon was broken on runtime-only installs — IconStore imported the flet package for icon names; it now sources them from the bundled api.json
  • Synonym search rebuilt on Google's fonts.google.com icon metadata (tags + popularity, Apache-2.0), committed as data/icons.json, refreshed via python -m flet_mcp.build.icons; hand-curated icons.yml and the pyyaml dependency removed
  • Deterministic ranking (score → popularity → name) with golden-query regression tests: minusREMOVE, trashDELETE, gearSETTINGS, …

Tests

39 tests in new packages/flet-mcp/tests/ (ApiStore rendering/collisions/query, IconStore ranking/golden queries). Verified live against a running Flet Studio agent: get_api fetches dropped from ~20k chars to ~1k avg per call, and icon lookups resolve first-try where they previously errored and fell back.

Summary by Sourcery

Revamp flet-mcp tooling for LLM agents with more compact API output, robust member querying, and improved icon search backed by committed metadata.

New Features:

  • Provide a text-formatted get_api response with member drill-down, substring-based member filtering, and inherited member discovery, with optional JSON output for programmatic use.
  • Add paging for large examples in get_example via per-file retrieval and introduce size-capped get_doc responses with narrowing hints.
  • Introduce an icon search metadata build step that fetches Google fonts icon tags and popularity into a committed icons.json file, and wire IconStore to use bundled enum names plus this metadata instead of the flet package.

Bug Fixes:

  • Fix missing type field listings in get_api responses for dataclass and event payload types.
  • Resolve name collisions between symbols like Text by ranking candidates instead of dict overwrites, and support dotted names to access shadowed variants.
  • Fix find_icon on runtime-only installs by removing the dependency on the flet package and sourcing icon names from bundled api.json enums.

Enhancements:

  • Improve enum member search ranking with exact/prefix/substring tiers and collapse Material style variants to avoid result spam.
  • Normalize and trim docstrings, including Sphinx roles, for more concise API listings and notes guiding deeper inspection.
  • Refine icon search ranking to be deterministic and popularity-aware, and collapse style variants when their base icon is present.

Build:

  • Remove the pyyaml dependency from flet-mcp now that icon synonym data is sourced from generated JSON instead of YAML.

CI:

  • Exclude the committed icons.json metadata file from typo checking in both typos config and pre-commit hooks to avoid noisy false positives.

Deployment:

  • Ensure web builds inject app/app.zip assets into pubspec at build time while native builds rely on unpacked bundles, simplifying Flutter template configuration.

Documentation:

  • Document the committed nature and refresh process of icons.json in the flet-mcp README and build indexer docs.

Tests:

  • Add a dedicated flet-mcp test suite covering ApiStore rendering, member filtering and collision handling, and IconStore ranking, synonym behavior, and golden icon queries.

Chores:

  • Clean up Flutter pubspec templates by removing stale commented geolocator snippets and clarifying asset injection behavior.

get_api:
- default response is compact signature-style text (~44% smaller than
  JSON, tokenizes better); format="json" escape hatch
- member docstrings trimmed to first sentence; member=<name> drill-down
  returns full docs; query=<substring> filters members, walking base
  classes (TextField border props live on FormFieldControl)
- event handler types unwrapped (Optional[EventHandler[TapEvent[...]]]
  -> on_tap(TapEvent)); Optional[X] -> X?; field(...) defaults unwrapped
- "fields" member section (dataclass types, event payloads) now included
- name collisions resolved by ranked candidates instead of last-wins:
  Text/Image/Rect no longer shadowed by canvas shapes; dotted names
  (canvas.Text, flet_map.Camera) select alternates; response notes them
- Sphinx :attr:/:class: roles stripped from all rendered docstrings

get_example pages large examples per file; get_doc capped with a
narrowing hint; search_enum_members ranked (exact/prefix/substring)
with Material style variants collapsed.

Icon search rebuilt on Google's fonts.google.com icon metadata (tags +
popularity, Apache-2.0), committed as data/icons.json and refreshed via
`python -m flet_mcp.build.icons`; hand-curated icons.yml and the pyyaml
dependency removed. IconStore no longer imports the flet package
(find_icon was broken on runtime-only installs) and ranks by
tags/popularity with golden-query regression tests.
…ents pubspec

The build template's pubspec.yaml guarded the web-only `assets:` section
(app/app.zip, app/app.zip.hash) with Jinja tags hidden in YAML comments.
Any tooling that round-trips the file with a YAML parser — like the CI
release patch script — strips comments, making the assets unconditional
and failing native builds on the missing app/app.zip.

Move the conditionality into flet build: the template pubspec is now
plain YAML, and build_base.py injects flutter.assets into the rendered
pubspec when config_platform is "web", in the same post-cookiecutter
patching pass as the local-dev and test-mode overrides. Native platforms
get no assets entry, as before — serious_python places the app inside
the bundle.

Also remove the vestigial flet_geolocator Jinja block: its dependencies
were themselves commented out, so it could never take effect.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 981befa
Status: ✅  Deploy successful!
Preview URL: https://2b671c39.flet-website-v2.pages.dev
Branch Preview URL: https://feature-flet-mcp-agent-tools.flet-website-v2.pages.dev

View logs

A second top-level `tests` package collides with packages/flet/tests
under pytest's prepend import mode — whichever imports first owns
`tests` in sys.modules and the other's modules fail collection. Without
the __init__.py, pytest names the modules by file (unique basenames),
which is what `pytest packages/*/tests` in CI needs.
@FeodorFitsner FeodorFitsner merged commit 1ba0abe into flet-0.86 Jul 7, 2026
121 of 139 checks passed
@FeodorFitsner FeodorFitsner deleted the feature/flet-mcp-agent-tools branch July 7, 2026 23:58
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.

1 participant