Skip to content

Add flet-mcp: MCP server for LLM agents - #6624

Merged
FeodorFitsner merged 17 commits into
flet-0.86from
flet-mcp
Jul 1, 2026
Merged

Add flet-mcp: MCP server for LLM agents#6624
FeodorFitsner merged 17 commits into
flet-0.86from
flet-mcp

Conversation

@FeodorFitsner

@FeodorFitsner FeodorFitsner commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the flet-mcp package — an MCP server that gives LLM agents Flet API, icons, examples, docs, and CLI lookups — rebased onto flet-0.86 and verified end to end.

Tool groups gate on FLET_MCP_ENABLE_* (API + icons on by default; examples, docs, CLI off).

What works (verified)

  • APIapi.json built via Griffe against the 0.86 source: 249 controls, 91 events, 201 types, 149 enums, 13 CLI commands. Spot-checked.
  • Iconsfind_icon with synonym matching.
  • Examples — 519 indexed; search ranking, get_example round-trip, and platform filter all validated against the current [tool.flet.metadata] / [tool.flet].platforms layout.
  • CLIget_cli_help from the flet_cli parser.
  • In-process usefrom flet_mcp import mcp + fastmcp.Client(mcp) exercised across all 11 tools.

Docs tools — deferred

The docs indexer parses a mkdocs search_index.json that the site no longer produces after the Docusaurus + Algolia migration. The DOCS group stays off and now degrades gracefully (table guards return empty results instead of crashing). README and the --docs CLI help note the deferral. Rebuilding docs search against Docusaurus is tracked as follow-up.

CI / packaging

  • New build_flet_mcp job builds the indexes (flet mcp build --examples) then uv build --package flet-mcp.
  • Feeds the release job and flet_mcp is included in the py_publish loop.
  • Verified the built wheel bundles data/api.json and data/mcp.db (via package-data = data/*).

Notes

  • api.json and mcp.db are gitignored build artifacts, generated at packaging time.

Summary by Sourcery

Introduce a new flet-mcp MCP server package for Flet, integrate its build and publication into the Python SDK and CI, and add metadata hooks for richer API indexing and MCP discovery.

New Features:

  • Add the flet-mcp package providing an MCP server with tools for Flet API, icons, examples, docs, and CLI integration.
  • Expose an MCP-focused CLI command flet mcp with build and serve subcommands and optional in-process usage via FastMCP.
  • Add optional MCP metadata (categories, tags) to controls like TextField, Column, Row, Checkbox, and Tabs for better discovery.

Enhancements:

  • Extend gradient color handling to accept generic color values instead of plain strings.
  • Clarify and slightly expand color usage documentation, including named colors and opacity behavior.
  • Wire flet-mcp as a workspace member and dependency in the Python SDK, including a dedicated mcp-build dependency group and isort config updates.

Build:

  • Add a dedicated build_flet_mcp CI job that builds MCP data, packages the flet-mcp wheel, and uploads artifacts.
  • Include flet-mcp in the release and publishing workflows so it is built and published alongside other Python packages.

Documentation:

  • Tweak colors cookbook docs for formatting and to clarify named color identifiers and opacity helper usage.

FeodorFitsner and others added 12 commits June 29, 2026 14:48
Introduce a new flet-mcp Python package (pyproject, README, package code and data) providing an MCP server for LLM agents, including ApiStore and bundled icons/docs data. Integrate flet-mcp into the CLI by registering an optional "mcp" subcommand only when the package is installed and add an optional dependency entry in flet-cli's pyproject. Update GitHub Actions to build, package, and publish flet-mcp (new build_flet_mcp job and inclusion in the publish step). Also add .gitignore for generated MCP artifacts and include various minor Python package updates.
Introduce a new flet_mcp build subpackage and tooling to generate MCP data. Adds api.py (API reference builder using Griffe, injects icon enums and extracts CLI help), docs.py (mkdocs search_index -> SQLite FTS5 indexer), examples.py (pyproject.toml-based examples indexer), and indexer.py (orchestrator that runs examples/docs/API pipelines and writes mcp.db/api.json). Update .gitignore to un-ignore the build subpackage and tweak icons.yml comment/content.
Defaults: API and ICONS groups on, EXAMPLES/DOCS/CLI off, so the
hallucination-reduction starter set is what consumers get out of the
box. Server instructions enumerate the active groups so the model sees
only relevant guidance.
Adds a 'Toggling groups' section to the package README explaining
which tool groups are on by default, the env var per group, and how
the active set is surfaced to MCP clients via the server's
initialize instructions.
… async methods, classify @value as dataclass

- Single get_api(name) tool replaces get_control_api + get_type_api. Looks
  across controls, services, dataclass types, and events and tags every
  match with a 'kind' discriminator ('control'/'service'/'type'/'event').
  One tool means one lookup instead of multiple guess-the-bucket attempts.

- Methods declared async def are now marked '"async": true' in the api.json
  methods list. The get_api tool docstring and the FastMCP server
  instructions both call this out, so callers know to await them (e.g.
  page.window.center() is async — handler must be async def).

- Treat Flet's @value decorator as a dataclass in the API builder. Most
  styling/value classes (ButtonStyle, Padding, ...) use @value, so prior
  builds were missing 70% of them. Type count: 28 -> 199.
Page extends BasePage, which extends BaseControl, but the classifier
only matched direct inheritance from BaseControl/LayoutControl/
AdaptiveControl/Service. Adding BasePage to the known control bases
catches Page itself (the most-used class in Flet). Controls: 166 -> 168
(Page + anything else inheriting from BasePage).
get_api responses now carry a 'package' field naming the pip-installable
package the class lives in. Derived from the first segment of 'module'
with underscores swapped for hyphens — so flet_video -> flet-video,
flet_audio -> flet-audio, etc. Core flet classes stay 'flet'.

Agents can now route 'use Video' to 'first add flet-video to deps'
without having to guess the distribution name from the import path.
The tool docstring, FastMCP server instructions, and README all call
this out so consumers know to surface it to the user.
…, mark deprecated classes

Three related changes to make get_api the true universal verifier:

1. _is_control_class now walks the inheritance chain through a global
   class-name registry built in a pre-pass over all loaded packages.
   Catches transitive subclasses of BaseControl/LayoutControl/
   AdaptiveControl/Service through intermediate bases (DialogControl,
   BasePage, ...) without hardcoding every link. AlertDialog, BottomSheet,
   SnackBar, Banner, Page, and ~80 other previously-missed controls now
   resolve. Controls indexed: 168 -> 248. BasePage drops out of the
   hardcoded base set since it's no longer needed.

2. api_store.get() now falls through to enums after controls/types/events.
   Calling get_api('MainAxisAlignment') returns the enum directly instead
   of 'not found' (it used to force a separate get_enum round-trip). Large
   enums (Icons, CupertinoIcons) come back truncated, same as get_enum.

3. Deprecated classes are kept in the index but marked with a
   'deprecated' object carrying reason/version/delete_version parsed from
   @deprecated_class. ElevatedButton now answers with
   'deprecated: {reason: "Use Button instead."}' — the model sees both
   the verdict and the replacement in one shot.
for Gradient, list[ColorValue] instead of list[str]
…n-process use

- Add table guards to search_docs/get_doc so they return empty results
  instead of crashing when no docs index is built
- Mark the docs index as deferred (mkdocs search_index.json no longer
  produced after the Docusaurus + Algolia migration) in README and the
  --docs CLI help
- Document in-process FastMCP usage via fastmcp.Client(mcp); fix stale
  get_control_api reference (now get_api) and bump the Pydantic AI model

@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 Jun 30, 2026

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 23ba2b0
Status: ✅  Deploy successful!
Preview URL: https://95448859.flet-website-v2.pages.dev
Branch Preview URL: https://flet-mcp.flet-website-v2.pages.dev

View logs

The CLI docs index auto-lists every registered command (including the new
'mcp' command), so the Docusaurus build failed on a broken link to a missing
flet-mcp page. Add the cli/flet-mcp.md stub (importing the generated
cli-mcp.mdx partial) and the sidebar entry, matching the other commands.
isolated: If `True`, marks the control as isolated. An isolated control
is excluded from page updates when its parent control is updated.
post_init_args: Number of InitVar arguments to pass to __post_init__.
categories: MCP metadata — control categories (e.g. ``("input", "form")``).

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.

single backsticks instead of double



@control("Tabs")
@control("Tabs", categories=("navigation", "layout"), tags=("tabbed", "switcher"))

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.

Hum, so we will have to do this for all controls?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's experimental. As AI is a non-deterministic, we currently don't know what would really help it to do better decisions. If these categories help - we will annotate all controls; if it happens to be a "noise" - we'll remove.

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.

will be nice to show this in documentation too - just like we do for extensions atm.
from what i see we currently only display the cli help.

Explain how to install and run the flet-mcp server, configure it in AI
clients, toggle tool groups, and consume it from a custom agent via
Pydantic AI or an in-process FastMCP client.
Drop the unprefixed data-channel-protocol-upgrade.md,
default-bundled-python-3-14.md, and removed-pyodide-version-export.md —
identical, unreferenced leftovers of the v0-86-0-* rename. Only the
v0-86-0-prefixed files are linked from the sidebar.
@FeodorFitsner
FeodorFitsner merged commit 540b031 into flet-0.86 Jul 1, 2026
90 of 104 checks passed
@FeodorFitsner
FeodorFitsner deleted the flet-mcp branch July 1, 2026 01:59
@FeodorFitsner FeodorFitsner mentioned this pull request Jul 14, 2026
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.

3 participants