diff --git a/README.md b/README.md index d311a97..ca74a27 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ for the frontend extension. - **Command Discovery**: List all available JupyterLab commands with their metadata - **Command Execution**: Execute any JupyterLab command programmatically from Python +- **MCP Integration**: Automatically exposes tools to AI assistants via [jupyter-server-mcp](https://github.com/jupyter-ai-contrib/jupyter-server-mcp) ## Requirements @@ -25,9 +26,40 @@ To install the extension, execute: pip install jupyterlab_commands_toolkit ``` +To install with `jupyter-server-mcp` integration support: + +```bash +pip install jupyterlab_commands_toolkit[mcp] +``` + ## Usage -Use the toolkit to execute any JupyterLab command from Python: +### With jupyter-server-mcp (Recommended) + +This extension automatically registers its tools with [jupyter-server-mcp](https://github.com/jupyter-ai-contrib/jupyter-server-mcp) via Python entrypoints, making them available to AI assistants and other MCP clients. + +1. Install both packages: + +```bash +pip install jupyterlab_commands_toolkit[mcp] +``` + +2. Start Jupyter Lab (the MCP server starts automatically): + +```bash +jupyter lab +``` + +3. Configure your MCP client (e.g., Claude Desktop) to connect to `http://localhost:3001/mcp` + +The following tools will be automatically available: + +- `list_all_commands` - List all available JupyterLab commands with their metadata +- `execute_command` - Execute any JupyterLab command programmatically + +### Direct Python Usage + +Use the toolkit directly from Python to execute JupyterLab commands: ```python import asyncio diff --git a/jupyterlab_commands_toolkit/tools.py b/jupyterlab_commands_toolkit/tools.py index e229eb7..ae3b3e1 100644 --- a/jupyterlab_commands_toolkit/tools.py +++ b/jupyterlab_commands_toolkit/tools.py @@ -8,6 +8,12 @@ # Store for pending command results pending_requests: Dict[str, Dict[str, Any]] = {} +# Tools list for jupyter-server-mcp entrypoint discovery +TOOLS = [ + "jupyterlab_commands_toolkit.tools:list_all_commands", + "jupyterlab_commands_toolkit.tools:execute_command", +] + def emit(data, wait_for_result=False): """ diff --git a/pyproject.toml b/pyproject.toml index 114515d..e35aa84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,12 @@ dependencies = [ ] dynamic = ["version", "description", "authors", "urls", "keywords"] +[project.optional-dependencies] +mcp = ["jupyter-server-mcp>=0.1.2"] + +[project.entry-points."jupyter_server_mcp.tools"] +jupyterlab_commands_toolkit = "jupyterlab_commands_toolkit.tools:TOOLS" + [tool.hatch.version] source = "nodejs"