NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <neograph/api.h>
17#include <neograph/tool.h>
18
19#include <asio/awaitable.hpp>
20
21#include <memory>
22#include <mutex>
23#include <string>
24#include <vector>
25
26namespace neograph::mcp {
27
28namespace detail {
32class StdioSession;
33}
34
42class NEOGRAPH_API MCPTool : public Tool {
43 public:
46 MCPTool(const std::string& server_url,
47 const std::string& name,
48 const std::string& description,
49 const json& input_schema);
50
54 MCPTool(std::shared_ptr<detail::StdioSession> session,
55 const std::string& name,
56 const std::string& description,
57 const json& input_schema);
58
59 ChatTool get_definition() const override;
60
66 std::string execute(const json& arguments) override;
67
68 std::string get_name() const override { return name_; }
69
70 private:
71 std::string server_url_;
72 std::shared_ptr<detail::StdioSession> stdio_session_;
73 std::string name_;
74 std::string description_;
75 json input_schema_;
76};
77
97class NEOGRAPH_API MCPClient {
98 public:
103 explicit MCPClient(const std::string& server_url);
104
114 explicit MCPClient(std::vector<std::string> argv);
115
121 bool initialize(const std::string& client_name = "neograph");
122
127 std::vector<std::unique_ptr<Tool>> get_tools();
128
135 json call_tool(const std::string& name, const json& arguments);
136
149 asio::awaitable<json> rpc_call_async(
150 const std::string& method,
151 const json& params = json::object());
152
153 private:
156 json rpc_call(const std::string& method, const json& params = json::object());
157
158 // HTTP state (empty strings when in stdio mode).
159 std::string server_url_;
160 std::string host_;
161 std::string path_prefix_;
171 mutable std::mutex http_state_mu_;
172 std::string session_id_;
178 std::string negotiated_protocol_version_;
179 int request_id_ = 0;
180
181 // stdio state (null when in HTTP mode).
182 std::shared_ptr<detail::StdioSession> stdio_session_;
183};
184
185} // namespace neograph::mcp
NEOGRAPH_API export/import macro for shared-library builds.
Abstract base class for tools that agents can call.
Definition tool.h:28
Client for connecting to MCP (Model Context Protocol) servers.
Definition client.h:97
MCPClient(std::vector< std::string > argv)
Construct a stdio-mode MCP client by spawning a subprocess.
json call_tool(const std::string &name, const json &arguments)
Call a tool directly by name.
bool initialize(const std::string &client_name="neograph")
Initialize the connection and perform the MCP handshake.
MCPClient(const std::string &server_url)
Construct an HTTP-mode MCP client.
std::vector< std::unique_ptr< Tool > > get_tools()
Discover tools from the MCP server.
asio::awaitable< json > rpc_call_async(const std::string &method, const json &params=json::object())
Async variant of rpc_call for the HTTP transport.
Wraps a remote MCP server tool as a local Tool.
Definition client.h:42
MCPTool(const std::string &server_url, const std::string &name, const std::string &description, const json &input_schema)
HTTP-mode constructor.
std::string execute(const json &arguments) override
Execute the tool on the MCP server.
std::string get_name() const override
Get the tool name.
Definition client.h:68
ChatTool get_definition() const override
Get the tool definition metadata.
MCPTool(std::shared_ptr< detail::StdioSession > session, const std::string &name, const std::string &description, const json &input_schema)
stdio-mode constructor.
Tool definition metadata sent to the LLM.
Definition types.h:51
Abstract tool interface for callable functions.