tia_portal_mcp_server

dgwoOstjfn/tia_portal_mcp_server

3.2

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 command needs 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_processes to discover TIA Portal instances you already have open, then attach_to_process to connect without opening a new instance.

Supported TIA Portal Versions

VersionStatus
V15.1Supported
V16Supported
V17Supported
V18Supported
V19Supported
V20Supported

Available Tools (35)

Session Management

ToolDescription
create_sessionCreate new TIA Portal session
close_sessionClose session and cleanup resources
list_sessionsList all active sessions
list_tia_processesList all running TIA Portal instances (no session required)
attach_to_processAttach to a running TIA Portal instance and create session

Project Operations

ToolDescription
open_projectOpen TIA Portal project (.ap* file)
save_projectSave current project
save_project_asSave project to new location with new name
close_projectClose current project
get_project_infoGet project metadata

Block Operations

ToolDescription
list_blocksList all blocks in project
export_blocksExport blocks to XML files
import_blocksImport blocks from XML files
create_block_from_sclCreate block directly from SCL code string
delete_blockDelete a block from project

Analysis Tools

ToolDescription
analyze_project_structureGet project tree structure
read_project_sourceRead SCL source code with filtering
cache_project_dataPre-cache all blocks for faster access
clear_cacheClear session cache

Cross-Reference Analysis

ToolDescription
get_cross_referencesGet outgoing references for a block (what it uses/calls)
get_block_dependentsGet incoming references for a block (what uses/calls it)
get_unused_blocksFind all unused blocks in project (with Global DB verification)
get_tag_cross_referencesGet cross-references for a PLC tag

Compilation

ToolDescription
compileCompile project, device, or block (use target param)
get_compilation_errorsGet compilation errors and warnings

PLC Tags

ToolDescription
list_tag_tablesList all tag tables
get_tag_table_detailsGet tags from specific table
export_tag_tablesExport tag tables to XML (all or specific)

UDTs (User-Defined Types)

ToolDescription
discover_all_udtsFind all UDTs in project
export_udtsExport UDTs to XML (all or specific)
import_udtImport UDT from XML
delete_udtDelete a UDT

File Conversions (Stateless)

ToolDescription
convert_formatConvert between XML, JSON, and SCL formats
convert_plc_tag_xml_to_excelConvert tag XML to Excel
convert_excel_to_plc_tag_xmlConvert 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

VariableDefaultDescription
TIA_SESSION_TIMEOUT3600Session timeout in seconds
TIA_MAX_SESSIONS3Maximum concurrent sessions
TIA_DEBUG0Enable debug logging

Troubleshooting

IssueSolution
Server won't startRun 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 failsCheck write permissions and clean ~/.tia_portal/exported_blocks/
Slow operationsTIA Portal operations are inherently slow; use caching where possible

Documentation

  • - Development guide
  • - Complete tool documentation with examples

License

See LICENSE file for details.