Skip to main content
Glama
utf8-file-ops

utf8-file-ops

by Pranav-stac

Cursor Write Edit Tool

Add to Cursor

An MCP server for Cursor that writes and edits files as UTF-8 on Windows.

Why I built this

I was hitting a frustrating issue on Windows with Cursor's built-in Agent Write and StrReplace tools — files were sometimes saved as UTF-16 instead of UTF-8. That broke builds (SyntaxError, illegal character '\0', etc.) and wasted time fixing corrupted source files.

So I made this tool. It uses MCP to write and edit files directly as UTF-8. In my experience it works well and fixes the encoding problem.

One drawback: you usually can't see the edits inline in Cursor the same way you do with the built-in Write/StrReplace diff view. The file changes on disk, but Cursor may not show a nice side-by-side preview of what changed.

Line endings: Windows files often use CRLF while the agent sends LF. utf8_replace now normalizes line endings before matching, so multi-line JSX/TSX edits should work. If a replace still fails, use utf8_write to rewrite the full file.

Related MCP server: Encoding MCP Server

Tools

Tool

Use when

Description

utf8_edit_lines

Multi-line JSX/TSX

Replace lines by number (no unique old_string needed)

utf8_replace

Small text swaps

EOL-aware replace; returns diff; rich errors on failure

utf8_batch

Many edits

Several write/replace/edit ops in one call

utf8_patch

Unified diff

Apply a single @@ hunk

utf8_write

New files / full rewrite

UTF-8 write; returns diff when overwriting

utf8_verify

Encoding check

Detect/fix UTF-16 corruption

MCP server id in Cursor: user-cursor-write-edit-tool

Requirements

  • Node.js 18+

  • Cursor with MCP support

  • Windows (this is mainly for the Cursor UTF-16 write bug on Windows)

Install in Cursor

One-click install

  1. Click Add to Cursor above

  2. Approve the install prompt

  3. Restart Cursor if the tools do not appear immediately

No clone or manual mcp.json editing required — it runs via npx from GitHub.

Manual install

Add to ~/.cursor/mcp.json (global) or .cursor/mcp.json (project):

{
  "mcpServers": {
    "cursor-write-edit-tool": {
      "command": "npx",
      "args": ["-y", "github:Pranav-stac/cursor-write-edit-tool"]
    }
  }
}

Restart Cursor after saving.

Agent usage

Prefer this MCP for source files on Windows. If utf8_replace fails twice, use utf8_edit_lines with line numbers. Built-in Write/StrReplace are fine as a fallback.

Tool results include a diff field (removed / added / unified) — show that to the user since inline diffs may not appear.

Write a file

{
  "path": "C:\\project\\src\\app.ts",
  "contents": "export const app = 'ok';\n"
}

Replace text

{
  "path": "C:\\project\\src\\app.ts",
  "old_string": "'ok'",
  "new_string": "'ready'",
  "replace_all": false
}

On failure you get reason, candidates (line + snippet), and hints — not just old_string not found.

Edit by line range (best for multi-line JSX)

{
  "path": "C:\\project\\src\\page.tsx",
  "start_line": 42,
  "end_line": 48,
  "new_string": "<section>\n  <h1>Title</h1>\n</section>"
}

Verify / fix encoding

{
  "path": "C:\\project\\src\\app.ts",
  "fix": true
}

Revert limitations

This tool writes files directly to disk through MCP. That means:

Action

Works?

Cursor Agent Revert button in chat

Usually no — MCP edits are not tracked like built-in Write/StrReplace

Editor Undo (Ctrl+Z)

Sometimes — only if the file is open and you undo right away

Git revert / restore

Yes — recommended

Cursor Local History / Timeline

Often yes

Use git carefully. Commit or stash before long agent sessions. Do not rely on Cursor's revert for MCP-made changes.

git add -A && git commit -m "checkpoint before agent session"

If something goes wrong:

git restore .
# or
git checkout -- path/to/file

Development

git clone https://github.com/Pranav-stac/cursor-write-edit-tool.git
cd cursor-write-edit-tool
npm install
npm test
npm start

License

MIT

Available Tools

3 tools
utf8_replaceA

Replace text in an existing file and save as UTF-8. Use instead of Cursor StrReplace on Windows.

Inputs: path (required), new_string (required), old_string (required), replace_all.

utf8_verifyB

Check whether a file is valid UTF-8 and optionally fix UTF-16 corruption.

Inputs: path (required), fix.

utf8_writeA

Create or overwrite a file as UTF-8 (no BOM). Use instead of Cursor Write on Windows.

Inputs: path (required), contents (required), newline.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 3 tools

    Disambiguation5/5

    Each tool has a clearly distinct role: write creates/overwrites, replace edits existing content, and verify checks/fixes encoding. There is no meaningful overlap between them.

    Naming Consistency5/5

    All tool names follow the uniform utf8_<verb> pattern with snake_case throughout, making the set predictable and easy to navigate.

    Tool Count5/5

    Three tools is a well-scoped size for a narrow, purpose-built server focused on UTF-8 file operations. Each tool earns its place without redundancy.

    Completeness4/5

    The set covers the core operations implied by the domain: write, replace, and verify. A read or conversion tool could round it out, but the stated UTF-8-focused purpose is reasonably complete.

    Maintenance

    ActivityStale
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables comprehensive file operations including reading, writing, searching, and editing files with advanced features like regex-based replacements, line-specific modifications, and directory-wide search capabilities. Provides 8 robust tools for safe file manipulation with content verification and detailed error handling.
      8
      9 npm
      2
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables creation and management of UTF-8 with BOM encoded files optimized for Windows build environments. Provides file encoding conversion, detection, and template support for C++ and PowerShell files to prevent Korean character encoding issues.
      4
      1
      MIT
    • F
      license
      Not graded
      quality
      C
      maintenance
      Enables AI assistants to read and write non-UTF-8 files (e.g., GBK, GB18030) on Windows by automatically detecting and converting encodings, preventing garbled text.
      7
      -
    • F
      license
      B
      quality
      D
      maintenance
      Windows-first MCP server for deterministic file writes with atomic create, replace, and structured edit operations, preserving encoding and newline styles.
      10
      1
      -