The EPICS MCP Server is a Python-based server designed to interact with EPICS (Experimental Physics and Industrial Control System) process variables (PVs). It allows you to retrieve PV values, set PV values, and fetch detailed information about PVs using the MCP framework, making it ideal for integration into larger control systems or workflows.
Before using the EPICS MCP Server, you must install EPICS on your local machine and ensure it's working properly. Verify that functions such as caget
, caput
, and cainfo
are operational.
For detailed 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 functionality:
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 EPICS MCP Server and its dependencies:
pip install -r requirements.txt
Retrieves the current value of a specified PV.
Inputs:
pv_name
(string): The name of the PV variable.Returns:
A JSON object with 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 with 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 with the status (success
or error
) and detailed information about the PV or an error message.
To use the EPICS MCP Server with Langchain:
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 a complete example of using the EPICS MCP Server with a client:
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
================================[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.
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 > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.