Skip to main content

anywidget-mcp

PyPI License: MIT

anywidget-mcp runs AnyWidgets inside AI conversations. Interact with a Python widget, then let the model respond to its current state. Connect through a host that supports MCP Apps, the Model Context Protocol extension for interactive interfaces.

It also exposes widgets already running in a notebook as WebMCP tools for browser agents, including notebooks running Python in WebAssembly.

Choose a color, then explore an interactive HEX-to-RGB explanation

  • Bring existing widgets. Serve widgets from a package or reuse the ones you develop in Jupyter and marimo.
  • Accept conversational input. Typed Python factories become tools that create a fresh widget for each call.
  • Share selected state. Python validates interactions, and you choose which values the model can read.
  • Explore large datasets. Serve query-backed viewers such as Embedding Atlas and share their current filter with the model.
  • Compose interfaces. Expose several tools, return a group of widgets, or create widgets from source in a sandbox.

Try it

Requires Python 3.10+ and uv, a Python package runner:

uvx --from 'anywidget-mcp[server]' --with wigglystuff anywidget-mcp serve wigglystuff:ColorPicker --port 8010

Connect your MCP Apps host to http://127.0.0.1:8010/mcp, ask to pick a color, and change the selection. Getting started walks through this in Inspector Chat.

Use Python

Install in the environment that owns your widgets:

uv pip install 'anywidget-mcp[server]' wigglystuff
from anywidget_mcp.server import serve
from wigglystuff import ColorPicker

serve(ColorPicker, state="color")

state="color" gives the model the current color while the full widget remains interactive. Use AnyWidgetMCP to register several tools or attach() to add widgets to an existing server. Register with @mcp.widget(reopen="manual") to offer Reopen for saved results, or reopen="auto" to recreate them on remount without adding recovery controls. Use reopen_ui=True to add fallback controls to automatic mode. Each reopening calls the factory with saved inputs and owns a fresh session. See Reopen saved results.

Use a browser agent

Install anywidget-mcp in your notebook environment, then enable WebMCP:

from anywidget_mcp import webmcp

webmcp.enable()

Current and future AnyWidgets expose read and update tools. Python validates updates and runs observers before returning state. The notebook host keeps rendering and synchronizing its widgets, including when Python runs in Pyodide, a Python runtime for the browser.

Pass installed widget classes or typed creation functions to offer tools that create new widgets. With wigglystuff installed:

from wigglystuff import ColorPicker

webmcp.enable(widgets=[ColorPicker], discover=False)

Display the returned session as the cell's final expression. Browser tool calls create widgets inside its output. discover=False includes supplied instances and widgets created through the session. Use a mapping in widgets= to configure private or read-only traits per class, function, or instance.

Requires a WebMCP-enabled browser and a compatible AnyWidget 0.11+ frontend. webmcp.disable() withdraws tools and leaves widgets open. WebMCP covers creation signatures, state exposure, host permissions, and composition with MCP Apps.

Documentation

Getting started · Write a widget · Pass input · Share state · WebMCP · API reference · Deployment

Experimental software. The API may change between releases.

Metadata

Release files for anywidget-mcp 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anywidget-mcp 0.2.1
File Size Uploaded
anywidget_mcp-0.2.1.tar.gz 193.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anywidget-mcp 0.2.1
File Interpreter ABI Platform
anywidget_mcp-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 406.2 kB

Release files / anywidget_mcp-0.2.1.tar.gz

Download URL anywidget_mcp-0.2.1.tar.gz
Size 193.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1659a9c1bccaa754f0bc8aa7278d35039eaeee2bd8cc03fa479736d3bf5f983f
BLAKE2b-256 checksum
How to use checksums
8d849767ee4d13189d023b47b1252d92b3193b13213eae97340ef17a49f493c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / anywidget_mcp-0.2.1-py3-none-any.whl

Download URL anywidget_mcp-0.2.1-py3-none-any.whl
Size 212.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27770dec9f7afa8c4163d6ff92a308d000fe2f5ef75857823a2d43b120548119
BLAKE2b-256 checksum
How to use checksums
1470c0b9d9c3e7de5354a95c0495276f4b11bb4b468db8734ee84e82e4ec6050
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page