#include <Pt/Mcp/ToolDeclaration.h>
MCP server name, version and tool catalog. More...
Inherits NonCopyable.
Public Member Functions | |
| ToolDeclaration (const std::string &serverName, const std::string &serverVersion) | |
| Creates a declaration for a server named serverName. | |
| ~ToolDeclaration () | |
| Destroys the declaration and its tools. | |
| Tool & | addTool (const std::string &name, const std::string &description) |
| Creates a tool named name and returns it. | |
| const Tool * | getTool (const std::string &name) const |
| Returns the tool named name, or a null pointer. | |
| const std::string & | serverName () const |
| Returns the server name. | |
| const std::string & | serverVersion () const |
| Returns the server version string. | |
| void | toToolsList (std::ostream &os) const |
| Writes the tools/list result JSON to os. | |
| void | toInitializeResult (std::ostream &os, const char *protocolVersion=0) const |
| Writes the initialize result JSON to os. | |
Static Public Member Functions | |
| static std::string | preferredVersion (const std::string &requested) |
| Returns the protocol version to use for requested. | |
| static bool | isSupportedVersion (const std::string &version) |
| Returns true if version is a supported protocol version. | |
ToolDeclaration is the server catalog the tools group described. The constructor stores the server name and version that initialize returns. addTool() creates a Tool, owns it, and returns it so addParam() and setContent() can be chained. getTool() finds a tool by name, or returns a null pointer.
toToolsList() writes the tools/list result JSON from the declared tools and their schemas. toInitializeResult() writes the initialize result JSON, echoing protocolVersion when it is not null and the latest supported version otherwise. Transports call both. Application code rarely writes those payloads itself.
preferredVersion() returns requested when it is a supported protocol version, otherwise the latest supported version. isSupportedVersion() tests a version string. The supported versions are 2025-11-25 and 2025-03-26.
The declaration owns every Tool it creates. It does not own the Type or ContentType objects those tools refer to. The declaration is not copyable.
| ToolDeclaration | ( | const std::string & | serverName, |
| const std::string & | serverVersion ) |
serverVersion is the version string initialize returns.
| Tool & addTool | ( | const std::string & | name, |
| const std::string & | description ) |
The returned tool is owned by this declaration.
|
static |
If requested is supported it is returned verbatim. Otherwise the latest supported version is returned.
| void toInitializeResult | ( | std::ostream & | os, |
| const char * | protocolVersion = 0 ) const |
protocolVersion is the negotiated version string to echo. If null, the latest supported version is used.