Parameter Schemas

JSON Schema descriptors for MCP tool parameters. More...

Classes

class  Type
 JSON Schema type for an MCP tool parameter. More...
class  Property
 Named slot of an object schema or a tool parameter. More...
class  ObjectType
 JSON object schema with named properties. More...
class  ArrayType
 JSON array schema with one element type. More...
class  EnumType
 String schema restricted to a fixed set of values. More...
class  NullableType
 Schema that accepts a type or JSON null. More...

Functions

PT_MCP_API const TypenullType ()
 Returns the process-wide JSON null schema type.
PT_MCP_API const TypeintegerType ()
 Returns the process-wide JSON integer schema type.
PT_MCP_API const TypenumberType ()
 Returns the process-wide JSON number schema type.
PT_MCP_API const TypestringType ()
 Returns the process-wide JSON string schema type.
PT_MCP_API const TypebooleanType ()
 Returns the process-wide JSON boolean schema type.

Detailed Description

A tool parameter is described by a Type, which is a JSON Schema fragment the declaration writes into tools/list. The schema is what the client sees. The C++ argument type of the procedure is what the remoting layer deserializes. Those two descriptions must agree: an integer schema belongs on an int parameter, an object schema on a serializable struct.

Primitive schemas are process-wide singletons. nullType(), integerType(), numberType(), stringType(), and booleanType() return them. They are never constructed by the caller and they outlive every tool.

Composed schemas are values the caller owns. ObjectType is a JSON object with named properties. ArrayType is an array whose items have one element type. EnumType is a string restricted to a fixed set of values. NullableType wraps another type so null is also accepted. The composed type stores a pointer to each inner Type; it does not copy it and it does not own it. Keep every inner type alive for as long as the composed type, and keep the composed type alive for as long as any Tool that names it.

Property is the named slot both objects and tools use: a name, a Type, a description, and a required flag. Properties and tool parameters are required by default. ObjectType::setOptional() and Tool::setOptional() clear that flag by name. ObjectType::setStrict() forbids additional properties in the schema.

Type::toSchema() writes the JSON Schema object to a stream. The declaration calls it when it formats tools/list. Application code rarely calls it directly. Type is not copyable.

The example builds an object schema with a required string and an optional integer, then uses it as a tool parameter. The object type must outlive the declaration.

query.addProperty("name", Pt::Mcp::stringType(), "Name to look up");
query.addProperty("limit", Pt::Mcp::integerType(), "Maximum rows");
query.setOptional("limit");
decl.addTool("search", "Search by name")
.addParam("query", query, "Search parameters");
JSON object schema with named properties.
Definition Type.h:175
ObjectType & setOptional(const std::string &name)
Marks the property named name as optional.
ObjectType & addProperty(const std::string &name, const Type &type, const std::string &description="")
Adds a required property named name of type.
PT_MCP_API const Type & stringType()
Returns the process-wide JSON string schema type.
PT_MCP_API const Type & integerType()
Returns the process-wide JSON integer schema type.