The EPICS MCP Server enables interactions with EPICS (Experimental Physics and Industrial Control System) process variables through a Python-based interface. It allows retrieving and setting PV values as well as fetching detailed PV information using the Model Context Protocol framework.
Before using the EPICS MCP Server, you must have EPICS properly installed on your machine with a functioning IOC. Verify that basic EPICS commands like caget
, caput
, and cainfo
work correctly.
For EPICS installation instructions, visit the EPICS Controls website.
Example of a working EPICS setup:
jiangyan@DESKTOP-84CO9VB:~$ softIoc -d ~/EPICS/DB/test.db
Starting iocInit
############################################################################
## EPICS R7.0.8
## Rev. 2025-02-13T14:29+0800
## Rev. Date build date/time:
############################################################################
iocRun: All initialization complete
epics>
Verify EPICS commands are working:
jiangyan@DESKTOP-84CO9VB:~$ caget temperature:water
temperature:water 88
jiangyan@DESKTOP-84CO9VB:~$ caput temperature:water 100
Old : temperature:water 88
New : temperature:water 100
jiangyan@DESKTOP-84CO9VB:~$ cainfo temperature:water
temperature:water
State: connected
Host: 127.0.0.1:5056
Access: read, write
Native data type: DBF_DOUBLE
Request type: DBR_DOUBLE
Element count: 1
Install the required dependencies:
pip install -r requirements.txt
The EPICS MCP Server provides three main tools:
Retrieves the current value of a specified PV.
Inputs:
pv_name
(string): The name of the PV variable.Returns:
A JSON object containing the status (success
or error
) and the retrieved value or an error message.
Sets a new value for a specified PV.
Inputs:
pv_name
(string): The name of the PV variable.pv_value
(string): The new value to be set for the PV.Returns:
A JSON object containing the status (success
or error
) and a confirmation message or an error message.
Fetches detailed information about a specified PV.
Inputs:
pv_name
(string): The name of the PV variable.Returns:
A JSON object containing the status (success
or error
) and the detailed information about the PV or an error message.
To use the EPICS MCP Server with Langchain, initialize the server parameters as follows:
server_params = StdioServerParameters(
command="python",
# Make sure to update to the full absolute path to your server.py file
args=["/path/server.py"],
)
Here's an example of how to create a client to interact with the server:
async def run():
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# Initialize the connection
await session.initialize()
# Get tools
tools = await load_mcp_tools(session)
# Create and run the agent
agent = create_react_agent(model, tools)
agent_response = await agent.ainvoke({"messages": "To query the value of a PV (Process Variable) named temperature:water"})
return agent_response
When querying a PV value:
================================[1m Human Message [0m=================================
To query the value of a PV (Process Variable) named temperature:water
==================================[1m Ai Message [0m==================================
Tool Calls:
get_pv_value (call_vvbXwi51CyYUxEM0hcyvCFCY)
Call ID: call_vvbXwi51CyYUxEM0hcyvCFCY
Args:
pv_name: temperature:water
=================================[1m Tool Message [0m=================================
Name: get_pv_value
{
"status": "success",
"value": 88.0
}
==================================[1m Ai Message [0m==================================
The current value of the PV named `temperature:water` is 88.0.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "epics-mcp-server" '{"command":"python","args":["/path/server.py"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"epics-mcp-server": {
"command": "python",
"args": [
"/path/server.py"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"epics-mcp-server": {
"command": "python",
"args": [
"/path/server.py"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect