OpenParable
Skip to content
← Back to skills

MCP Tool Creator

Agent Building
mcp-tool-creator

MCP Tool Creator is an Agent Skill for agent building published in the bage2014/study repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

MCP 工具创建器。当用户需要为系统添加新的 MCP 工具时使用此技能。

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/bage2014/study/blob/HEAD/study-ai-best-practice/.trae/skills/mcp-tool-creator/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/mcp-tool-creator, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

MCP 工具创建器

功能描述

帮助为系统创建新的 MCP(Model Context Provider)工具,扩展系统的信息收集和数据提供能力。

何时使用

在以下情况调用此技能:

  • 为系统添加新的 MCP 工具
  • 集成外部服务到业务流程
  • 扩展系统的数据收集能力
  • 模拟上下文数据用于测试

核心功能

  • MCP服务创建:创建新的上下文数据提供服务
  • 数据模拟:生成模拟数据用于测试和验证
  • 服务集成:将外部服务集成到业务流程

输入参数

参数类型必填说明
serviceNameString是MCP服务名称
dataTypeString是数据类型
configMap否配置参数

输出格式

{
  "serviceName": "MyMcpService",
  "status": "SUCCESS",
  "dataType": "CUSTOM_DATA",
  "description": "自定义MCP服务创建成功"
}

MCP 服务结构

服务接口规范

@Service
public class MyMcpService {
    
    public SomeData getData(String appId, LocalDateTime time, String scene) {
        // 实现数据获取逻辑
        // 返回模拟或真实数据
    }
}

创建新 MCP 服务步骤

第一步:创建数据模型

public class CustomData {
    private String field1;
    private int field2;
    // getters and setters
}

第二步:创建 MCP 服务类

@Service
public class CustomMcpService {
    
    private final Random random = new Random();
    
    public CustomData getData(String appId, LocalDateTime time, String scene) {
        CustomData data = new CustomData();
        // 根据场景生成模拟数据
        if ("custom_scenario".equals(scene)) {
            // 特定场景数据
        } else {
            // 默认数据
            data.setField1("value-" + random.nextInt(100));
            data.setField2(random.nextInt(1000));
        }
        return data;
    }
}

第三步:集成到业务服务

@Service
public class BusinessServiceImpl {
    
    private final CustomMcpService customMcpService;
    
    // 在业务方法中调用
    CustomData customData = customMcpService.getData(appId, time, scene);
}

配置要求

无需额外配置,Spring Boot 自动扫描并注册 @Service 注解的 MCP 服务。

目录结构

src/main/java/com/bage/study/ai/best/practice/hello/
├── mcp/                    # MCP服务目录
│   └── CustomMcpService.java
└── service/
    └── impl/
        └── BusinessServiceImpl.java

使用示例

// 注入 MCP 服务
@Autowired
private CustomMcpService customMcpService;

// 获取数据
CustomData data = customMcpService.getData(appId, time, scene);

扩展指南

添加新的数据类型

  1. 创建新的数据模型类
  2. 创建对应的 MCP 服务类
  3. 在业务服务中注入并调用

支持场景参数

在 MCP 服务的方法中添加 scene 参数,根据不同场景返回不同的模拟数据。