dgwoOstjfn/tia_portal_mcp_server
If you are the rightful owner of tia_portal_mcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The TIA Portal MCP Server is a Model Context Protocol server designed for Siemens TIA Portal automation, facilitating seamless integration and management of automation projects.
TIA Portal MCP Server
Model Context Protocol (MCP) server for Siemens TIA Portal automation. Enables AI assistants like Claude to programmatically interact with TIA Portal projects - opening projects, reading/writing blocks, compiling, and managing PLC tags and UDTs.
Prerequisites
- Python: 3.9 or higher
- TIA Portal: V15.1, V16, V17, V18, V19, or V20 installed
- TIA Openness: Enabled in TIA Portal (requires appropriate license)
- Windows: Required for TIA Portal COM/Openness API
Quick Start
1. Environment Setup
cd tia_portal_mcp_server
python -m venv venv
venv\Scripts\activate
pip install -r MCP_Server/requirements.txt
2. Test the Server
venv\Scripts\python.exe MCP_Server\start_server.py test
This runs diagnostic tests to verify TIA Portal connectivity and configuration.
3. Configure MCP Client
Option A: Using launch_mcp.bat (Recommended)
Add to your Claude Desktop config (~/.claude.json or .mcp.json):
{
"mcpServers": {
"tia-portal": {
"command": "C:\\path\\to\\tia_portal_mcp_server\\launch_mcp.bat",
"env": {
"PYTHONUNBUFFERED": "1"
}
}
}
}
Option B: Direct Python
{
"mcpServers": {
"tia-portal": {
"command": "C:\\path\\to\\tia_portal_mcp_server\\venv\\Scripts\\python.exe",
"args": ["MCP_Server\\start_server.py"],
"env": {
"PYTHONUNBUFFERED": "1",
"TIA_SESSION_TIMEOUT": "3600",
"TIA_MAX_SESSIONS": "3"
}
}
}
}
Note: Only
commandneeds an absolute path. The server auto-detects its location.
Typical Workflow
Once configured, you can interact with TIA Portal through Claude:
Option A: Start Fresh Session
1. Create session → create_session
2. Open project → open_project (provide .ap* file path)
3. Explore project → list_blocks, list_tag_tables, discover_all_udts
4. Read/analyze code → read_project_source, analyze_project_structure
5. Make changes → create_block_from_scl, import_blocks
6. Compile & verify → compile (target="project"), get_compilation_errors
7. Save & close → save_project, close_session
Option B: Attach to Running TIA Portal
1. Find instances → list_tia_processes (shows all running TIA Portal instances)
2. Attach to process → attach_to_process (using process_id from step 1)
3. Work with project → list_blocks, read_project_source, compile, etc.
4. Close when done → close_session
Tip: Use
list_tia_processesto discover TIA Portal instances you already have open, thenattach_to_processto connect without opening a new instance.
Supported TIA Portal Versions
| Version | Status |
|---|---|
| V15.1 | Supported |
| V16 | Supported |
| V17 | Supported |
| V18 | Supported |
| V19 | Supported |
| V20 | Supported |
Available Tools (35)
Session Management
| Tool | Description |
|---|---|
create_session | Create new TIA Portal session |
close_session | Close session and cleanup resources |
list_sessions | List all active sessions |
list_tia_processes | List all running TIA Portal instances (no session required) |
attach_to_process | Attach to a running TIA Portal instance and create session |
Project Operations
| Tool | Description |
|---|---|
open_project | Open TIA Portal project (.ap* file) |
save_project | Save current project |
save_project_as | Save project to new location with new name |
close_project | Close current project |
get_project_info | Get project metadata |
Block Operations
| Tool | Description |
|---|---|
list_blocks | List all blocks in project |
export_blocks | Export blocks to XML files |
import_blocks | Import blocks from XML files |
create_block_from_scl | Create block directly from SCL code string |
delete_block | Delete a block from project |
Analysis Tools
| Tool | Description |
|---|---|
analyze_project_structure | Get project tree structure |
read_project_source | Read SCL source code with filtering |
cache_project_data | Pre-cache all blocks for faster access |
clear_cache | Clear session cache |
Cross-Reference Analysis
| Tool | Description |
|---|---|
get_cross_references | Get outgoing references for a block (what it uses/calls) |
get_block_dependents | Get incoming references for a block (what uses/calls it) |
get_unused_blocks | Find all unused blocks in project (with Global DB verification) |
get_tag_cross_references | Get cross-references for a PLC tag |
Compilation
| Tool | Description |
|---|---|
compile | Compile project, device, or block (use target param) |
get_compilation_errors | Get compilation errors and warnings |
PLC Tags
| Tool | Description |
|---|---|
list_tag_tables | List all tag tables |
get_tag_table_details | Get tags from specific table |
export_tag_tables | Export tag tables to XML (all or specific) |
UDTs (User-Defined Types)
| Tool | Description |
|---|---|
discover_all_udts | Find all UDTs in project |
export_udts | Export UDTs to XML (all or specific) |
import_udt | Import UDT from XML |
delete_udt | Delete a UDT |
File Conversions (Stateless)
| Tool | Description |
|---|---|
convert_format | Convert between XML, JSON, and SCL formats |
convert_plc_tag_xml_to_excel | Convert tag XML to Excel |
convert_excel_to_plc_tag_xml | Convert Excel to tag XML |
Key Feature: Create Blocks from SCL
Create TIA Portal blocks directly from SCL code without file system access:
result = await call_tool("create_block_from_scl", {
"session_id": "your-session-id",
"scl_content": """FUNCTION_BLOCK "FB_Motor"
VAR_INPUT
Enable : Bool;
Speed : Real;
END_VAR
VAR_OUTPUT
Running : Bool;
END_VAR
BEGIN
IF #Enable THEN
#Running := TRUE;
END_IF;
END_FUNCTION_BLOCK
""",
"block_name": "FB_Motor",
"target_folder": "Motors"
})
Key Feature: Cross-Reference Analysis
Analyze block dependencies and find unused code in your TIA Portal project:
# Get what a block uses (outgoing references)
result = await call_tool("get_cross_references", {
"session_id": "your-session-id",
"block_name": "FB_MainSequence",
"filter": "AllObjects" # or ObjectsWithReferences, UnusedObjects
})
# Returns: FB_Blink, FB_Warning, DB_Global, etc.
# Get what uses a block (incoming references)
result = await call_tool("get_block_dependents", {
"session_id": "your-session-id",
"block_name": "FB_MainSequence"
})
# Returns: Main (OB1), DB_MainSequence (Instance DB)
# Find unused blocks for project cleanup
result = await call_tool("get_unused_blocks", {
"session_id": "your-session-id",
"verify_global_db": True # Secondary verification for Global DBs
})
# Returns only truly unused blocks (filters out false positives for Global DBs)
Note: The get_unused_blocks tool performs secondary verification for Global DBs to avoid false positives. Global DBs accessed via symbolic names (e.g., "DB_Global".myVar) are correctly detected as used.
Consolidated Tool APIs
Several tools have been consolidated to reduce context overhead. Here are the new APIs:
convert_format - Universal Format Converter
# Convert XML to SCL
result = await call_tool("convert_format", {
"input_path": "path/to/block.xml",
"from_format": "xml",
"to_format": "scl",
"output_path": "path/to/output.scl" # optional
})
# Supported conversions: xml↔json, json↔scl, xml↔scl
compile - Unified Compilation
# Compile entire project
result = await call_tool("compile", {
"session_id": "your-session-id",
"target": "project"
})
# Compile specific device
result = await call_tool("compile", {
"session_id": "your-session-id",
"target": "device",
"name": "PLC_1"
})
# Compile specific block
result = await call_tool("compile", {
"session_id": "your-session-id",
"target": "block",
"name": "FB_Motor"
})
export_tag_tables - Tag Table Export
# Export all tag tables
result = await call_tool("export_tag_tables", {
"session_id": "your-session-id",
"output_path": "./exports"
})
# Export specific tables
result = await call_tool("export_tag_tables", {
"session_id": "your-session-id",
"table_names": ["Inputs", "Outputs"],
"output_path": "./exports"
})
export_udts - UDT Export
# Export all UDTs
result = await call_tool("export_udts", {
"session_id": "your-session-id",
"output_path": "./exports"
})
# Export specific UDTs
result = await call_tool("export_udts", {
"session_id": "your-session-id",
"udt_names": ["UDT_Motor", "UDT_Valve"],
"output_path": "./exports"
})
Configuration
The server uses tia_portal_mcp.json for configuration (auto-created on first run):
{
"paths": {
"tia_portal": {
"installation_path": "C:\\Program Files\\Siemens\\Automation\\Portal V20"
}
},
"settings": {
"session": {
"timeout_seconds": 3600,
"max_concurrent": 3
}
}
}
Environment Variables
| Variable | Default | Description |
|---|---|---|
TIA_SESSION_TIMEOUT | 3600 | Session timeout in seconds |
TIA_MAX_SESSIONS | 3 | Maximum concurrent sessions |
TIA_DEBUG | 0 | Enable debug logging |
Troubleshooting
| Issue | Solution |
|---|---|
| Server won't start | Run python MCP_Server/start_server.py test for diagnostics |
| "TIA Portal not found" | Verify TIA Portal installation path in tia_portal_mcp.json |
| "Session not found" | Session expired - create a new session |
| "No project is open" | Call open_project before project operations |
| Export fails | Check write permissions and clean ~/.tia_portal/exported_blocks/ |
| Slow operations | TIA Portal operations are inherently slow; use caching where possible |
Documentation
- - Development guide
- - Complete tool documentation with examples
License
See LICENSE file for details.