MCP servers that expose C++ procedures as tools. More...
Topics | |
| Parameter Schemas | |
| JSON Schema descriptors for MCP tool parameters. | |
| Tools and Server Declaration | |
| Declare an MCP server and its tools. | |
| Result Content | |
| Format a tool result as an MCP content block. | |
| HTTP Transport | |
| Serve MCP tools over HTTP. | |
| Standard I/O Transport | |
| Serve MCP tools over standard streams. | |
This module is an MCP server, so a caller registers ordinary C++ procedures and serves them as tools that a client can list and call. It is not an MCP client. The unit of work is a tool: a named procedure, a JSON Schema for its parameters, and a content type for its result. JSON-RPC is the envelope. Pt::Remoting supplies the procedure table. This module adds the MCP methods, the tool schemas, and the transports.
Work proceeds in four steps. A Pt::Remoting::ServiceDefinition holds the C++ functions or methods. A ToolDeclaration holds the matching tool names, descriptions, and parameter schemas. Each tool may name a ContentType for its result; the default is text. A transport then serves that pair: HttpService on an HTTP server, or Service / StdioService on standard streams.
The tool name in the declaration must be the procedure name in the definition. Arguments and results must be serializable, as in the other remoting modules: a type that can be written to SerializationInfo can be a tool parameter or a return value. Custom types are welcome when they have that support.
The declaration and the definition are not owned by the transport. Both must outlive the HttpService, Service, or StdioService that uses them. A Type named by a tool parameter must outlive that tool. Primitive schema types from integerType() and the other factories are process-wide singletons. Composed types (ObjectType, ArrayType, EnumType, NullableType) are owned by the caller. ToolDeclaration owns the Tool objects it creates. A ContentType used with Tool::setContent() must outlive the tool; textContent() and imageContent() are process-wide singletons.
The protocol methods are initialize, tools/list, and tools/call. Initialize negotiates a protocol version and returns the server name and version from the declaration. Tools/list returns the declared tools and their input schemas. Tools/call looks up the tool, maps named arguments onto the procedure, and writes the result as MCP content. A request without an id is a notification and produces no JSON-RPC body.
Supported protocol versions are 2025-11-25 and 2025-03-26. ToolDeclaration::preferredVersion() returns the requested version when it is supported, otherwise the latest. A tool that throws Pt::JsonRpc::Fault or Pt::Remoting::Fault becomes an MCP error response. Other failures are reported as JSON-RPC errors by the transport.
The example registers two procedures, declares the matching tools with schemas, and serves them over HTTP. The stdio path is the same declaration and definition with StdioService.
The rest of this chapter is parameter schemas, then tool declarations, then result content, then the HTTP transport, then standard I/O.