# MCP-server-for-Tia-Portal

Made a MCP server for Tia Portal. Was looking for a way to export OPC UA nodeset files using Tia Portal Openness.

<br/>
<img width="1197" height="788" alt="image" src="https://github.com/user-attachments/assets/3eb3ee7f-6302-4fee-bd31-d44b33e8a6d4" />
<br/>
<br/>
<img width="924" height="582" alt="image" src="https://github.com/user-attachments/assets/fc1b512b-65ea-4391-880f-9e113e9f96c3" />
<br/>
<br/>
<br/>
Project Management: Open and close TIA Portal projects
PLC Discovery: List all PLC devices in a project
Block Operations: List, read, and export program blocks (OB, FC, FB, DB)
Tag Management: Access and search PLC tag tables
Hardware Configuration: Retrieve device topology and configuration
OPC UA Support: Access and export OPC UA server interfaces
Project Information: Get detailed project metadata

##  Available Actions
1. Open Project. Opens a TIA Portal project file.
2. Close Project. Closes the currently open project.
3. List PLCs: Lists all PLC devices in the open project.
4. List Blocks: Lists program blocks for a specific PLC.
5. Get Block Code: Retrieves information about a specific block.
6. Export Block: Exports a block to XML format.
7. Get Tag Table: Retrieves the PLC tag table (global variables).
8. Search Tag: Searches for tags by name across the project.
9. Get Hardware Config:Retrieves hardware configuration and device topology.
10. Get Project Info: Gets general information about the currently open project.
11. Export OPC UA Interface: Exports the OPC UA server interface configuration to XML.
12. Get OPC UA Interface Info: Gets information about the OPC UA server interface configuration.

# Limitations

Only one project can be open at a time
The server runs in "WithoutUserInterface" mode, so no TIA Portal GUI is shown
Some operations may require specific TIA Portal versions or licenses
OPC UA functionality requires the PLC to have OPC UA configured


# Claude Desktop settings for MCP server

<br/>
<img width="890" height="126" alt="image" src="https://github.com/user-attachments/assets/d6f2763c-8c90-43b0-8c73-6adbe1417a71" />
<br/>

# Security Considerations

This server provides full access to TIA Portal projects
Ensure proper access controls are in place
Do not expose this server to untrusted networks
Validate all file paths to prevent directory traversal attacks
Consider running in a sandboxed environment

# Troubleshooting

"No project is open" error
Make sure to call OpenProject before attempting other operations.

"PLC not found" error
Verify the PLC name matches exactly (case-sensitive). Use ListPLCs to see available PLCs.

OPC UA errors
Ensure OPC UA is configured in the TIA Portal project
Check that the correct TIA Portal Openness assemblies are referenced
Verify the PLC supports OPC UA functionality





