A tool is a callable operation that an MCP client — and through it, a language model — can invoke on your server. Each tool declares a name, a description, and a set of typed input properties, so the model knows both what the tool does and exactly what arguments it accepts. TTMSMCPTool covers the whole surface: simple single-argument callbacks, structured arguments including arrays of objects, behaviour hints that tell a client whether a call is safe to repeat, JSON output schemas, native MCP content items, and opt-in execution as a long-running task.
Generates a JSON schema from a Delphi type, for output schemas and object arguments.
Minimal example
Register a tool with the convenience methodPascalC++
procedure TForm1.RegisterGreetTool;
var
Prop: TTMSMCPToolProperty;
begin
{ Server is a TTMSMCPServer dropped on the form. }
Server.Tools.RegisterTool('greet_user', 'Generates a greeting for a person',
function(const Args: array of TValue): TValue
begin
Result := Format('Hello, %s!', [Args[0].AsString]);
end,
ptString);
{ RegisterTool creates the tool with no declared input properties, so
declare them separately - the client needs them to build the call. }
Prop := Server.Tools.FindByName('greet_user').Properties.Add;
Prop.Name := 'name';
Prop.Description := 'Name of the person to greet';
Prop.PropertyType := ptString;
Prop.Required := True;
end;
// The anonymous method of the Delphi API is an interface in C++Builder.
class TGreetMethod : public TCppInterfacedObject<TTMSMCPMethod>
{
public:
TValue __fastcall Invoke(const TValue *Args, const NativeInt Args_High)
{
return TValue::From<System::UnicodeString>(
Format("Hello, %s!", ARRAYOFCONST((TValue(Args[0]).AsString()))));
}
};
void __fastcall TForm1::RegisterGreetTool()
{
TTMSMCPToolProperty *Prop;
// Server is a TTMSMCPServer dropped on the form.
Server->Tools->RegisterTool("greet_user", "Generates a greeting for a person",
_di_TTMSMCPMethod(new TGreetMethod()),
TTMSMCPToolPropertyType::ptString);
// RegisterTool creates the tool with no declared input properties, so
// declare them separately - the client needs them to build the call.
Prop = Server->Tools->FindByName("greet_user")->Properties->Add();
Prop->Name = "name";
Prop->Description = "Name of the person to greet";
Prop->PropertyType = TTMSMCPToolPropertyType::ptString;
Prop->Required = true;
}