Skip to content

pywry.mcp

MCP (Model Context Protocol) server for exposing PyWry widgets to AI agents.


Server

pywry.mcp.create_server

create_server(settings: MCPSettings | None = None) -> FastMCP

Create and configure the MCP server with PyWry tools and skills.

PARAMETER DESCRIPTION
settings

MCP configuration settings. If None, loads from get_settings().

TYPE: MCPSettings DEFAULT: None

RETURNS DESCRIPTION
FastMCP

Configured FastMCP server instance.

RAISES DESCRIPTION
ImportError

If fastmcp package is not installed.

pywry.mcp.run_server

run_server(transport: str | None = None, port: int | None = None, host: str | None = None, headless: bool | None = None, settings: MCPSettings | None = None) -> None

Run the MCP server.

All parameters override the corresponding MCPSettings values. If not provided, values are loaded from configuration.

PARAMETER DESCRIPTION
transport

Transport type: "stdio", "sse", or "streamable-http".

TYPE: str DEFAULT: None

port

Port for HTTP transports (ignored for stdio).

TYPE: int DEFAULT: None

host

Host for HTTP transports.

TYPE: str DEFAULT: None

headless

Run in headless mode (inline widgets). If None, uses config or PYWRY_HEADLESS.

TYPE: bool DEFAULT: None

settings

MCP configuration settings. If None, loads from get_settings().

TYPE: MCPSettings DEFAULT: None

RAISES DESCRIPTION
ValueError

If unknown transport is specified.


Tool Definitions

pywry.mcp.tools.get_tools

get_tools() -> list[Tool]

Return all MCP tools with complete schemas.

RETURNS DESCRIPTION
list[Tool]

List of all available MCP tools.


Prompts

pywry.mcp.prompts.get_prompts

get_prompts() -> list[Prompt]

Return MCP prompts for agent skills.

RETURNS DESCRIPTION
list of Prompt

All available skill prompts.

pywry.mcp.prompts.get_prompt_content

get_prompt_content(name: str) -> GetPromptResult | None

Get the content for a specific prompt.

PARAMETER DESCRIPTION
name

Prompt name (e.g., 'skill:native').

TYPE: str

RETURNS DESCRIPTION
GetPromptResult or None

Prompt content or None if not found.


Resources

pywry.mcp.resources.get_resources

get_resources() -> list[Resource]

Return all MCP resources.

RETURNS DESCRIPTION
list of Resource

All available MCP resources.

pywry.mcp.resources.get_resource_templates

get_resource_templates() -> list[ResourceTemplate]

Return resource templates for parameterized access.

RETURNS DESCRIPTION
list of ResourceTemplate

Available resource templates.

pywry.mcp.resources.read_resource

read_resource(uri: str) -> str | None

Read resource content by URI.

PARAMETER DESCRIPTION
uri

Resource URI (e.g., 'pywry://component/button').

TYPE: str

RETURNS DESCRIPTION
str or None

Resource content or None if not found.

pywry.mcp.resources.get_component_source

get_component_source(component_name: str) -> str | None

Get source code for a component class from toolbar.py.

PARAMETER DESCRIPTION
component_name

Name of the component (e.g., 'button', 'select').

TYPE: str

RETURNS DESCRIPTION
str or None

Source code of the component class or None if not found.

pywry.mcp.resources.export_widget_code

export_widget_code(widget_id: str) -> str | None

Generate Python code to recreate a widget.

PARAMETER DESCRIPTION
widget_id

ID of the widget to export.

TYPE: str

RETURNS DESCRIPTION
str or None

Python code to recreate the widget or None if not found.

pywry.mcp.resources.read_component_doc

read_component_doc(comp_name: str) -> str | None

Read component documentation.

PARAMETER DESCRIPTION
comp_name

Component name.

TYPE: str

RETURNS DESCRIPTION
str or None

Markdown documentation or None if not found.

pywry.mcp.resources.read_source_code

read_source_code(comp_name: str) -> str | None

Read component source code.

PARAMETER DESCRIPTION
comp_name

Component name or 'components' for all.

TYPE: str

RETURNS DESCRIPTION
str or None

Source code or None if not found.

pywry.mcp.resources.read_events_doc

read_events_doc() -> str

Read built-in events documentation.

RETURNS DESCRIPTION
str

Markdown documentation of all built-in events.

pywry.mcp.resources.read_skill_doc

read_skill_doc(skill_name: str) -> str | None

Read skill documentation.

PARAMETER DESCRIPTION
skill_name

Name of the skill.

TYPE: str

RETURNS DESCRIPTION
str or None

Skill documentation or None if not found.

pywry.mcp.resources.read_quickstart_guide

read_quickstart_guide() -> str

Return the quick start guide content.

RETURNS DESCRIPTION
str

Quick start guide markdown.


Builders

pywry.mcp.builders.build_toolbar_item

build_toolbar_item(cfg: dict[str, Any]) -> Any | None

Build a single toolbar item from config dict.

PARAMETER DESCRIPTION
cfg

Configuration dictionary with 'type' and component-specific options.

TYPE: dict[str, Any]

RETURNS DESCRIPTION
Any or None

Toolbar component instance or None if type is unknown.

pywry.mcp.builders.build_toolbars

build_toolbars(toolbars_data: list[dict[str, Any]]) -> list[Any]

Build Toolbar objects from config dicts.

PARAMETER DESCRIPTION
toolbars_data

List of toolbar configurations with 'position' and 'items'.

TYPE: list[dict[str, Any]]

RETURNS DESCRIPTION
list[Any]

Built toolbar instances.


Handler Context

pywry.mcp.handlers.HandlerContext

HandlerContext(args: dict[str, Any], events: EventsDict, make_callback: MakeCallback, headless: bool)

Context object containing shared state for handlers.


MCP Widget State

pywry.mcp.state.get_app

get_app() -> PyWry

Get or create the global PyWry app instance.

Adapts to the rendering environment: - Desktop (PYWRY_HEADLESS=0 or unset): Native windows via WindowMode.NEW_WINDOW - Headless (PYWRY_HEADLESS=1): Inline widgets via WindowMode.BROWSER

RETURNS DESCRIPTION
PyWry

The global PyWry application instance.

pywry.mcp.state.register_widget

register_widget(widget_id: str, widget: Any) -> None

Register a widget.

PARAMETER DESCRIPTION
widget_id

Unique identifier for the widget.

TYPE: str

widget

The widget instance.

TYPE: Any

pywry.mcp.state.store_widget_config

store_widget_config(widget_id: str, config: dict[str, Any]) -> None

Store widget configuration for export.

PARAMETER DESCRIPTION
widget_id

The widget identifier.

TYPE: str

config

The widget configuration.

TYPE: dict[str, Any]

pywry.mcp.state.get_widgets

get_widgets() -> dict[str, Any]

Get all widgets.

RETURNS DESCRIPTION
dict[str, Any]

Dictionary of widget IDs to widget instances.

pywry.mcp.state.get_widget

get_widget(widget_id: str) -> Any | None

Get a widget by ID.

PARAMETER DESCRIPTION
widget_id

The widget identifier.

TYPE: str

RETURNS DESCRIPTION
Any or None

The widget instance or None if not found.

pywry.mcp.state.get_widget_config

get_widget_config(widget_id: str) -> dict[str, Any] | None

Get widget configuration by ID.

PARAMETER DESCRIPTION
widget_id

The widget identifier.

TYPE: str

RETURNS DESCRIPTION
dict or None

The widget configuration or None if not found.

pywry.mcp.state.list_widget_ids

list_widget_ids() -> list[str]

List all active widget IDs.

RETURNS DESCRIPTION
list of str

List of widget identifiers.

pywry.mcp.state.remove_widget

remove_widget(widget_id: str) -> bool

Remove a widget.

PARAMETER DESCRIPTION
widget_id

The widget identifier.

TYPE: str

RETURNS DESCRIPTION
bool

True if widget was removed, False if not found.