跳转到主内容

MCP 服务器

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

Oh My Posh MCP 服务器是什么?

Oh My Posh MCP(模型上下文协议)服务器是一个验证服务,可让您根据官方 JSON 模式验证 oh-my-posh 主题配置。它支持 JSON、YAML 和 TOML 格式,并提供详细的错误报告,帮助您创建有效的配置。

功能更新

  • 多格式支持:验证 JSON、YAML 和 TOML 配置

  • 详细错误报告:获取包含 JSON 路径的精准验证错误

  • 格式自动检测:自动识别配置文件的格式

  • 警告与建议:接收最佳实践建议和弃用警告

  • 基于标准:使用官方 oh-my-posh JSON 模式

  • 远程访问:无需安装 - 通过 HTTPS 访问

使用指南

通过 MCP 客户端使用

配置兼容 MCP 的客户端(如 Claude Desktop、Cline 或其他 AI 助手)使用验证器:

{
"mcpServers": {
"oh-my-posh-validator": {
"url": "https://ohmyposh.dev/api/mcp",
"transport": "http"
}
}
}

然后让您的 AI 助手验证 oh-my-posh 配置。

直接 HTTP API

您也可以通过 HTTP 请求直接使用验证器。

获取服务器信息

curl https://ohmyposh.dev/api/mcp

列出可用工具

curl -X POST https://ohmyposh.dev/api/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/list",
"id": 1
}'

验证配置

curl -X POST https://ohmyposh.dev/api/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "validate_config",
"arguments": {
"content": "{\"$schema\":\"https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json\",\"version\":4,\"blocks\":[]}",
"format": "json"
}
},
"id": 1
}'

工具参数

validate_config

参数:

ParameterTypeRequiredDescription
contentstringYesThe configuration content as a string (JSON, YAML, or TOML)
formatstringNoThe format: json, yaml, toml, or auto (default: auto)

返回结果:

{
"valid": true,
"errors": [],
"warnings": [
{
"path": "$schema",
"message": "Consider adding \"$schema\" property for better editor support.",
"type": "recommendation"
}
],
"detectedFormat": "json",
"parsedConfig": { ... }
}

响应字段

FieldTypeDescription
validbooleanWhether the configuration is valid
errorsarrayList of validation errors (empty if valid)
warningsarrayList of warnings and recommendations
detectedFormatstringThe detected or specified format
parsedConfigobjectThe parsed configuration object

错误格式

errors 数组中的每个错误包含:

FieldTypeDescription
pathstringJSON path to the problematic property
messagestringHuman-readable error message
keywordstringThe validation keyword that failed
paramsobjectAdditional parameters about the error
dataanyThe actual data that failed validation

示例

有效配置示例

{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"version": 4,
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "path",
"style": "powerline",
"background": "blue",
"foreground": "white"
}
]
}
]
}

无效配置示例

{
"blocks": [
{
"type": "invalid-type"
}
]
}

验证结果:

{
"valid": false,
"errors": [
{
"path": "/blocks/0/type",
"message": "Value must be one of: prompt, rprompt, line",
"keyword": "enum"
}
]
}

集成示例

Claude Desktop

添加到 Claude Desktop 配置中(macOS 路径为 ~/Library/Application Support/Claude/config.json):

{
"mcpServers": {
"oh-my-posh-validator": {
"url": "https://ohmyposh.dev/api/mcp",
"transport": "http"
}
}
}

然后询问 Claude:"请帮我验证这个 oh-my-posh 配置" 并粘贴您的配置。

Cline(VS Code 扩展)

配置 Cline 使用 MCP 服务器后,当您处理 oh-my-posh 主题时,它会自动验证配置。

支持格式

JSON

{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"version": 4,
"blocks": []
}

YAML

$schema: https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json
version: 4
blocks: []

TOML

version = 4
blocks = []

隐私与安全

  • 您的配置内容不会被存储或记录

  • 所有验证均在内存中进行,处理完成后立即丢弃

  • 服务器仅从代码仓库读取官方模式

  • 无需身份验证 - 完全匿名

源代码

MCP 服务器是开源项目,属于 oh-my-posh 代码库:

故障排除

格式检测失败

如果自动检测失败,请显式指定格式:

{
"arguments": {
"content": "...",
"format": "yaml"
}
}

解析错误

如果遇到解析错误,请先检查配置是否为有效的 JSON/YAML/TOML 语法,再进行模式验证。

模式错误

该验证器使用主分支的最新架构。如果您使用的是旧版 oh-my-posh,某些新属性可能无法被识别。

参与贡献

发现错误或有建议?请在 GitHub 上提交问题