Skip to main content
Glama

convert_encoding

Destructive

Convert files between text encodings, auto-detecting the source or using a specified from value. Preview batch migrations with dryRun and prevent corrupting narrowing conversions.

Instructions

Convert files between encodings. Parameters: path (one file) OR paths (a batch — never both), to (required), from (omit to auto-detect), backup (write .bak first), dryRun (report only), allowLowConfidence, bom ("auto" default, "always", "never", "preserve"). Refuses rather than corrupting: a narrowing conversion (utf-8 to cp1251) names the characters the target lacks with line and column, and an untrusted detection names its best guess — confirm it with from, or pass allowLowConfidence=true. A source BOM is stripped before decoding; one contradicting an explicit from is an error. No-op if the file already holds the target bytes. In a batch one bad file does not stop the rest. Run dryRun over a project first. Examples: {"path": "D:\legacy\data.txt", "to": "utf-8", "backup": true} leaves data.txt.bak; {"paths": ["a.pas", "b.pas"], "to": "utf-8", "dryRun": true} previews a migration.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYes
bomNo
fromNo
pathNo
pathsNo
backupNo
dryRunNo
allowLowConfidenceNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dryRunNo
errorsNo
hasBomYes
bomTypeNo
changedYes
messageYes
resultsNo
backupPathNo
errorCountNo
successCountNo
sourceEncodingNo
targetEncodingYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv4.2.0
    • addedInput schema / properties / allowLowConfidence
      Added value: +{
      +  "type": "boolean"
      +}
  2. Changed9 schema fields changedv3.3.0
    • addedInput schema / properties / dryRun
      Added value: +{
      +  "type": "boolean"
      +}
    • addedInput schema / properties / paths
      Added value: +{
      +  "items": {
      +    "type": "string"
      +  },
      +  "type": [
      +    "null",
      +    "array"
      +  ]
      +}
    • changedInput schema / required
      Previous value: -[
      -  "path",
      -  "to"
      -]New value: +[
      +  "to"
      +]
    • addedOutput schema / properties / dryRun
      Added value: +{
      +  "type": "boolean"
      +}
    • addedOutput schema / properties / errorCount
      Added value: +{
      +  "type": "integer"
      +}
    • addedOutput schema / properties / errors
      Added value: +{
      +  "items": {
      +    "type": "string"
      +  },
      +  "type": [
      +    "null",
      +    "array"
      +  ]
      +}
    • addedOutput schema / properties / results
      Added value: +{
      +  "items": {
      +    "additionalProperties": false,
      +    "properties": {
      +      "backupPath": {
      +        "type": "string"
      +      },
      +      "bomType": {
      +        "type": "string"
      +      },
      +      "changed": {
      +        "type": "boolean"
      +      },
      +      "error": {
      +        "type": "string"
      +      },
      +      "hasBom": {
      +        "type": "boolean"
      +      },
      +      "message": {
      +        "type": "string"
      +      },
      +      "path": {
      +        "type": "string"
      +      },
      +      "sourceEncoding": {
      +        "type": "string"
      +      },
      +      "unsupported": {
      +        "items": {
      +          "additionalProperties": false,
      +          "properties": {
      +            "char": {
      +              "type": "string"
      +            },
      +            "code": {
      +              "type": "string"
      +            },
      +            "column": {
      +              "type": "integer"
      +            },
      +            "line": {
      +              "type": "integer"
      +            }
      +          },
      +          "required": [
      +            "char",
      +            "code",
      +            "line",
      +            "column"
      +          ],
      +          "type": "object"
      +        },
      +        "type": [
      +          "null",
      +          "array"
      +        ]
      +      },
      +      "unsupportedCount": {
      +        "type": "integer"
      +      }
      +    },
      +    "required": [
      +      "path",
      +      "changed"
      +    ],
      +    "type": "object"
      +  },
      +  "type": [
      +    "null",
      +    "array"
      +  ]
      +}
    • addedOutput schema / properties / successCount
      Added value: +{
      +  "type": "integer"
      +}
    • changedOutput schema / required
      Previous value: -[
      -  "message",
      -  "sourceEncoding",
      -  "targetEncoding",
      -  "hasBom",
      -  "changed"
      -]New value: +[
      +  "message",
      +  "targetEncoding",
      +  "hasBom",
      +  "changed"
      +]
  3. Addedv0.1.1

TDQS

A4.6/5.0
Behavior5/5

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

Annotations already declare destructive/readOnly/idempotent status, but the description adds rich behavior: refuses rather than corrupting, names offending characters with line/column, handles BOM stripping and contradictions, no-ops on target bytes, and continues batches after one bad file.

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

Conciseness5/5

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

The description front-loads purpose, then compactly lists parameters, then adds behavioral notes and examples. Although long, every clause adds needed detail for an 8-parameter mutation tool with complex failure semantics.

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

Completeness5/5

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

With an output schema present, the description need not explain return values. It covers operation, parameters, failure modes, and batch semantics, leaving nothing critical for invoking correctly.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must carry parameter semantics. It fully documents all 8 parameters, including path OR paths mutual exclusion, backup .bak behavior, dryRun, allowLowConfidence, and bom enum values.

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 first sentence states a specific verb and resource: 'Convert files between encodings.' It does not explicitly name sibling tools such as detect_encoding or manage_bom to differentiate, but the conversion action is clear from the name and description.

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

Usage Guidelines4/5

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

It gives clear operational guidance: run dryRun first, use path XOR paths (never both), omit from to auto-detect. However, it does not state when to choose this tool over sibling tools like detect_encoding or manage_bom, so sibling selection is left implicit.

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