mcpField
M
mcp-this

mcp-this

本地服务
github.com/shane-kercheval开发工具2050 周前更新

关于 mcp-this

mcp-this 是一个 MCP 服务,可通过 YAML 配置文件将命令行工具暴露为 MCP 工具,并定义可复用的提示词模板。它面向希望无需编写代码即可把现有命令接入 MCP 客户端的用户。

主要功能

  1. 01通过 YAML 将命令行命令定义为工具
  2. 02支持参数占位符与可选参数
  3. 03可定义结构化提示词模板
  4. 04提供 default、editing、github 等预设
  5. 05支持配置文件、JSON 字符串与环境变量三种方式

适用场景

  1. 01将 git 状态查询或端口检查等命令暴露给 Claude Desktop
  2. 02为代码审查或网页摘要编写可复用的提示词模板
  3. 03使用预设快速接入 GitHub 相关工具

MCP 相关

该项目是 MCP 服务,把 YAML 中定义的命令行命令与提示词模板暴露为 MCP 工具和提示词,供 Claude Desktop 等 MCP 客户端使用。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"this": {
"command": "uvx",
"args": [
"mcp-this"
]
}
}
}
启动命令uvx mcp-this

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
pypimcp-this

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

mcp-this

一个 MCP 服务,可通过 YAML 配置文件动态地将 CLI/bash 命令作为工具和提示词模板提供。

mcp-this 可将任意命令行工具转换为 MCP 工具,并创建结构化提示词模板,供任何 MCP 客户端(例如 Claude Desktop)使用。无需编写代码,只需在 YAML 文件中定义命令、提示词及其参数,MCP 服务就会将它们提供给 Claude Desktop 等 MCP 客户端。

核心价值: 使用简单的 YAML 配置,将 CLI 命令转换为 MCP 工具,并创建可复用的提示词模板。


工作原理

在 YAML 中定义工具(CLI 命令)和提示词(AI 模板):

tools:
  get-current-time:
    description: |
      Display the current date and time in various formats.
      
      Examples:
      - get_current_time(format="iso") → 2025-05-18T17:17:39Z
      - get_current_time(format="readable") → Friday, May 18, 2025 5:17 PM
    execution:
      command: >-
        if [ "<<format>>" = "iso" ]; then 
          date -u +"%Y-%m-%dT%H:%M:%SZ"; 
        elif [ "<<format>>" = "readable" ]; then 
          date "+%A, %B %d, %Y %I:%M %p"; 
        else 
          echo "ISO: $(date -u +"%Y-%m-%dT%H:%M:%SZ")"; 
          echo "Readable: $(date "+%A, %B %d, %Y %I:%M %p")"; 
        fi
    parameters:
      format:
        description: "Time format: iso, readable, or empty for both"
        required: false

  system-info:
    description: Get basic system information
    execution:
      command: uname -a && echo "CPU: $(nproc) cores"
    parameters: {}

prompts:
  code-reviewer:
    description: Perform a thorough code review with best practices focus
    template: |
      Please review the following code with a focus on:
      - Code quality and best practices
      - Security vulnerabilities
      - Performance considerations
      {{#if focus_area}}- Special attention to: {{focus_area}}{{/if}}
      
      Code to review:
      {{code}}
      
      {{#if context}}Additional context: {{context}}{{/if}}
    arguments:
      code:
        description: Code to review
        required: true
      focus_area:
        description: Specific area to focus on (e.g., security, performance)
        required: false
      context:
        description: Additional context about the code
        required: false

在 Claude Desktop 中使用:

{
  "mcpServers": {
    "mcp-this-custom": {
      "command": "uvx",
      "args": ["mcp-this", "--config-path", "/path/to/your-tools.yaml"]
    }
  }
}

就是这么简单!Claude 现在可以:

  • 执行你的自定义 CLI 工具(get-current-time、system-info)
  • 使用你的结构化提示词模板(带引导式参数的 code-reviewer)

快速开始

1. 安装 uvx
# Install uv (includes uvx)
curl -LsSf https://astral.sh/uv/install.sh | sh
2. 创建你的第一个工具

创建 my-tools.yaml:

tools:
  web-scraper:
    description: Fetch a webpage and convert it to clean, readable text
    execution:
      command: curl -s '<<url>>' | lynx -dump -stdin
    parameters:
      url:
        description: URL of the webpage to fetch
        required: true

  find-large-files:
    description: Find files larger than specified size in a directory
    execution:
      command: find '<<directory>>' -type f -size +<<size>> -exec ls -lh {} \;
    parameters:
      directory:
        description: Directory to search
        required: true
      size:
        description: Minimum file size (e.g., 100M, 1G)
        required: true
2.1. 添加 AI 提示词模板(可选)

为 my-tools.yaml 添加结构化提示词模板:

tools:
  # ... your tools above ...

prompts:
  summarize-webpage:
    description: Generate a structured summary of webpage content
    template: |
      Please analyze the following webpage content and provide:
      
      1. **Main Topic**: What is this page about?
      2. **Key Points**: {{num_points}} most important points
      3. **Target Audience**: Who is this content for?
      {{#if focus}}4. **{{focus}} Analysis**: Specific insights about {{focus}}{{/if}}
      
      Content:
      {{content}}
    arguments:
      content:
        description: Webpage content to summarize
        required: true
      num_points:
        description: Number of key points to extract (default 5)
        required: false
      focus:
        description: Specific aspect to focus on (e.g., technical, business, educational)
        required: false

  file-analysis:
    description: Analyze files for specific purposes
    template: |
      Analyze the following files for {{analysis_type}}:
      
      {{#if criteria}}Focus on: {{criteria}}{{/if}}
      
      {{files}}
      
      Please provide:
      - Summary of findings
      - Recommendations
      - {{#if format}}Output in {{format}} format{{/if}}
    arguments:
      files:
        description: File contents or paths to analyze
        required: true
      analysis_type:
        description: Type of analysis (security, performance, quality, etc.)
        required: true
      criteria:
        description: Specific criteria or standards to check against
        required: false
      format:
        description: Output format (markdown, JSON, report, etc.)
        required: false

在 Claude Desktop 中使用提示词:

  1. 点击消息输入框中的 + 图标
  2. 选择“从 mcp-this-custom 添加”
  3. 选择你的提示词(例如,“summarize-webpage”)
  4. 填写参数——Claude 会引导你完成必填和选填字段
3. 配置 Claude Desktop

添加到你的 claude_desktop_config.json:

{
  "mcpServers": {
    "my-tools": {
      "command": "uvx",
      "args": ["mcp-this", "--config-path", "/path/to/my-tools.yaml"]
    }
  }
}
4. 重启 Claude Desktop

现在即可使用你的工具和提示词!Claude 可以:

  • 使用自定义 CLI 工具获取网页内容并查找大文件
  • 使用结构化提示词模板进行引导式分析和摘要生成

配置格式

工具定义
tools:
  tool-name:
    description: "Description with usage examples"
    execution:
      command: "command-template <<parameter1>> <<optional_param>>"
    parameters:
      parameter1:
        description: "Parameter description"
        required: true
      optional_param:
        description: "Optional parameter description"  
        required: false

要点:

  • 在命令中使用 <<parameter>> 占位符
  • 如果未提供参数,标记为 required: false 的参数会从命令中移除
  • 多行命令请使用 command: >-(不要使用 command: |)
提示词定义
prompts:
  prompt-name:
    description: "Prompt description"
    template: |
      Template with {{argument}} placeholders.
      {{#if optional_arg}}Conditional: {{optional_arg}}{{/if}}
    arguments:
      argument:
        description: "Argument description"
        required: true
      optional_arg:
        description: "Optional argument"
        required: false

提示词与工具的区别:

  • 工具执行命令,并使用 <<parameter>> 语法
  • 提示词生成文本模板,并使用 Handlebars 的 {{argument}} 语法

配置方式

方式用法示例
YAML 文件--config-path <path>--config-path ./my-tools.yaml
JSON 字符串--config-value <json>--config-value '{"tools":{...}}'
环境变量MCP_THIS_CONFIG_PATHexport MCP_THIS_CONFIG_PATH=./tools.yaml
内置预设--preset <n>--preset default

预构建的工具和提示词集合(预设)

为方便使用,mcp-this 提供了可直接使用的工具和提示词集合:

  • default — 安全的只读工具(文件浏览、网页抓取)
  • editing — 文件操作工具(创建、编辑、删除)
  • github — GitHub 集成工具(PR 分析、仓库操作)+ 专用提示词(代码审查、创建 PR 描述)

快速使用:

{
  "mcpServers": {
    "mcp-this": {
      "command": "uvx", 
      "args": ["mcp-this", "--preset", "default"]
    }
  }
}

有关完整的预设文档、工具列表、依赖项和高级设置,请参阅 README_PRESETS.md。


实际示例

开发工作流工具
tools:
  git-status-summary:
    description: Get a concise overview of git repository status
    execution:
      command: >-
        echo "=== Branch ===" && git branch --show-current &&
        echo "=== Status ===" && git status --porcelain &&
        echo "=== Recent Commits ===" && git log --oneline -5
    parameters: {}

  test-runner:
    description: Run tests with optional pattern matching
    execution:
      command: >-
        if [ -n "<<pattern>>" ]; then
          npm test -- --grep "<<pattern>>"
        else
          npm test
        fi
    parameters:
      pattern:
        description: Test pattern to match (optional)
        required: false

  docker-container-logs:
    description: Get logs from a Docker container
    execution:
      command: docker logs <<container_name>> --tail <<lines>>
    parameters:
      container_name:
        description: Name or ID of the Docker container
        required: true
      lines:
        description: Number of log lines to show (default 100)
        required: false
        default: "100"
AI 驱动的工作流提示词
prompts:
  refactor-code:
    description: Guide code refactoring with specific goals and constraints
    template: |
      Please refactor the following code with these objectives:
      {{#if goals}}
      **Goals:**
      {{goals}}
      {{/if}}
      
      **Constraints:**
      - Maintain existing functionality
      - {{#if language}}Follow {{language}} best practices{{/if}}
      - {{#if performance}}Optimize for {{performance}}{{/if}}
      {{#if additional_constraints}}
      - {{additional_constraints}}
      {{/if}}
      
      **Code to refactor:**
      ```
      {{code}}
      ```
      
      Please provide:
      1. Refactored code with explanations
      2. Summary of changes made
      3. Potential risks or considerations
    arguments:
      code:
        description: Code to refactor
        required: true
      goals:
        description: Specific refactoring goals (e.g., improve readability, reduce complexity)
        required: false
      language:
        description: Programming language for best practices
        required: false
      performance:
        description: Performance optimization target (speed, memory, etc.)
        required: false
      additional_constraints:
        description: Any additional constraints or requirements
        required: false

  technical-documentation:
    description: Generate comprehensive technical documentation
    template: |
      Create {{doc_type}} documentation for:
      
      {{content}}
      
      **Requirements:**
      - Target audience: {{audience}}
      {{#if style}}- Documentation style: {{style}}{{/if}}
      {{#if sections}}- Include sections: {{sections}}{{/if}}
      - {{#if detail_level}}Detail level: {{detail_level}}{{/if}}
      
      {{#if examples}}**Include examples:** {{examples}}{{/if}}
      
      Please structure the documentation with clear headings, examples, and actionable information.
    arguments:
      content:
        description: Code, API, or system to document
        required: true
      doc_type:
        description: Type of documentation (API, user guide, technical spec, etc.)
        required: true
      audience:
        description: Target audience (developers, end-users, administrators, etc.)
        required: true
      style:
        description: Documentation style (formal, conversational, tutorial, reference)
        required: false
      sections:
        description: Specific sections to include
        required: false
      detail_level:
        description: Level of detail (high-level, detailed, comprehensive)
        required: false
      examples:
        description: Types of examples to include
        required: false
系统管理工具
tools:
  port-checker:
    description: Check what process is using a specific port
    execution:
      command: lsof -i :<<port>>
    parameters:
      port:
        description: Port number to check
        required: true

  service-status:
    description: Check the status of a system service
    execution:
      command: systemctl status <<service_name>>
    parameters:
      service_name:
        description: Name of the service to check
        required: true

  disk-usage-analyzer:
    description: Analyze disk usage and find largest directories
    execution:
      command: >-
        echo "=== Disk Usage Summary ===" &&
        df -h <<path>> &&
        echo "=== Largest Directories ===" &&
        du -h <<path>> | sort -hr | head -10
    parameters:
      path:
        description: Path to analyze (default current directory)
        required: false
        default: "."

Python API 用法

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

# Using custom configuration
server_params = StdioServerParameters(
    command='uvx',
    args=['mcp-this', '--config-path', '/path/to/tools.yaml'],
)

async with stdio_client(server_params) as (read, write):
    async with ClientSession(read, write) as session:
        await session.initialize()
        
        # List available tools
        tools = await session.list_tools()
        print([tool.name for tool in tools.tools])
        
        # Use a tool
        result = await session.call_tool(
            'git-status-summary',
            {}
        )
        print(result.content[0].text)

安装选项

通过 uvx 安装(推荐)
# No installation needed - uvx runs tools in isolated environments
uvx mcp-this --config-path ./my-tools.yaml
通过 pip 安装
pip install mcp-this
mcp-this --config-path ./my-tools.yaml
从源代码安装
git clone https://github.com/your-username/mcp-this.git
cd mcp-this
uv sync
python -m mcp_this --config-path ./my-tools.yaml

安全注意事项

⚠️ 重要: mcp-this 会根据你的配置执行 shell 命令。请务必:

  • 仅使用可信的配置文件
  • 在生产环境中验证用户输入
  • 以满足需求的最低权限运行
  • 考虑使用容器化来增强安全性
  • 检查命令是否包含危险操作

有关详细的安全指南,请参阅安全部分。


开发

Setup
git clone https://github.com/your-username/mcp-this.git
cd mcp-this
uv sync
Testing
make tests         # Run all tests
make unittests     # Unit tests only
make linting       # Linting only
make open_coverage # View coverage report
Building
make package-build    # Build package
make package-publish  # Publish (requires UV_PUBLISH_TOKEN)

License

Apache License 2.0

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。