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:
|
| 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:
|
port
|
Port for HTTP transports (ignored for stdio).
TYPE:
|
host
|
Host for HTTP transports.
TYPE:
|
headless
|
Run in headless mode (inline widgets). If None, uses config or PYWRY_HEADLESS.
TYPE:
|
settings
|
MCP configuration settings. If None, loads from get_settings().
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If unknown transport is specified. |
Tool Definitions¶
pywry.mcp.tools.get_tools
¶
Return all MCP tools with complete schemas.
| RETURNS | DESCRIPTION |
|---|---|
list[Tool]
|
List of all available MCP tools. |
Prompts¶
pywry.mcp.prompts.get_prompts
¶
Return MCP prompts for agent skills.
| RETURNS | DESCRIPTION |
|---|---|
list of Prompt
|
All available skill prompts. |
pywry.mcp.prompts.get_prompt_content
¶
Get the content for a specific prompt.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Prompt name (e.g., 'skill:native').
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
GetPromptResult or None
|
Prompt content or None if not found. |
Resources¶
pywry.mcp.resources.get_resources
¶
Return all MCP resources.
| RETURNS | DESCRIPTION |
|---|---|
list of Resource
|
All available MCP resources. |
pywry.mcp.resources.get_resource_templates
¶
Return resource templates for parameterized access.
| RETURNS | DESCRIPTION |
|---|---|
list of ResourceTemplate
|
Available resource templates. |
pywry.mcp.resources.read_resource
¶
Read resource content by URI.
| PARAMETER | DESCRIPTION |
|---|---|
uri
|
Resource URI (e.g., 'pywry://component/button').
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str or None
|
Resource content or None if not found. |
pywry.mcp.resources.get_component_source
¶
Get source code for a component class from toolbar.py.
| PARAMETER | DESCRIPTION |
|---|---|
component_name
|
Name of the component (e.g., 'button', 'select').
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str or None
|
Source code of the component class or None if not found. |
pywry.mcp.resources.export_widget_code
¶
Generate Python code to recreate a widget.
| PARAMETER | DESCRIPTION |
|---|---|
widget_id
|
ID of the widget to export.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str or None
|
Python code to recreate the widget or None if not found. |
pywry.mcp.resources.read_component_doc
¶
Read component documentation.
| PARAMETER | DESCRIPTION |
|---|---|
comp_name
|
Component name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str or None
|
Markdown documentation or None if not found. |
pywry.mcp.resources.read_source_code
¶
Read component source code.
| PARAMETER | DESCRIPTION |
|---|---|
comp_name
|
Component name or 'components' for all.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str or None
|
Source code or None if not found. |
pywry.mcp.resources.read_events_doc
¶
Read built-in events documentation.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Markdown documentation of all built-in events. |
pywry.mcp.resources.read_skill_doc
¶
Read skill documentation.
| PARAMETER | DESCRIPTION |
|---|---|
skill_name
|
Name of the skill.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str or None
|
Skill documentation or None if not found. |
pywry.mcp.resources.read_quickstart_guide
¶
Return the quick start guide content.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Quick start guide markdown. |
Builders¶
pywry.mcp.builders.build_toolbar_item
¶
Build a single toolbar item from config dict.
| PARAMETER | DESCRIPTION |
|---|---|
cfg
|
Configuration dictionary with 'type' and component-specific options.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any or None
|
Toolbar component instance or None if type is unknown. |
pywry.mcp.builders.build_toolbars
¶
Build Toolbar objects from config dicts.
| PARAMETER | DESCRIPTION |
|---|---|
toolbars_data
|
List of toolbar configurations with 'position' and 'items'.
TYPE:
|
| 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 a widget.
| PARAMETER | DESCRIPTION |
|---|---|
widget_id
|
Unique identifier for the widget.
TYPE:
|
widget
|
The widget instance.
TYPE:
|
pywry.mcp.state.store_widget_config
¶
Store widget configuration for export.
| PARAMETER | DESCRIPTION |
|---|---|
widget_id
|
The widget identifier.
TYPE:
|
config
|
The widget configuration.
TYPE:
|
pywry.mcp.state.get_widgets
¶
Get all widgets.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of widget IDs to widget instances. |
pywry.mcp.state.get_widget
¶
Get a widget by ID.
| PARAMETER | DESCRIPTION |
|---|---|
widget_id
|
The widget identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any or None
|
The widget instance or None if not found. |
pywry.mcp.state.get_widget_config
¶
Get widget configuration by ID.
| PARAMETER | DESCRIPTION |
|---|---|
widget_id
|
The widget identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict or None
|
The widget configuration or None if not found. |
pywry.mcp.state.list_widget_ids
¶
List all active widget IDs.
| RETURNS | DESCRIPTION |
|---|---|
list of str
|
List of widget identifiers. |
pywry.mcp.state.remove_widget
¶
Remove a widget.
| PARAMETER | DESCRIPTION |
|---|---|
widget_id
|
The widget identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if widget was removed, False if not found. |