#include <Pt/Mcp/Service.h>
Synchronous MCP service over standard streams. More...
Public Member Functions | |
| Service (Remoting::ServiceDefinition &serviceDef, const ToolDeclaration &decl) | |
| Creates a service for serviceDef and decl. | |
| ~Service () | |
| Destroys the service. | |
| std::string | readMessage (std::istream &is) |
| Reads one Content-Length framed message from is. | |
| void | writeMessage (std::ostream &os, const std::string &json) |
| Writes a Content-Length framed message json to os. | |
| std::string | dispatch (const std::string &json) |
| Dispatches an MCP request and returns the response JSON. | |
Service is the synchronous stdio transport. It reads and writes Content-Length framed JSON-RPC messages and dispatches initialize, tools/list, and tools/call on the calling thread. Use it when every tool is a synchronous procedure. Asynchronous procedures need StdioService and an EventLoop.
readMessage() consumes one framed message from a stream and returns the JSON body, or an empty string on EOF. writeMessage() writes a Content-Length header and the JSON body. dispatch() runs the request and returns the response JSON, or an empty string for a notification.
The Pt::Remoting::ServiceDefinition and the ToolDeclaration are not owned. Both must outlive this service.
| std::string readMessage | ( | std::istream & | is | ) |
Returns the JSON body, or an empty string on EOF.
| std::string dispatch | ( | const std::string & | json | ) |
Returns an empty string for notifications (no id).