MCP-Slicer: 3D Slicer Model Context Protocol Integration

Hello everyone!

Try mcp-slicer and provide feedback~

Model Context Protocol (MCP) has become very popular recently, as it enables language models to extend their capabilities by using various tools, such as controlling web browsers, file systems, and more.

BlenderMCP, which “connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt-assisted 3D modeling, scene creation, and manipulation,” has gained significant popularity, already accumulating 8.2k stars on GitHub.

I believe that Slicer should also have its own MCP server. Slicer has a flexible and user-friendly architecture, and large language models already have a decent understanding of it (and even if they don’t, we can simply provide them with documentation). This would allow us to write functional code and operate Slicer using natural language without significant overhead – which is really cool.

I’ve created a simple implementation called mcp-slicer that allows Claude, Cline, or other MCP-compatible clients to control a running instance of Slicer. You can check out this project on GitHub, try it out, and provide feedback.

Initially, I wanted to implement the server directly within Slicer using extensions and modules, but Slicer currently uses Python 3.9, while MCP Server development requires Python 3.10 or higher. Fortunately, I discovered the Slicer Web Server, which already implements many interfaces suitable for interaction with an MCP Server, so I utilized that approach.

Below is the README from the mcp-slicer project for your reference.

logo

MCP-Slicer - 3D Slicer Model Context Protocol Integration

English | 简体中文

Python Version
License: MIT
PyPI version

MCP-Slicer connects 3D Slicer with model clients like Claude Desktop or Cline through the Model Context Protocol (MCP), enabling direct interaction and control of 3D Slicer. This integration allows for medical image processing, scene creation, and manipulation using natural language.

Features

  1. list_nodes: List and filter Slicer MRML nodes and view their properties

  2. execute_python_code: Execute Python code in the Slicer environment

Installation

Prerequisites

  • 3D Slicer 5.8 or newer
  • Python 3.13 or newer
  • uv package manager

If you’re on Mac, please install uv as

brew install uv

On Windows

powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

and then

set Path=C:\Users\nntra\.local\bin;%Path%

Otherwise installation instructions are on their website: Install uv

:warning: Please install UV first

Claude for Desktop Integration

Go to Claude > Settings > Developer > Edit Config > claude_desktop_config.json to include the following:

{
  "mcpServers": {
    "slicer": {
      "command": "uvx",
      "args": ["mcp-slicer"]
    }
  }
}

Cline Intergration

{
  "mcpServers": {
    "slicer": {
      "command": "uvx",
      "args": ["mcp-slicer"]
    }
  }
}

Usage

Check Claude Settings

Image

Make sure you see the corresponding slicer tools added to the Claude Desktop App

Image
Image

Open Slicer Web Server

  1. Open the Slicer Web Server module,
  2. ensure the required interfaces are checked,
  3. then start the server

Image

Examples

- list_nodes

What Markups nodes are in the Slicer scene now, list their names, what is their length if it is a line, and what is its angle if it is an angle

Image

- execute python code

Draw a translucent green cube of 8 cm in the Slicer scene, mark its vertices, and then draw a red sphere inscribed in it.

example_code_execute_en

Technical Details

Utilizes existing Slicer Web Server interfaces. For technical details, please see Slicer web server user guide

Limitations & Security Considerations

  • The execute_python_code tool allows running arbitrary Python code in 3D Slicer, which is powerful but potentially dangerous.

    :warning: Not recommended for production use.

  • Complex operations may need to be broken down into smaller steps.

Contributing

Contributions are welcome! Feel free to submit Pull Requests.

Disclaimer

This is a third-party integration project, not developed by the 3D Slicer team.

2 Likes

Sounds great!

Thanks for including the warning about possible security issues, particularly if PHI is involved. Safety first :+1:

That said I can’t wait to try this out of a virtual machine with public data.

This is awesome! I wanted to try how capable MCP for Slicer is and your work makes this much easier. Also, the example that you show here is really promising!

We’ll update Slicer’s Python version hopefully in a couple of weeks, which will simplify the installation process. It would be also interesting to try to extend the interface to allow more functionality without exposing the python exec API. For example, getting information about the currently loaded image, get image data, set image data, drawing markups on the image, etc. These would be pretty safe to use (so we might run it without sandboxing the application) and could allow some really cool use cases.

3 Likes

FYI, I was able to try this out using DeepSeek-R1 in cline in vscode using these instructions and I was able to replicate the examples, so that’s cool. (Results where a bit oddly different and incorrect, like when I pasted in the example prompt to make the red sphere inscribed in the green cube, it make a green cube inscribed in the sphere).

I tried asking it do a few other things like downloading sample data, scrolling through slices and it was interesting to see that it was making reasonable guesses and using the error messages to come up with better solutions. I think there’s a lot of potential in this.

2 Likes

It is delightful to hear the news that the Python version will be updated in the near future. This indeed can bring a great deal of convenience.
Yes, there are many Web Server interfaces that can be utilized, and they are safer than python exec API. I will gradually add them later.
Moreover, it would be very cool if Slicer had its own chatbot module, I would like to try whether bidirectional communication with the LLM client is possible and transfer the prompt input in Slicer to it. Having Claude and Slicer open simultaneously is a bit cumbersome.

Thank you for trying it out. happy to hear that mcp-slicer is working properly. :blush: I haven’t tested it in many environments yet.

In my experience, using different language models has a significant impact on the results. Generally, I think Claude 3.7 or 3.5 can also yield excellent results.

Mcp-slicer can not only execute code but also return execution results and error messages to the client. This is very promising. Nowadays, large-model clients can determine whether they are on the right path based on the returned results and correct their methods. By interacting several more times, one can often obtain the correct results.

Moreover, if everyone wants to try it out for free, the Vscode Cline plugin is an excellent choice. It can utilize the free usage in GitHub Copilot. You can use Claude 3.5 Sonnet for FREE

1 Like