Service.h
1/* Copyright (C) 2020-2026 by Marc Boris Duerner
2 SPDX-License-Identifier: LGPL-2.1-or-later WITH mif-exception
3*/
4
5#ifndef PT_MCP_SERVICE_H
6#define PT_MCP_SERVICE_H
7
8#include <Pt/Mcp/Api.h>
9#include <Pt/Mcp/ToolDeclaration.h>
10#include <Pt/Remoting/ServiceDefinition.h>
11#include <string>
12#include <iosfwd>
13
14namespace Pt {
15
16namespace Mcp {
17
37class PT_MCP_API Service
38{
39 public:
43 const ToolDeclaration& decl);
44
48
53 std::string readMessage(std::istream& is);
54
57 void writeMessage(std::ostream& os, const std::string& json);
58
63 std::string dispatch(const std::string& json);
64
65 private:
66 std::string dispatchToolsCall(const std::string& json);
67 std::string dispatchInitialize(const std::string& json);
68 std::string dispatchToolsList(const std::string& json);
69
70 static std::string extractMethod(const std::string& json);
71 static Pt::int64_t extractId(const std::string& json);
72
73 Remoting::ServiceDefinition* _serviceDef;
74 const ToolDeclaration* _decl;
75};
76
77} // namespace Mcp
78
79} // namespace Pt
80
81#endif // PT_MCP_SERVICE_H
Service(Remoting::ServiceDefinition &serviceDef, const ToolDeclaration &decl)
Creates a service for serviceDef and decl.
~Service()
Destroys the service.
void writeMessage(std::ostream &os, const std::string &json)
Writes a Content-Length framed message json to os.
std::string readMessage(std::istream &is)
Reads one Content-Length framed message from is.
std::string dispatch(const std::string &json)
Dispatches an MCP request and returns the response JSON.
MCP server name, version and tool catalog.
Definition ToolDeclaration.h:126
Remote service definition.
Definition ServiceDefinition.h:59
int_type int64_t
Signed 64-bit integer type.
Definition Api-Types.h:59
Model Context Protocol (MCP) services.
Core module.
Definition Allocator.h:33