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
2 changes: 1 addition & 1 deletion docs/docs/tools/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The server currently offers 16 tools organized into 3 categories:
- This tool recursively lists files and directories from the Jupyter server's content API, showing the complete file structure including notebooks, data files, scripts, and directories.
- Input:
- `path`(string, optional): The starting path to list from (empty string means root directory)
- `max_depth`(int, optional): Maximum depth to recurse into subdirectories (default: 3)
- `max_depth`(int, optional): Maximum depth to recurse into subdirectories (default: 1)
- Returns: Tab-separated table with columns: Path, Type, Size, Last_Modified
- **Path**: Full path to the file or directory
- **Type**: File type ("file", "directory", "notebook", or "error" if inaccessible)
Expand Down
50 changes: 13 additions & 37 deletions jupyter_mcp_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
ensure_kernel_alive,
execute_cell_with_forced_sync,
wait_for_kernel_idle,
safe_notebook_operation,
list_files_recursively,
safe_notebook_operation
)
from jupyter_mcp_server.config import get_config, set_config
from jupyter_mcp_server.notebook_manager import NotebookManager
Expand All @@ -54,7 +53,6 @@
# Cell Execution
ExecuteCellTool,
# Other Tools
AssignKernelToNotebookTool,
ExecuteIpythonTool,
ListFilesTool,
ListKernelsTool,
Expand Down Expand Up @@ -207,12 +205,15 @@ async def health_check(request: Request):
@mcp.tool()
async def list_files(
path: Annotated[str, Field(description="The starting path to list from (empty string means root directory)")] = "",
max_depth: Annotated[int, Field(description="Maximum depth to recurse into subdirectories (default: 3)")] = 3,
) -> Annotated[str, Field(description="Tab-separated table with columns: Path, Type, Size, Last_Modified")]:
"""List all files and directories in the Jupyter server's file system.

This tool recursively lists files and directories from the Jupyter server's content API,
showing the complete file structure including notebooks, data files, scripts, and directories.
# Maximum depth to recurse into subdirectories, Set Max to 3 to avoid infinite recursion.
max_depth: Annotated[int, Field(description="Maximum depth to recurse into subdirectories", ge=0, le=3)] = 1,
start_index: Annotated[int, Field(description="Starting index for pagination (0-based)", ge=0)] = 0,
limit: Annotated[int, Field(description="Maximum number of items to return (0 means no limit)", ge=0)] = 25,
pattern: Annotated[str, Field(description="Glob pattern to filter file paths")] = "",
) -> Annotated[str, Field(description="Tab-separated table with columns: Path, Type, Size, Last_Modified. Includes pagination info header.")]:
"""
List all files and directories recursively in the Jupyter server's file system.
Used to explore the file system structure of the Jupyter server or to find specific files or directories.
"""
return await safe_notebook_operation(
lambda: ListFilesTool().execute(
Expand All @@ -221,7 +222,9 @@ async def list_files(
contents_manager=server_context.contents_manager,
path=path,
max_depth=max_depth,
list_files_recursively_fn=list_files_recursively,
start_index=start_index,
limit=limit,
pattern=pattern if pattern else None,
)
)

Expand All @@ -243,33 +246,6 @@ async def list_kernels() -> Annotated[str, Field(description="Tab-separated tabl
)
)


@mcp.tool()
async def assign_kernel_to_notebook(
notebook_path: Annotated[str, Field(description="Path to the notebook file, relative to the Jupyter server root (e.g. 'notebook.ipynb')")],
kernel_id: Annotated[str, Field(description="ID of the kernel to assign to the notebook")],
session_name: Annotated[str, Field(description="Name for the session (If is empty, defaults to notebook path)")] = None,
) -> Annotated[str, Field(description="Success message with session information including session ID")]:
"""Assign a kernel to a notebook by creating a Jupyter session.

This creates a Jupyter server session that connects a notebook file to a kernel,
enabling code execution in the notebook. Sessions are the mechanism Jupyter uses
to maintain the relationship between notebooks and their kernels.
"""
return await safe_notebook_operation(
lambda: AssignKernelToNotebookTool().execute(
mode=server_context.mode,
server_client=server_context.server_client,
contents_manager=server_context.contents_manager,
session_manager=server_context.session_manager,
kernel_manager=server_context.kernel_manager,
notebook_path=notebook_path,
kernel_id=kernel_id,
session_name=session_name,
)
)


###############################################################################
# Multi-Notebook Management Tools.

Expand Down
2 changes: 0 additions & 2 deletions jupyter_mcp_server/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from jupyter_mcp_server.tools.execute_cell_tool import ExecuteCellTool

# Import tool implementations - Other Tools
from jupyter_mcp_server.tools.assign_kernel_to_notebook_tool import AssignKernelToNotebookTool
from jupyter_mcp_server.tools.execute_ipython_tool import ExecuteIpythonTool
from jupyter_mcp_server.tools.list_files_tool import ListFilesTool
from jupyter_mcp_server.tools.list_kernels_tool import ListKernelsTool
Expand All @@ -56,7 +55,6 @@
# Cell Execution
"ExecuteCellTool",
# Other Tools
"AssignKernelToNotebookTool",
"ExecuteIpythonTool",
"ListFilesTool",
"ListKernelsTool",
Expand Down
127 changes: 0 additions & 127 deletions jupyter_mcp_server/tools/assign_kernel_to_notebook_tool.py

This file was deleted.

Loading
Loading