-
Notifications
You must be signed in to change notification settings - Fork 14
Enhancement/mcp apps #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Enhancement/mcp apps #161
Changes from 4 commits
de64ee1
d76e96f
88ea500
477b6bc
5b127f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| { | ||
| "python-envs.defaultEnvManager": "ms-python.python:system", | ||
| "python-envs.pythonProjects": [] | ||
| "python-envs.defaultEnvManager": "ms-python.python:system" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ The Display Server is a component of the HoloViz MCP that enables AI assistants | |
|
|
||
| The Display System uses a decoupled architecture: | ||
|
|
||
| 1. **MCP Server** (your main process): Hosts the `show` tool, connects via HTTP | ||
| 1. **MCP Server** (your main process): Hosts the `show` and `show_pyodide` tools | ||
| 2. **Display Server** (independent process): Executes Python code and serves web pages | ||
| 3. **Browser** (user interface): Displays visualizations and management interfaces | ||
|
|
||
|
|
@@ -22,7 +22,14 @@ When you use the `show` tool: | |
| 3. Display Server stores the snippet in SQLite database | ||
| 4. Display Server executes the code and captures output | ||
| 5. MCP server returns URL to view visualization | ||
| 6. User accesses visualization via URL in browser | ||
| 6. User accesses visualization via URL in browser (or via in-chat MCP App UI when supported) | ||
|
|
||
| When you use the `show_pyodide` tool: | ||
|
|
||
| 1. AI sends code to the MCP server via the tool | ||
| 2. MCP server returns a payload for an MCP App resource | ||
| 3. The host renders the app in a sandboxed iframe | ||
| 4. panel-live runs the code in a browser/Pyodide runtime | ||
|
|
||
| This decoupled architecture means: | ||
|
|
||
|
|
@@ -38,7 +45,7 @@ The `show` MCP tool is the primary interface for creating visualizations. It acc | |
| - **app** (required): Python code to execute | ||
| - **name** (optional): Human-readable title for the visualization | ||
| - **description** (optional): Explanation of what the code does | ||
| - **method** (optional): Execution method - "jupyter" (default) or "panel" | ||
| - **method** (optional): Execution method - "jupyter" (default), "panel", or "pyodide" | ||
|
Comment on lines
43
to
+48
|
||
|
|
||
| The tool returns a response containing: | ||
|
|
||
|
|
@@ -48,6 +55,17 @@ The tool returns a response containing: | |
|
|
||
| The workflow is designed to be simple: send code, get URL, view in browser. | ||
|
|
||
| ## The `show_pyodide` Tool | ||
|
|
||
| The `show_pyodide` MCP tool is a browser-runtime path intended for panel-live/Pyodide rendering. | ||
| It does not depend on display-server code execution. | ||
|
|
||
| It accepts: | ||
|
|
||
| - **code** (required): Python code to run in panel-live | ||
| - **name** (optional): Human-readable title for the app | ||
| - **description** (optional): Explanation of what the code does | ||
|
|
||
| ## Why an Independent Server? | ||
|
|
||
| Running visualizations in an independent server process provides several key benefits: | ||
|
|
@@ -81,7 +99,7 @@ A **snippet** is a stored code sample with metadata. Each snippet has: | |
| - Detected packages and Panel extensions | ||
| - Execution method and timestamp | ||
|
|
||
| The Display System supports two execution methods: | ||
| The Display System supports three execution methods: | ||
|
|
||
| ### Jupyter Method (Default) | ||
|
|
||
|
|
@@ -101,6 +119,11 @@ Executes code that explicitly calls `.servable()` on Panel components. This meth | |
| - Multiple objects can be served | ||
| - Best for complex, interactive applications | ||
|
|
||
| ### Pyodide Method | ||
|
|
||
| Stores snippets with browser-runtime intent and skips Panel-extension inference. | ||
| This method is intended for `show_pyodide` and panel-live flows. | ||
|
|
||
| The method is automatically inferred from the code or can be specified explicitly. | ||
|
|
||
| ## Database and URL Management | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -140,6 +140,33 @@ Tools for accessing HoloViews documentation. | |||||
|
|
||||||
| Tools for searching and accessing HoloViz documentation. | ||||||
|
|
||||||
| ### show | ||||||
|
|
||||||
| **Purpose**: Execute visualization code via the display server and return a view URL (with MCP App rendering in capable hosts). | ||||||
|
|
||||||
| **Parameters**: | ||||||
| - `code` (string): Python code to execute | ||||||
| - `name` (string, optional): Visualization name | ||||||
| - `description` (string, optional): Visualization description | ||||||
| - `method` (string, optional): `jupyter` (default), `panel`, or `pyodide` | ||||||
|
|
||||||
| **Use Case**: Standard display-server backed visualization flow with URL fallback behavior. | ||||||
|
|
||||||
| **Returns**: Success/error message containing a view URL. | ||||||
|
||||||
| **Returns**: Success/error message containing a view URL. | |
| **Returns**: JSON text payload (as returned by `holoviz_mcp.server.display()`) describing the view, including a view URL and rendering metadata. In non–MCP-App hosts, this may be surfaced to the user as a success/error message string containing the view URL. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,10 +117,21 @@ def _execute_code(snippet: Snippet) -> pn.viewable.Viewable | None: | |
| """ | ||
| module_name = f"holoviz_snippet_{snippet.id.replace('-', '_')}" | ||
|
|
||
| # We need to reset the material design | ||
| app: str = ( | ||
| """\ | ||
| import panel as pn | ||
|
|
||
| pn.config.design = None | ||
|
|
||
| """ | ||
| + snippet.app | ||
| ) | ||
|
|
||
| if snippet.method == "jupyter": | ||
| # Extract last expression | ||
| try: | ||
| statements, last_expr = extract_last_expression(snippet.app) | ||
| statements, last_expr = extract_last_expression(app) | ||
| except ValueError as e: | ||
| raise ValueError(f"Failed to parse code: {e}") from e | ||
|
|
||
|
|
@@ -150,7 +161,7 @@ def _execute_code(snippet: Snippet) -> pn.viewable.Viewable | None: | |
| else: # panel method | ||
| # Execute code that should call .servable() | ||
| execute_in_module( | ||
| snippet.app, | ||
| app, | ||
| module_name=module_name, | ||
| cleanup=True, # Can cleanup immediately | ||
| ) | ||
|
Comment on lines
131
to
167
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flow description still says the MCP server “returns URL to view visualization”, but
shownow returns a JSON payload (withurlembedded) for MCP App rendering. Adjust the wording here to reflect the new contract, otherwise this doc contradicts the implementation and theshowMCP App template logic.