Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/giant-pandas-cut.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"toolsets": minor
---

feat:Fix: Pass launch kwargs to Gradio's demo.launch()
13 changes: 11 additions & 2 deletions toolsets/gradio_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@
StreamableHTTPSessionManager = None


def launch_gradio_ui(toolset: "Toolset", mcp_server: bool = False) -> None:
def launch_gradio_ui(
toolset: "Toolset",
mcp_server: bool = False,
share: bool | None = None,
server_port: int | None = None,
) -> None:
"""
Launch the Gradio UI for the toolset.

Args:
toolset: The Toolset instance to create the UI for.
mcp_server: If True, create and integrate the MCP server. Defaults to False.
share: If True, creates a publicly accessible link. Defaults to None (False).
server_port: The port to bind the server to. Defaults to None (7860).
"""
toolset._get_tool_data()
if toolset._verbose:
Expand Down Expand Up @@ -200,7 +207,9 @@ def get_mcp_info(request: gr.Request):
except ImportError:
pass

demo.launch(css=css, footer_links=["settings"])
demo.launch(
css=css, footer_links=["settings"], share=share, server_port=server_port
)


def _get_complete_schema(toolset: "Toolset", request: Request) -> JSONResponse:
Expand Down
16 changes: 14 additions & 2 deletions toolsets/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,12 @@ def _search_deferred_tools(

return results

def launch(self, mcp_server: bool = False):
def launch(
self,
mcp_server: bool = False,
share: bool | None = None,
server_port: int | None = None,
):
"""
Launch the Gradio UI for this toolset.

Expand All @@ -290,17 +295,24 @@ def launch(self, mcp_server: bool = False):
mcp_server: If True, creates and integrates an MCP server that exposes all tools
through the MCP protocol at the `/gradio_api/mcp` endpoint. The MCP server
can be accessed by MCP clients for programmatic tool usage. Defaults to False.
share: If True, creates a publicly accessible link for the Gradio UI.
Defaults to None (False).
server_port: The port to bind the server to. Defaults to None (7860).

Examples:
>>> from toolsets import Server, Toolset
>>> t = Toolset("My Tools")
>>> t.add(Server("gradio/mcp_tools"))
>>> t.launch() # UI only
>>> t.launch(mcp_server=True) # UI + MCP server
>>> t.launch(mcp_server=True, share=True) # With public link
>>> t.launch(server_port=8080) # Custom port

Note:
When mcp_server=True, the MCP server endpoint is available at
`http://localhost:7860/gradio_api/mcp` (or the appropriate host/port).
Connection details are shown in the "MCP Info" tab of the UI.
"""
launch_gradio_ui(self, mcp_server=mcp_server)
launch_gradio_ui(
self, mcp_server=mcp_server, share=share, server_port=server_port
)
Loading