morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::ui::McpAdapter Class Reference

Serves MCP's tools over one server connection (spec 8 §11). More...

#include <agent.hpp>

Public Member Functions

 McpAdapter (std::shared_ptr< backend::RemoteServer > server, McpOptions options)
 An adapter on a new connection of server.
 ~McpAdapter ()
 Closes the adapter's connection, releasing its private instances.
 McpAdapter (McpAdapter const &)=delete
McpAdapter & operator= (McpAdapter const &)=delete
 McpAdapter (McpAdapter &&)=delete
McpAdapter & operator= (McpAdapter &&)=delete
async::Completion< std::optional< std::string > > handle (std::string const &message)
 Handles one JSON-RPC message.

Detailed Description

Serves MCP's tools over one server connection (spec 8 §11).

It answers initialize, tools/list, tools/call and ping, and refuses every other request with JSON-RPC error -32601; a notification, which carries no id, gets no reply.

  • Tools. One per action the catalog lists as permitted for the session, named by the action id, whose inputSchema is the action's schema from schemas. A keyed model's tool also takes the instance key as the argument instance, and runs on the shared instance with that key. Any other model's tool runs on one private instance per model type, registered on the adapter's connection at its first call. A tool evaluate, taking {action, body}, is a dry run through ui-evaluate.
  • A call's result is the action's result JSON as text content, or the server's err message with isError.
  • The connection is opened when the adapter is made and closed when it is destroyed, which releases its private instances. The server treats it like any other connection, so its changes reach every watching GUI.

handle is called on the owner, McpOptions::callbacks, and its completion is delivered there.

Definition at line 79 of file agent.hpp.

Constructor & Destructor Documentation

◆ McpAdapter()

morph::ui::McpAdapter::McpAdapter ( std::shared_ptr< backend::RemoteServer > server,
McpOptions options )
inline

An adapter on a new connection of server.

Parameters
serverThe server; the adapter keeps it alive.
optionsIts options.
Exceptions
std::invalid_argumentwithout a server or a callbacks executor.

Definition at line 85 of file agent.hpp.

◆ ~McpAdapter()

morph::ui::McpAdapter::~McpAdapter ( )
inline

Closes the adapter's connection, releasing its private instances.

Definition at line 94 of file agent.hpp.

Member Function Documentation

◆ handle()

async::Completion< std::optional< std::string > > morph::ui::McpAdapter::handle ( std::string const & message)
inlinenodiscard

Handles one JSON-RPC message.

Parameters
messageThe message's JSON text.
Returns
Completes with the reply's JSON text, or with nothing for a notification. It never fails: a fault is answered as a JSON-RPC error.

Definition at line 111 of file agent.hpp.


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