Skip to main content
Glama
agenticcontrolio

TwinCAT Validator MCP Server

extract_methods_to_xml

Convert inline METHOD blocks in TwinCAT ST code to structured XML elements for improved organization and IEC 61131-3 compliance.

Instructions

Promote inline METHOD blocks from main ST to XML elements.

Args: file_path: Path to .TcPOU file create_backup: Create .bak backup when content changes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
create_backupNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core implementation of the extract_methods_to_xml tool which promotes inline METHOD blocks to <Method> XML nodes.
    def extract_methods_to_xml(file_path: str, create_backup: bool = True) -> str:
        """Promote inline METHOD blocks from main ST to <Method> XML elements.
    
        Args:
            file_path: Path to .TcPOU file
            create_backup: Create .bak backup when content changes
        """
        _t0 = time.monotonic()
        try:
            path, error = _validate_file_path(file_path, start_time=_t0)
            if error:
                return error
    
            file = TwinCATFile.from_path(path)
            if file.suffix != ".TcPOU":
                return _tool_error(
                    "extract_methods_to_xml only supports .TcPOU files",
                    file_path=file_path,
                    start_time=_t0,
                )
    
            before_hash = _sha256_text(file.content)
            changed, methods_extracted = _promote_inline_methods_to_xml(file)
            backup_path = None
            if changed:
                backup_path = file.save(create_backup=create_backup)
    
            after_hash = _sha256_text(file.content)
            return _with_meta(
                {
                    "success": True,
                    "file_path": str(file.filepath),
                    "content_changed": changed,
                    "methods_extracted": methods_extracted,
                    "backup_created": create_backup and changed,
                    "backup_path": str(backup_path) if backup_path else None,
  • Registration of the extract_methods_to_xml tool within the server.
    extract_methods_to_xml = _get_tool_fn("extract_methods_to_xml")
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses the backup creation behavior ('Create .bak backup when content changes'), implying file modification, but lacks explicit disclosure that it modifies the input file in-place, error handling behavior, or output format details despite the existence of an output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Appropriately concise with a clear single-sentence purpose statement followed by a structured Args block. No redundant text, though the Args section repeats information that ideally would be in the schema (necessary given 0% coverage).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Adequate for a 2-parameter tool with an output schema (which excuses return value documentation). However, given this is a file-modifying mutation tool with no annotations, the description should explicitly state the modification behavior rather than implying it only through the backup parameter.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Excellent compensation for 0% schema description coverage. The Args section documents both parameters: 'file_path' includes the specific '.TcPOU' extension context, and 'create_backup' explains the conditional backup behavior ('when content changes'). Provides the semantic meaning missing from the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific transformation: extracting inline METHOD blocks from main ST (Structured Text) into dedicated <Method> XML elements. It identifies the specific file format (.TcPOU) and operation type, though it doesn't explicitly differentiate from the generic 'process_twincat_single' sibling.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance provided on when to use this tool versus alternatives like 'process_twincat_single' or 'autofix_file'. Missing prerequisites (e.g., when extraction is appropriate) and exclusion criteria (e.g., files without inline methods).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/agenticcontrolio/twincat-validator-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server