protocol
mcp_tool_protocol
Protocol for Logtalk objects that provide tools to be exposed via an MCP (Model Context Protocol) server. Implementing objects must define the set of tools available and handle tool calls. Tool metadata (names, titles, descriptions, input and output schemas) can be derived automatically from info/2 and mode/2 directives on the tool predicates, or overridden using input_schema/2 and output_schema/2. Used by both the 2025-06-18 and 2026-07-28 adapters.
logtalk_load(mcp_server(loader))static
Capabilities: Objects can optionally define
capabilities/1to declare additional application features. Currently supported:prompts,resources, andcompletions(server capabilities advertised during initialization) andelicitation(a required client capability that allows the server to ask the user questions during tool execution under the 2025-06-18 adapter). Ifcapabilities/1is not defined, only thetoolsserver capability is advertised.Tool title: The tool title (human-friendly display name) is derived from a
titlekey in the predicateinfo/2directive. If not specified, the predicate name (functor) is used as the title.Schemas: Input and output schemas are inferred from the tool predicate
info/2andmode/2directives. Defineinput_schema/2oroutput_schema/2to override the inferred schema for a tool. Tools can returnstructured(StructuredContent)orstructured(ContentItems, StructuredContent)results; the structured content is included in thestructuredContentfield of the tool call response alongside thecontentarray.Resource links: Tool results can include
resource_link(URI, Name)orresource_link(URI, Name, Description, MimeType)content items inresults/1lists.Elicitation (2025-06-18 only): Under the 2025-06-18 adapter, tools that need user interaction during execution should define
tool_call/4instead oftool_call/3. The extra argument is an elicitation closure that can be called ascall(Elicit, Message, Schema, Answer)whereMessageis the prompt text (an atom),Schemais a JSON Schema curly-term for the requested input, andAnsweris unified withaccept(Content),decline, orcancel. The 2026-07-28 adapter never invokestool_call/4; multi-round interaction is provided bymcp_multiround_protocolinstead.Multi-round (2026-07-28): For the 2026-07-28 adapter, applications that need additional input during a tool call implement
tool_call_round/4from themcp_multiround_protocol. Existingtool_call/3and auto-dispatch remain valid and are wrapped ascompleteresults when the round hook is absent.
Public predicates
capabilities/1
Returns a list of additional MCP features used by this provider. prompts, resources, and completions are advertised as server capabilities. elicitation declares that the provider may ask the user questions and is enabled only when the client advertises the corresponding client capability. If not defined, only the tools server capability is advertised.
staticcapabilities(Capabilities)capabilities(-list(atom)) - onetools/1
Returns a list of tool descriptors available from this object. Each descriptor is a compound term tool(Name, Functor, Arity) where Name is the MCP tool name (an atom), Functor is the predicate functor, and Arity is the predicate arity. By default, the tool name is the predicate functor. Tool titles are derived from info/2 title keys (falling back to the predicate name). Tool descriptions and parameter schemas are derived from the info/2 and mode/2 directives of the corresponding predicates.
statictools(Tools)tools(-list(compound)) - onetool_call/3
Handles a tool call. Name is the MCP tool name (as declared in tools/1), Arguments is a list of ArgumentName-Value pairs, and Result is unified with the tool result. The result must be one of: text(Atom) for a text result, error(Atom) for an error result, results(List) for a list of content items where each item is text(Atom), error(Atom), resource_link(URI, Name), or resource_link(URI, Name, Description, MimeType), structured(StructuredContent) for structured output with auto-generated text, or structured(ContentItems, StructuredContent) for structured output with explicit content items. If this predicate is not defined for a tool, the MCP server will use auto-dispatch: it calls the tool predicate as a message to the implementing object, collects output arguments, and returns them as a text result.
statictool_call(Name,Arguments,Result)tool_call(+atom,+list(pair),--compound) - onetool_call/4
Handles a tool call with elicitation support under the 2025-06-18 adapter only. Same as tool_call/3 but receives an Elicit closure as the third argument. The closure can be called as call(Elicit, Message, Schema, Answer) where Message is a prompt text (an atom), Schema is a curly-term JSON Schema describing the requested input (e.g., {type-object, properties-{answer-{type-string, enum-[yes, no]}}, required-[answer]}), and Answer is unified with accept(Content) (where Content is the user response as a curly-term), decline, or cancel. Only available when the application declares elicitation in its capabilities/1 and the client advertises elicitation support during initialization. Falls back to tool_call/3 and then auto-dispatch if not defined. The 2026-07-28 adapter never calls this predicate; use tool_call_round/4 from mcp_multiround_protocol instead.
statictool_call(Name,Arguments,Elicit,Result)tool_call(+atom,+list(pair),+callable,--compound) - oneoutput_schema/2
Returns the JSON output schema for the given tool name. Optional; when defined, the schema overrides the one inferred from the tool predicate info/2 and mode/2 directives. The tool can return structured(StructuredContent) or structured(ContentItems, StructuredContent) results. The schema must be a curly-term following JSON Schema format (e.g. {type-object, properties-{temperature-{type-number}}, required-[temperature]}).
staticoutput_schema(Name,Schema)output_schema(+atom,-compound) - zero_or_oneinput_schema/2
Returns the JSON input schema for the given tool name. Optional; when defined, the schema overrides the one inferred from the tool predicate info/2 and mode/2 directives. The schema must be a curly-term following JSON Schema format (e.g. {type-object, properties-{temperature-{type-number}}, required-[temperature]}).
staticinput_schema(Name,Schema)input_schema(+atom,-compound) - zero_or_oneProtected predicates
(none)
Private predicates
(none)
Operators
(none)