| 1 | //===- Tool.h -------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLDB_PLUGINS_PROTOCOL_MCP_TOOL_H |
| 10 | #define LLDB_PLUGINS_PROTOCOL_MCP_TOOL_H |
| 11 | |
| 12 | #include "Protocol.h" |
| 13 | #include "lldb/Core/Debugger.h" |
| 14 | #include "llvm/Support/JSON.h" |
| 15 | #include <string> |
| 16 | |
| 17 | namespace lldb_private::mcp { |
| 18 | |
| 19 | class Tool { |
| 20 | public: |
| 21 | Tool(std::string name, std::string description); |
| 22 | virtual ~Tool() = default; |
| 23 | |
| 24 | virtual llvm::Expected<protocol::TextResult> |
| 25 | Call(const protocol::ToolArguments &args) = 0; |
| 26 | |
| 27 | virtual std::optional<llvm::json::Value> GetSchema() const { |
| 28 | return llvm::json::Object{{.K: "type" , .V: "object" }}; |
| 29 | } |
| 30 | |
| 31 | protocol::ToolDefinition GetDefinition() const; |
| 32 | |
| 33 | const std::string &GetName() { return m_name; } |
| 34 | |
| 35 | private: |
| 36 | std::string m_name; |
| 37 | std::string m_description; |
| 38 | }; |
| 39 | |
| 40 | class CommandTool : public mcp::Tool { |
| 41 | public: |
| 42 | using mcp::Tool::Tool; |
| 43 | ~CommandTool() = default; |
| 44 | |
| 45 | virtual llvm::Expected<protocol::TextResult> |
| 46 | Call(const protocol::ToolArguments &args) override; |
| 47 | |
| 48 | virtual std::optional<llvm::json::Value> GetSchema() const override; |
| 49 | }; |
| 50 | |
| 51 | } // namespace lldb_private::mcp |
| 52 | |
| 53 | #endif |
| 54 | |