Commit e436f4c3 authored by Boris Glimcher's avatar Boris Glimcher Committed by Tomasz Zawadzki
Browse files

python/mcp: adding first MCP server for SPDK json-rpc APIs

The [Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
lets you build servers that expose data and functionality to LLM applications
in a secure, standardized way.  Think of it like a web API,
but specifically designed for LLM interactions.

Example usages:
 - [VS Code](https://code.visualstudio.com/)
 - [Claude Desktop](https://claude.ai/download

)
 - more...

Change-Id: Iae9c912deb7ad4e75ce24af92a2f5a05f38fc73b
Signed-off-by: default avatarBoris Glimcher <Boris.Glimcher@emc.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26123


Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz@tzawadzki.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@nutanix.com>
parent 5c365eb0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -60,5 +60,6 @@ uninstall:
	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk-rpc
	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk-sma
	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk-cli
	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk-mcp

.PHONY: all clean install uninstall
+36 −0
Original line number Diff line number Diff line
@@ -52,3 +52,39 @@ From a Python interpreter:
```

For more information, see <https://spdk.io/doc/jsonrpc.html>

## Model Context Protocol (MCP)

The [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) lets you build servers that expose
data and functionality to LLM applications in a secure, standardized way.
Think of it like a web API, but specifically designed for LLM interactions.

MCP servers can:

- Expose data through Resources (think of these sort of like GET endpoints; they are used to load information into the LLM's context)
- Provide functionality through Tools (sort of like POST endpoints; they are used to execute code or otherwise produce a side effect)
- Define interaction patterns through Prompts (reusable templates for LLM interactions)
- And more!

The SPDK MCP Server is a Model Context Protocol (MCP) server that provides seamless integration with SPDK APIs,
enabling advanced automation and interaction capabilities for developers and tools.

```bash
$ uv venv
$ source .venv/bin/activate
$ uv pip install spdk[mcp]
or locally
$ uv pip install python/[mcp]
```

You can install this server in [Claude Desktop](https://claude.ai/download) and interact with it right away by running:

```bash
mcp install server.py
```

Alternatively, you can test it with the MCP Inspector:

```bash
mcp dev server.py
```
+4 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ dependencies = []
spdk-rpc = "spdk.spdk_rpc:main"
spdk-sma = "spdk.spdk_sma:main"
spdk-cli = "spdk.spdk_cli:main"
spdk-mcp = "spdk.mcp:server"

[project.optional-dependencies]
sma = [
@@ -54,6 +55,9 @@ sma = [
cli = [
    "configshell_fb"
]
mcp = [
    "mcp[cli]>=1.9.2"
]

[tool.hatch.version]
path = "spdk/version.py"
+2 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (C) 2025 Dell Inc, or its subsidiaries.  All rights reserved.
+30 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (C) 2025 Dell Inc, or its subsidiaries.  All rights reserved.

from spdk import rpc
from spdk.rpc.client import JSONRPCClient
from mcp.server.fastmcp import FastMCP

# Create an MCP server
mcp = FastMCP("SPDK")

# TODO: add tcp support and make it input argument
client = JSONRPCClient("/var/tmp/spdk.sock")


@mcp.tool()
def spdk_get_version() -> dict:
    """Get the SPDK version"""
    return rpc.spdk_get_version(client)


@mcp.resource("bdevs://all")
def bdev_get_bdevs() -> list:
    """Get a list of block devices"""
    return rpc.bdev.bdev_get_bdevs(client)


@mcp.tool()
def bdev_malloc_create(name: str, num_blocks: int = 1024, block_size: int = 512) -> dict:
    """Create a malloc block device"""
    return rpc.bdev.bdev_malloc_create(client, num_blocks, block_size, name=name)