NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
neograph::mcp::MCPTool Class Reference

Wraps a remote MCP server tool as a local Tool. More...

#include <client.h>

Inheritance diagram for neograph::mcp::MCPTool:
[legend]
Collaboration diagram for neograph::mcp::MCPTool:
[legend]

Public Member Functions

asio::awaitable< std::string > execute_async (const json &arguments) override
 Execute the tool on the MCP server.
 
asio::awaitable< std::string > execute_async (const json &arguments, ToolExecutionContext context) override
 What every dispatcher calls (ToolExecutionController): the call is bounded by the run's cancel token and deadline, as above.
 
CallToolResult execute_result (const json &arguments)
 Typed execution preserving all content block kinds and MCP result fields.
 
asio::awaitable< CallToolResult > execute_result_async (const json &arguments, ToolExecutionContext context)
 Typed execution bounded by the dispatcher's context: its cancel token and deadline stop waiting for the response, which is then dropped.
 
ChatTool get_definition () const override
 Get the tool definition metadata.
 
const ToolDefinition & get_mcp_definition () const noexcept
 Full MCP definition, including outputSchema and annotations.
 
std::string get_name () const override
 Get the tool name.
 
 MCPTool (const std::string &server_url, const std::string &name, const std::string &description, const json &input_schema)
 Direct HTTP constructor for one known tool.
 
- Public Member Functions inherited from neograph::AsyncTool
std::string execute (const json &arguments) final
 Sync facade — drives execute_async on a private io_context.
 

Detailed Description

Wraps a remote MCP server tool as a local Tool.

MCPTool implements the Tool interface through the originating protocol session, independently of which transport owns the connection.

Definition at line 44 of file client.h.

Constructor & Destructor Documentation

◆ MCPTool()

neograph::mcp::MCPTool::MCPTool ( const std::string &  server_url,
const std::string &  name,
const std::string &  description,
const json &  input_schema 
)

Direct HTTP constructor for one known tool.

The tool opens one MCP session on its first call, reuses it for every later call, and ends it with DELETE when the tool is destroyed. server_url is the server's MCP endpoint URL, used as given. Prefer MCPClient(url).get_tools(), which shares one session among all of a server's tools and keeps their complete definitions.

Member Function Documentation

◆ execute_async() [1/2]

asio::awaitable< std::string > neograph::mcp::MCPTool::execute_async ( const json &  arguments)
overridevirtual

Execute the tool on the MCP server.

Parameters
argumentsJSON object containing the tool's input parameters.
Returns
Result string (text content joined by newlines) or JSON dump. Native async execution — overlaps with sibling tool calls when a node dispatches several at once. stdio correlates in-flight calls by JSON-RPC id; discovered HTTP tools reuse their originating session.

Implements neograph::AsyncTool.

◆ execute_async() [2/2]

asio::awaitable< std::string > neograph::mcp::MCPTool::execute_async ( const json &  arguments,
ToolExecutionContext  context 
)
overridevirtual

What every dispatcher calls (ToolExecutionController): the call is bounded by the run's cancel token and deadline, as above.

An isError result throws std::runtime_error, an ordinary tool failure.

Implements neograph::ContextualAsyncTool.

◆ execute_result_async()

asio::awaitable< CallToolResult > neograph::mcp::MCPTool::execute_result_async ( const json &  arguments,
ToolExecutionContext  context 
)

Typed execution bounded by the dispatcher's context: its cancel token and deadline stop waiting for the response, which is then dropped.

Cancellation throws graph::CancelledException; a deadline or request timeout throws asio::system_error(asio::error::timed_out).

◆ get_definition()

ChatTool neograph::mcp::MCPTool::get_definition ( ) const
overridevirtual

Get the tool definition metadata.

Returns a ChatTool containing the tool's name, description, and JSON Schema for its parameters. This is sent to the LLM so it can decide when to call the tool.

Returns
Tool definition including name, description, and parameter schema.

Implements neograph::Tool.

◆ get_name()

std::string neograph::mcp::MCPTool::get_name ( ) const
inlineoverridevirtual

Get the tool name.

Returns
Tool name string (must match the name in get_definition()).

Implements neograph::Tool.

Definition at line 88 of file client.h.


The documentation for this class was generated from the following file: