FSharp.Refactor — Claude Code MCP server: what it does, how to install
Offline F# analyzer that strips parentheses, swaps slow constructs for fast ones, and makes agent-written or legacy code say what it means.
Open on GitHubWhat FSharp.Refactor does
The tool runs from the command line: fsharp-refactor Your.fsproj --dry-run --api-changes prints every change with file and line, fsharp-refactor Your.fsproj --api-changes applies them. Drop --api-changes to leave public methods alone. Inside: 150+ rules that swap new FileStream for use, string Contains "x" for char Contains 'x', match b with | true -> 1 | false -> 0 for if b then 1 else 0, and strip new before StringBuilder() and Attribute suffix from attributes.
Your project must compile before you run it: broken source is rejected upfront, and any edit that breaks the build stops execution with an error. Ships as a global dotnet tool, VS Code extension, Visual Studio 2022–2026 plugin, and NuGet analyzer package. MCP support is baked into the CLI version. Unlicense license.
What it helps with
- remove parentheses and the
newkeyword where they add no meaning - replace
raise (Exception "text")withfailwith "text" - move
Seq.toListafterSeq.mapso the full sequence is not copied before mapping - replace
matchon a boolean withif - add interpolation to
failwithwith variables that show what went wrong
Example prompts for the agent
- Run
fsharp-refactor src/Main.fsproj --dry-runand show me what would change - Apply all fixes to
Core.fsprojwithfsharp-refactor Core.fsproj --api-changes - Refactor every project in
src/without touching public signatures
How to install FSharp.Refactor
Install
The MCP registry has no launch command for it: see the repository README
Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about FSharp.Refactor
How to install FSharp.Refactor in Claude Code?
Install the global dotnet tool with dotnet tool install --global fsharp-refactor. MCP support is built into the CLI version; no separate MCP setup is needed.
What does FSharp.Refactor do?
Analyzes F# code and applies 150+ rules: strips redundant parentheses and new, swaps slow constructs (Contains "x" → Contains 'x'), replaces raise (Exception ...) with failwith, and match on a boolean with if. Runs offline, no AI involved.
Can FSharp.Refactor run on a broken project?
No. The tool requires a project that compiles before it starts, and stops immediately if an edit introduces a build error.