22namespace neograph::mcp {
29struct NEOGRAPH_API MCPServerConfig {
30 json server_info = json::object();
31 std::string instructions;
32 std::size_t max_concurrent_calls = 4;
33 std::size_t max_pending_calls = 64;
55 using ToolHandler = std::function<CallToolResult(
56 const json&,
const std::shared_ptr<graph::CancelToken>&)>;
60 std::function<json(
const json&,
const std::shared_ptr<graph::CancelToken>&,
const json&)>;
74 explicit MCPServer(MCPServerConfig config);
96 using Reply = std::function<void(std::optional<json>)>;
113 void run(std::istream& in, std::ostream& out);
127 bool initialized()
const;
128 bool is_running()
const;
137 std::unique_ptr<Impl> impl_;
NEOGRAPH_API export/import macro for shared-library builds.
Cooperative cancellation primitive for graph runs.
Local, stdio-first MCP server with typed tools and bounded execution.
void register_raw_tool(ToolDefinition definition, RawToolHandler handler)
Add a tool whose result shape is selected using request metadata.
std::function< void(const json &id)> NoResponseSink
Receives the id of a request that ended without a response: the client cancelled it,...
void set_response_sink(ResponseSink sink)
Set the destination for asynchronously completed tool-call responses.
void register_tool(ToolDefinition definition, ToolHandler handler)
Add a tool. Names must be unique and registration closes at initialize.
void handle_message(const json &message, Reply reply)
Process one parsed message and pass its outcome to reply exactly once: before this returns,...
void register_method(std::string method, MethodHandler handler)
Register an extension JSON-RPC method before initialization.
std::function< json(const json &, const json &)> MethodHandler
Synchronous extension-method handler; the server wraps the JSON result.
void run(std::istream &in, std::ostream &out)
Drive newline-delimited MCP stdio until EOF or a message-boundary stop.
std::function< json(const json &, const std::shared_ptr< graph::CancelToken > &, const json &)> RawToolHandler
Extension hook for polymorphic tool results such as CreateTaskResult.
void set_response_sink(ResponseSink sink, NoResponseSink no_response)
As above; no_response receives the id of each call that ends without a response.
std::function< void(std::optional< json >)> Reply
The outcome of one message given to handle_message(message, reply): its response (an object,...
std::string protocol_version() const
The revision initialize negotiated: the client's when it is one of MCP_SUPPORTED_PROTOCOL_VERSIONS,...
void stop()
Cooperatively cancel outstanding calls and drain the worker pool.
std::function< void(const json &)> ResponseSink
Receives complete JSON-RPC response envelopes produced asynchronously.
void register_extension(std::string identifier, json settings=json::object())
Advertise an explicitly enabled MCP extension capability.
json handle_message(const json &envelope)
Process one parsed JSON-RPC message.
constexpr const char * MCP_PROTOCOL_VERSION
The newest revision the server negotiates.
Complete typed values for the supported MCP tools client surface.