3D Slicer

3D Slicer

zhaoyouj

Connects AI assistants to 3D Slicer for medical image analysis, enabling remote control and visualization of medical imaging workflows through natural language commands.

26269 views5Local (stdio)

What it does

  • List and filter MRML nodes in 3D Slicer
  • Execute Python code directly in Slicer environment
  • Capture screenshots of slice views and 3D renderings
  • Control medical image processing workflows remotely
  • Manipulate 3D medical imaging scenes

Best for

Medical researchers analyzing imaging dataHealthcare professionals automating Slicer workflowsDevelopers building medical imaging applicationsAI-assisted medical image analysis
Direct 3D Slicer integrationReal-time visual feedback with screenshotsNatural language control of medical imaging

Tools (3)

list_nodes

List MRML nodes via the Slicer Web Server API. The filter_type parameter specifies the type of node information to retrieve. Possible values include "names" (node names), "ids" (node IDs), and "properties" (node properties). The default value is "names". The class_name, name, and id parameters are optional and can be used to further filter nodes. The class_name parameter allows filtering nodes by class name. The name parameter allows filtering nodes by name. The id parameter allows filtering nodes by ID. Examples: - List the names of all nodes: {"tool": "list_nodes", "arguments": {"filter_type": "names"}} - List the IDs of nodes of a specific class: {"tool": "list_nodes", "arguments": {"filter_type": "ids", "class_name": "vtkMRMLModelNode"}} - List the properties of nodes with a specific name: {"tool": "list_nodes", "arguments": {"filter_type": "properties", "name": "MyModel"}} - List nodes with a specific ID: {"tool": "list_nodes", "arguments": {"filter_type": "ids", "id": "vtkMRMLModelNode123"}} Returns a dictionary containing node information. If filter_type is "names" or "ids", the returned dictionary contains a "nodes" key, whose value is a list containing node names or IDs. Example: {"nodes": ["node1", "node2", ...]} or {"nodes": ["id1", "id2", ...]} If filter_type is "properties", the returned dictionary contains a "nodes" key, whose value is a dictionary containing node properties. Example: {"nodes": {"node1": {"property1": "value1", "property2": "value2"}, ...}} If an error occurs, a dictionary containing an "error" key is returned, whose value is a string describing the error.

execute_python_code

Execute Python code in 3D Slicer. Parameters: code (str): The Python code to execute. The code parameter is a string containing the Python code to be executed in 3D Slicer's Python environment. The code should be executable by Python's `exec()` function. To get return values, the code should assign the result to a variable named `__execResult`. Examples: - Create a sphere model: {"tool": "execute_python_code", "arguments": {"code": "sphere = slicer.vtkMRMLModelNode(); slicer.mrmlScene.AddNode(sphere); sphere.SetName('MySphere'); __execResult = sphere.GetID()"}} - Get the number of nodes in the current scene: {"tool": "execute_python_code", "arguments": {"code": "__execResult = len(slicer.mrmlScene.GetNodes())"}} - Calculate 1+1: {"tool": "execute_python_code", "arguments": {"code": "__execResult = 1 + 1"}} Returns: dict: A dictionary containing the execution result. If the code execution is successful, the dictionary will contain the following key-value pairs: - "success": True - "message": The result of the code execution. If the code assigns the result to `__execResult`, the value of `__execResult` is returned, otherwise it returns empty. If the code execution fails, the dictionary will contain the following key-value pairs: - "success": False - "message": A string containing an error message indicating the cause of the failure. The error message may come from the Slicer Web Server or the Python interpreter. Examples: - Successful execution: {"success": True, "message": 2} # Assuming the result of 1+1 is 2 - Successful execution: {"success": True, "message": "vtkMRMLScene1"} # Assuming the created sphere id is vtkMRMLScene1 - Python execution error: {"success": False, "message": "Server error: name 'slicer' is not defined"} - Connection error: {"success": False, "message": "Connection error: ..."} - HTTP error: {"success": False, "message": "HTTP Error 404: Not Found"}

capture_screenshot

Capture a screenshot from 3D Slicer's views. This tool provides real-time visual feedback of the current state of Slicer, enabling AI to observe the GUI and make informed decisions in a complete REACT loop. Parameters: view_type (str): Type of screenshot to capture. Options: - "application" (default): Full application window including all panels and views - "slice": A specific slice view (Red/Yellow/Green) - "3d": The 3D rendering view view_name (str): For slice views, specify which view to capture. Options: "red", "yellow", "green" Only used when view_type="slice" slice_offset (float): For slice views, offset in mm relative to slice origin. Only used when view_type="slice" slice_orientation (str): For slice views, specify orientation. Options: "axial", "sagittal", "coronal" Only used when view_type="slice" camera_axis (str): For 3D views, specify camera view direction. Options: "L" (Left), "R" (Right), "A" (Anterior), "P" (Posterior), "I" (Inferior), "S" (Superior) Only used when view_type="3d" image_size (int): Pixel size of output image (for slice and 3D views). Only used when view_type="slice" or view_type="3d" Returns: A list containing text and/or image content. The image is returned in MCP's standard format for proper display in AI clients. Examples: - Capture full application: {"tool": "capture_screenshot", "arguments": {"view_type": "application"}} - Capture Red slice view: {"tool": "capture_screenshot", "arguments": {"view_type": "slice", "view_name": "red"}} - Capture 3D view from anterior: {"tool": "capture_screenshot", "arguments": {"view_type": "3d", "camera_axis": "A"}} - Capture axial slice: {"tool": "capture_screenshot", "arguments": {"view_type": "slice", "view_name": "red", "slice_orientation": "axial"}}

Alternatives