openmanus.cpp/include/tool_base.h

54 lines
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef OPENMANUS_TOOL_BASE_H
#define OPENMANUS_TOOL_BASE_H
#include <string>
#include <vector>
#include <functional>
#include "mcp/include/mcp_message.h"
#include "mcp/include/mcp_tool.h"
namespace openmanus {
/**
* @class ToolBase
* @brief 工具的基类,定义了所有工具的基本接口
*/
class ToolBase {
public:
ToolBase(const std::string& name, const std::string& description);
virtual ~ToolBase() = default;
/**
* @brief 执行工具
* @param params 工具参数
* @return 执行结果
*/
virtual mcp::json execute(const mcp::json& params) = 0;
/**
* @brief 获取工具名称
* @return 工具名称
*/
std::string getName() const { return name_; }
/**
* @brief 获取工具描述
* @return 工具描述
*/
std::string getDescription() const { return description_; }
/**
* @brief 获取工具参数定义
* @return 参数定义
*/
mcp::json getParameters() const { return parameters_; }
protected:
std::string name_;
std::string description_;
mcp::json parameters_; // 参数定义使用JSON Schema格式
};
} // namespace openmanus
#endif // OPENMANUS_TOOL_BASE_H