Saltar al contenido principal
Versión: Siguiente

MCP

MCP : 4D.MCPContext

ParameterTypeDescription
Function result4D.MCPContext←Context of the current MCP tool call
History
ReleaseChanges
21 R6Created

Description​

The MCP command returns the 4D.MCPContext object of the current call of a tool of the MCP server.

The 4D.MCPContext object gives information about the call (.toolName, .clientInfo, .canElicit) and lets the tool:

The context is available while an exposed MCP Function runs as a tool of the MCP server, including in the methods and functions it calls.

Outside an MCP tool call (for example in a REST request or in a method run from the 4D environment), MCP returns an inert object:

  • .hasInput() returns False,
  • .requireInput() asks nothing and returns Null,
  • .error() does nothing,
  • .toolName is an empty string, .clientInfo is Null, and .canElicit is False.

For more information, see Asking the user for confirmation.

Example 1​

You want the user to confirm the deletion of an order before it is dropped:

// cs.OrderEntity class
Class extends Entity

// Deletes the order
exposed MCP Function delete() : Text
If (Not(MCP.hasInput("confirm")))
MCP.requireInput({message: "Delete order "+String(This.ID)+"?"; confirm: {type: "boolean"; title: "Delete"}}; This.getStamp())
return
End if
If (MCP.bound#This.getStamp())
MCP.error("The order was modified, please try again")
return
End if
If (MCP.input.confirm)
This.drop()
return "Order deleted"
End if
return "Deletion cancelled"

Example 2​

A method called both by an MCP tool and by other code checks whether it runs in an MCP tool call:

var $context : 4D.MCPContext:=MCP
If ($context.toolName="")
// not called from an MCP tool: $context is inert
End if

See also​

MCPContext class
MCP server
Session

Properties​

Command number1872
Thread safeyes