Record Class HostedTool.Mcp

java.lang.Object
java.lang.Record
org.springframework.ai.openai.responses.HostedTool.Mcp
Record Components:
serverLabel - the label the model uses to address the server
serverUrl - the server URL, or null when using connectorId
connectorId - an OpenAI-managed connector id, or null
allowedTools - restricts the callable tools, or null for all of them
headers - headers to send to the MCP server, e.g. authorization
requireApproval - never, or null for the provider default. always is rejected: the approval round-trip is not implemented, so it would end every tool-using turn without running the tool
All Implemented Interfaces:
HostedTool
Enclosing interface:
HostedTool

public static record HostedTool.Mcp(String serverLabel, @Nullable String serverUrl, @Nullable String connectorId, @Nullable List<String> allowedTools, @Nullable Map<String,String> headers, @Nullable String requireApproval) extends Record implements HostedTool
Call tools on a remote MCP server from inside OpenAI's request.

The approval round-trip is out of scope: requireApproval should be never unless the application inspects OpenAiResponsesMetadata.HOSTED_TOOL_CALLS on the generation metadata itself, because an mcp_approval_request left unanswered ends the turn without running the tool.

  • Constructor Details

    • Mcp

      public Mcp(String serverLabel, @Nullable String serverUrl, @Nullable String connectorId, @Nullable List<String> allowedTools, @Nullable Map<String,String> headers, @Nullable String requireApproval)
      Creates an instance of a Mcp record class.
      Parameters:
      serverLabel - the value for the serverLabel record component
      serverUrl - the value for the serverUrl record component
      connectorId - the value for the connectorId record component
      allowedTools - the value for the allowedTools record component
      headers - the value for the headers record component
      requireApproval - the value for the requireApproval record component
  • Method Details

    • of

      public static HostedTool.Mcp of(String serverLabel, String serverUrl)
    • toTool

      public com.openai.models.responses.Tool toTool()
      Description copied from interface: HostedTool
      Convert this tool to the SDK request representation.
      Specified by:
      toTool in interface HostedTool
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • serverLabel

      public String serverLabel()
      Returns the value of the serverLabel record component.
      Returns:
      the value of the serverLabel record component
    • serverUrl

      public @Nullable String serverUrl()
      Returns the value of the serverUrl record component.
      Returns:
      the value of the serverUrl record component
    • connectorId

      public @Nullable String connectorId()
      Returns the value of the connectorId record component.
      Returns:
      the value of the connectorId record component
    • allowedTools

      public @Nullable List<String> allowedTools()
      Returns the value of the allowedTools record component.
      Returns:
      the value of the allowedTools record component
    • headers

      public @Nullable Map<String,String> headers()
      Returns the value of the headers record component.
      Returns:
      the value of the headers record component
    • requireApproval

      public @Nullable String requireApproval()
      Returns the value of the requireApproval record component.
      Returns:
      the value of the requireApproval record component