内容
# 格式化 XAML 内容
[](https://www.nuget.org/packages/xaml-styler-mcp)
[](https://www.nuget.org/packages/xaml-styler-mcp)
[](https://github.com/airtaxi/XamlStylerMcp/actions/workflows/pack-and-publish.yml)
[](LICENSE.txt)
🌐 English | [한국어](README.ko.md)
xaml-styler-mcp 是一个 .NET 全局工具,通过 stdio MCP 服务器提供 [XamlStyler](https://github.com/Xavalon/XamlStyler) 功能。本地编码代理可以调用它来格式化 XAML 字符串、格式化 XAML 文件或检查文件是否会发生变化。
## 主要特点
- 通过 Codex、Claude Code、GitHub Copilot CLI、Gemini CLI 或任何支持 stdio MCP 服务器的提供商,格式化 XAML 内容。
- 使用 `mcp-install`、`mcp-remove` 或 `mcp-uninstall` 命令,在支持的提供商 CLI 中注册或删除服务器。
- 直接编辑任意 `mcp.json` 文件,适用于没有内置安装程序命令的提供商。
- 重用 `Settings.XamlStyler` 配置文件,并从文件路径自动发现它们。
- 在格式化磁盘上的文件时,保留文件编码。
## 安装
```powershell
dotnet tool install --global xaml-styler-mcp
```
更新现有安装:
```powershell
dotnet tool update --global xaml-styler-mcp
```
## 提供商设置
使用支持的提供商 CLI:
```powershell
xaml-styler-mcp mcp-install --provider codex
xaml-styler-mcp mcp-install --provider claude
xaml-styler-mcp mcp-install --provider copilot
xaml-styler-mcp mcp-install --provider gemini
xaml-styler-mcp mcp-install --provider all
```
删除注册:
```powershell
xaml-styler-mcp mcp-remove --provider codex
xaml-styler-mcp mcp-uninstall --provider claude
xaml-styler-mcp mcp-remove --provider all
```
默认 MCP 服务器名称是 `xaml-styler`。在需要时覆盖它:
```powershell
xaml-styler-mcp mcp-install --provider codex --name xaml-styler
```
## 自定义 mcp.json
对于其他提供商,直接传递目标 MCP 配置文件:
```powershell
xaml-styler-mcp mcp-install --config "C:\path\to\mcp.json"
```
这会添加:
```json
{
"mcpServers": {
"xaml-styler": {
"command": "xaml-styler-mcp",
"args": []
}
}
}
```
配置编辑器在读取时接受 JSON 注释和尾随逗号。它写入标准格式的 JSON,并在修改现有配置之前创建 `.bak` 文件。
## MCP 工具
- `format_xaml`:格式化 XAML 字符串并返回格式化内容。
- `format_xaml_file`:格式化 `.xaml` 或 `.axaml` 文件,默认情况下写入更改。
- `format_xaml_directory`:格式化目录中的 `.xaml` 和 `.axaml` 文件。设置 `recursive` 以包括子目录,排除 `bin` 和 `obj` 文件夹。
- `check_xaml_file`:检查 `.xaml` 或 `.axaml` 文件是否会发生变化。
- `check_xaml_directory`:检查目录中的 `.xaml` 和 `.axaml` 文件是否会发生变化。设置 `recursive` 以包括子目录,排除 `bin` 和 `obj` 文件夹。
每个工具都接受一个可选的 `configPath` 参数,指向 XamlStyler 设置文件。基于文件的工具在省略 `configPath` 时,会搜索父目录中的 `Settings.XamlStyler`。
## 手动服务器命令
在没有参数的情况下运行会启动 stdio MCP 服务器:
```powershell
xaml-styler-mcp
```
显示 CLI 帮助:
```powershell
xaml-styler-mcp help
xaml-styler-mcp --help
```
## 软件包开发
```powershell
dotnet restore
dotnet build
dotnet test
dotnet pack
```
## 许可证
xaml-styler-mcp 在 [MIT License](LICENSE.txt) 下获得许可。
XAML 格式化由 [XamlStyler](https://github.com/Xavalon/XamlStyler) 提供,获得 Apache-2.0 许可。参见 [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md) 和 [licenses/XamlStyler-Apache-2.0.txt](licenses/XamlStyler-Apache-2.0.txt)。
## 作者
由 [Howon Lee (airtaxi)](https://github.com/airtaxi) 创建。
在 OpenAI Codex 的帮助下构建。