# fsharp-refactor [Health: Active]

**Category:** 💻 Developer Tools  
**Repository:** https://github.com/Thorium/fsharp-refactor  
**GitHub Stars:** 17  
**Views:** 1  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/fsharp-refactor

## Description
FSharp refactoring tool - The tool clarifies the (agent-generated or old) code's intent, reduces non-alphanumeric noise, and uses built-in .NET libraries more efficiently.

## Claude Desktop Quick Installation
No generated config for this server: it installs through its own setup steps.

The project's own setup steps (from https://github.com/Thorium/fsharp-refactor), copied verbatim. Follow them in order; they are not an mcpServers config.

1. Install:

```sh
dotnet tool install --global fsharp-refactor
```

## Documentation

## What fsharp-refactor does

fsharp-refactor provides functional refactoring suggestions for F# code through a .NET command-line tool with MCP support for agentic scenarios. Its rules target correctness, performance, idiomatic style, redundancy, diagnostics, and cosmetic improvements. Examples include replacing an ordinary binding with a `use` binding for disposable resources, simplifying boolean matches into conditionals, removing unnecessary `new` syntax, and moving `Seq.map` before `Seq.toList`.

The suggestions have `Hint` severity. They identify opportunities rather than defects, do not block a build, and are intended to clarify code written by agents or older codebases. The implementation runs fully offline and does not use AI at runtime.

## How it works

The tool accepts a range of F# inputs. A project file uses its project configuration, a solution processes the F# projects listed by that solution, and a source file is analyzed in the context of its project while edits are limited to that file. It can also process an `.fsx` script without invoking MSBuild, a directory containing a solution or projects, or a glob matching project files.

For project inputs, the tool obtains compiler arguments from MSBuild. Scripts are resolved through F# Compiler Services instead. It runs the analyzers, applies non-overlapping fixes from the bottom of each file upward, and repeats analysis until another pass produces no changes. A fix can therefore enable a later fix.

Use `--dry-run` to print proposed changes with their file locations without writing files. Without that flag, the tool applies the selected fixes. It refuses to start when the input already has compilation errors and verifies the result after applying changes; if the edit introduces an error, the run fails. Existing warning-as-error settings remain in control of verification.

## Setup and configuration

Install the command-line tool as a global .NET tool:

```bash
dotnet tool install --global fsharp-refactor
```

A preview run can then target a project with:

```bash
fsharp-refactor Your.fsproj --dry-run --api-changes
```

Remove `--dry-run` to apply the changes. Omit `--api-changes` when public methods or other API changes should not be modified. Additional options can limit the run by rule code or category, control parallel jobs, and set the maximum number of passes.

The analyzer assemblies are also distributed in the `FSharp.Refactor.Analyzers` package. They can be hosted by `fsharp-analyzers` for reporting in local or CI workflows, including SARIF output, while the `fsharp-refactor` tool is responsible for editing files. Repository-specific rule settings can be placed in `fsharprefactor.json`.

For editor diagnostics and light-bulb fixes, the project provides VS Code/Ionide and Visual Studio extensions. Ionide can load the analyzer package through its analyzer settings, and the Visual Studio extension uses an FsAutoComplete sidecar.

## Tools and capabilities

- Analyze a project, solution, source file, script, directory, or glob.
- Report every proposed fix with its file and position.
- Apply fixes directly after an explicit non-dry-run invocation.
- Restrict execution to selected rule codes or categories.
- Repeat analysis until enabled fixes reach a stable result.
- Validate the starting and resulting code through compilation checks.
- Provide analyzer diagnostics and quick fixes through supported editor integrations.

## Limitations and notes

The command-line tool does not silently rewrite files: editing requires leaving off `--dry-run`. API-affecting changes are opt-in through `--api-changes`. A project that does not already compile is rejected, and warning settings can cause a proposed change to be rolled back during verification.

The analyzer package is a development dependency and is not copied into compiled output. In CI, `fsharp-analyzers` reports findings but does not edit source files; applying changes requires the separate `fsharp-refactor` tool. Script analysis can begin without an MSBuild step, but unresolved script references are handled only by the syntactic rules that can run in that context.

The editor integrations depend on FsAutoComplete and matching analyzer SDK assemblies. Ionide and newer FsAutoComplete versions use different analyzer assemblies packaged side by side so the host can load the compatible one.

_Full upstream README: https://allmcps.com/mcp/fsharp-refactor/readme_

