The Power in your Hands
Search Site:
About
Features
Documentation
Download
Community
Main
Class Index
Namespaces
Modules
include
Pt
Mcp
ToolDeclaration.h
1
/*
2
* Copyright (C) 2020-2026 by Marc Boris Duerner
3
*
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
8
*
9
* As a special exception, you may use this file as part of a free
10
* software library without restriction. Specifically, if other files
11
* instantiate templates or use macros or inline functions from this
12
* file, or you compile this file and link it with other files to
13
* produce an executable, this file does not by itself cause the
14
* resulting executable to be covered by the GNU General Public
15
* License. This exception does not however invalidate any other
16
* reasons why the executable file might be covered by the GNU Library
17
* General Public License.
18
*
19
* This library is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
* Lesser General Public License for more details.
23
*
24
* You should have received a copy of the GNU Lesser General Public
25
* License along with this library; if not, write to the Free Software
26
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27
* MA 02110-1301 USA
28
*/
29
30
#ifndef PT_MCP_TOOLDECLARATION_H
31
#define PT_MCP_TOOLDECLARATION_H
32
33
#include <Pt/Mcp/Api.h>
34
#include <Pt/Mcp/Type.h>
35
#include <Pt/Mcp/ContentType.h>
36
#include <Pt/NonCopyable.h>
37
#include <string>
38
#include <vector>
39
40
namespace
Pt
{
41
42
namespace
Mcp {
43
49
class
PT_MCP_API
Tool
:
private
NonCopyable
50
{
51
public
:
52
Tool
(
const
std::string& name,
const
std::string& description);
53
54
~
Tool
();
55
56
Tool
& addParam(
const
std::string& name,
const
Type
& type,
57
const
std::string& description =
""
);
58
59
Tool
& setOptional(
const
std::string& paramName);
60
61
Tool
& setContent(
const
ContentType
& content);
62
63
const
std::string& name()
const
64
{
return
_name; }
65
66
const
std::string& description()
const
67
{
return
_description; }
68
69
const
std::vector<Property>& params()
const
70
{
return
_params; }
71
72
std::size_t paramCount()
const
73
{
return
_params.size(); }
74
75
int
getParamIndex(
const
std::string& name)
const
;
76
77
const
ContentType
& content()
const
;
78
79
private
:
80
std::string _name;
81
std::string _description;
82
std::vector<Property> _params;
83
const
ContentType
* _content;
84
};
85
86
92
class
PT_MCP_API
ToolDeclaration
:
private
NonCopyable
93
{
94
public
:
95
ToolDeclaration
(
const
std::string& serverName,
96
const
std::string& serverVersion);
97
98
~
ToolDeclaration
();
99
100
Tool
& addTool(
const
std::string& name,
const
std::string& description);
101
102
const
Tool
* getTool(
const
std::string& name)
const
;
103
104
const
std::string& serverName()
const
105
{
return
_serverName; }
106
107
const
std::string& serverVersion()
const
108
{
return
_serverVersion; }
109
115
static
std::string
preferredVersion
(
const
std::string& requested);
116
119
static
bool
isSupportedVersion
(
const
std::string& version);
120
123
void
toToolsList
(std::ostream& os)
const
;
124
130
void
toInitializeResult
(std::ostream& os,
131
const
char
* protocolVersion = 0)
const
;
132
133
private
:
134
std::string _serverName;
135
std::string _serverVersion;
136
std::vector<Tool*> _tools;
137
};
138
139
}
// namespace Mcp
140
141
}
// namespace Pt
142
143
#endif // PT_MCP_TOOLDECLARATION_H
Pt
Core module.
Definition:
Allocator.h:33
Pt::Mcp::ToolDeclaration::isSupportedVersion
static bool isSupportedVersion(const std::string &version)
Returns true if version is a supported protocol version.
Pt::Mcp::Type
JSON Schema type descriptor for MCP tool parameters.
Definition:
Type.h:46
Pt::Mcp::Tool
MCP tool descriptor.
Definition:
ToolDeclaration.h:50
Pt::Mcp::ToolDeclaration
MCP server and tool registry.
Definition:
ToolDeclaration.h:93
Pt::Mcp::ToolDeclaration::toInitializeResult
void toInitializeResult(std::ostream &os, const char *protocolVersion=0) const
Writes the initialize result JSON to the stream.
Pt::Mcp::ToolDeclaration::toToolsList
void toToolsList(std::ostream &os) const
Writes the tools/list result JSON to the stream.
Pt::Mcp::ToolDeclaration::preferredVersion
static std::string preferredVersion(const std::string &requested)
Returns the best supported protocol version for the given request.
Pt::Mcp::ContentType
Formats a tool result as MCP content.
Definition:
ContentType.h:120
Pt::NonCopyable
Protects derived classes from being copied.
Definition:
NonCopyable.h:54