McpTool Class

public final class McpTool
extends Tool

MCP tool Give the model access to additional tools via remote Model Context Protocol (MCP) servers. [Learn more about MCP](https://developers.openai.com/api/docs/guides/tools-connectors-mcp).

Constructor Summary

Constructor Description
McpTool(String serverLabel)

Creates an instance of McpTool class.

Method Summary

Modifier and Type Method and Description
static McpTool fromJson(JsonReader jsonReader)

Reads an instance of McpTool from the JsonReader.

List<CallableToolAllowedCaller> getAllowedCallers()

Get the allowedCallers property: The allowed_callers property.

McpToolFilter getAllowedToolsAsMcpToolFilter()

Get the allowedTools property: The allowed_tools property.

List<String> getAllowedToolsAsStringList()

Get the allowedTools property: The allowed_tools property.

String getAuthorization()

Get the authorization property: An OAuth access token that can be used with a remote MCP server, either with a custom MCP server URL or a service connector.

McpToolConnectorId getConnectorType()

Get the connectorType property: Identifier for service connectors, like those available in ChatGPT.

Map<String,String> getHeaders()

Get the headers property: The headers property.

String getProjectConnectionId()

Get the projectConnectionId property: The connection ID in the project for the MCP server.

McpToolRequireApproval getRequireApprovalAsMcpToolRequireApproval()

Get the requireApproval property: The require_approval property.

String getRequireApprovalAsString()

Get the requireApproval property: The require_approval property.

String getServerDescription()

Get the serverDescription property: Optional description of the MCP server, used to provide more context.

String getServerLabel()

Get the serverLabel property: A label for this MCP server, used to identify it in tool calls.

String getServerUrl()

Get the serverUrl property: The URL for the MCP server.

Map<String,ToolConfig> getToolConfigs()

Get the toolConfigs property: Deprecated.

String getTunnelId()

Get the tunnelId property: The Secure MCP Tunnel ID to use instead of a direct server URL.

ToolType getType()

Get the type property: The type property.

Boolean isDeferLoading()

Get the deferLoading property: Whether this MCP tool is deferred and discovered via tool search.

McpTool setAllowedCallers(List<CallableToolAllowedCaller> allowedCallers)

Set the allowedCallers property: The allowed_callers property.

McpTool setAllowedTools(List<String> allowedTools)

Set the allowedTools property: The allowed_tools property.

McpTool setAllowedTools(McpToolFilter allowedTools)

Set the allowedTools property: The allowed_tools property.

McpTool setAuthorization(String authorization)

Set the authorization property: An OAuth access token that can be used with a remote MCP server, either with a custom MCP server URL or a service connector.

McpTool setConnectorType(McpToolConnectorId connectorType)

Set the connectorType property: Identifier for service connectors, like those available in ChatGPT.

McpTool setDeferLoading(Boolean deferLoading)

Set the deferLoading property: Whether this MCP tool is deferred and discovered via tool search.

McpTool setHeaders(Map<String,String> headers)

Set the headers property: The headers property.

McpTool setProjectConnectionId(String projectConnectionId)

Set the projectConnectionId property: The connection ID in the project for the MCP server.

McpTool setRequireApproval(McpToolRequireApproval requireApproval)

Set the requireApproval property: The require_approval property.

McpTool setRequireApproval(String requireApproval)

Set the requireApproval property: The require_approval property.

McpTool setServerDescription(String serverDescription)

Set the serverDescription property: Optional description of the MCP server, used to provide more context.

McpTool setServerUrl(String serverUrl)

Set the serverUrl property: The URL for the MCP server.

McpTool setToolConfigs(Map<String,ToolConfig> toolConfigs)

Set the toolConfigs property: Deprecated.

McpTool setTunnelId(String tunnelId)

Set the tunnelId property: The Secure MCP Tunnel ID to use instead of a direct server URL.

JsonWriter toJson(JsonWriter jsonWriter)

Methods inherited from Tool

Methods inherited from java.lang.Object

Constructor Details

McpTool

public McpTool(String serverLabel)

Creates an instance of McpTool class.

Parameters:

serverLabel - the serverLabel value to set.

Method Details

fromJson

public static McpTool fromJson(JsonReader jsonReader)

Reads an instance of McpTool from the JsonReader.

Parameters:

jsonReader - The JsonReader being read.

Returns:

An instance of McpTool if the JsonReader was pointing to an instance of it, or null if it was pointing to JSON null.

Throws:

IOException

- If the deserialized JSON object was missing any required properties.

getAllowedCallers

public List<CallableToolAllowedCaller> getAllowedCallers()

Get the allowedCallers property: The allowed_callers property.

Returns:

the allowedCallers value.

getAllowedToolsAsMcpToolFilter

public McpToolFilter getAllowedToolsAsMcpToolFilter()

Get the allowedTools property: The allowed_tools property.

Returns:

the allowedTools value as a McpToolFilter.

getAllowedToolsAsStringList

public List<String> getAllowedToolsAsStringList()

Get the allowedTools property: The allowed_tools property.

Returns:

the allowedTools value as a list of Strings.

getAuthorization

public String getAuthorization()

Get the authorization property: An OAuth access token that can be used with a remote MCP server, either with a custom MCP server URL or a service connector. Your application must handle the OAuth authorization flow and provide the token here.

Returns:

the authorization value.

getConnectorType

public McpToolConnectorId getConnectorType()

Get the connectorType property: Identifier for service connectors, like those available in ChatGPT. One of `server_url`, `connector_id`, or `tunnel_id` must be provided. Learn more about service connectors [here](https://developers.openai.com/api/docs/guides/tools-connectors-mcp\#connectors). This field is deprecated for models released after September 1, 2026. Use `server_url` to connect to a remote MCP server, or `tunnel_id` to connect through a Secure MCP Tunnel. Currently supported `connector_id` values are: - Dropbox: `connector_dropbox` - Gmail: `connector_gmail` - Google Calendar: `connector_googlecalendar` - Google Drive: `connector_googledrive` - Microsoft Teams: `connector_microsoftteams` - Outlook Calendar: `connector_outlookcalendar` - Outlook Email: `connector_outlookemail` - SharePoint: `connector_sharepoint`.

Returns:

the connectorType value.

getHeaders

public Map<String,String> getHeaders()

Get the headers property: The headers property.

Returns:

the headers value.

getProjectConnectionId

public String getProjectConnectionId()

Get the projectConnectionId property: The connection ID in the project for the MCP server. The connection stores authentication and other connection details needed to connect to the MCP server.

Returns:

the projectConnectionId value.

getRequireApprovalAsMcpToolRequireApproval

public McpToolRequireApproval getRequireApprovalAsMcpToolRequireApproval()

Get the requireApproval property: The require_approval property.

Returns:

the requireApproval value as a McpToolRequireApproval.

getRequireApprovalAsString

public String getRequireApprovalAsString()

Get the requireApproval property: The require_approval property.

Returns:

the requireApproval value as a String.

getServerDescription

public String getServerDescription()

Get the serverDescription property: Optional description of the MCP server, used to provide more context.

Returns:

the serverDescription value.

getServerLabel

public String getServerLabel()

Get the serverLabel property: A label for this MCP server, used to identify it in tool calls.

Returns:

the serverLabel value.

getServerUrl

public String getServerUrl()

Get the serverUrl property: The URL for the MCP server. One of `server_url`, `connector_id`, or `tunnel_id` must be provided.

Returns:

the serverUrl value.

getToolConfigs

public Map<String,ToolConfig> getToolConfigs()

Get the toolConfigs property: Deprecated. This property is deprecated and will be removed in a future version.

Returns:

the toolConfigs value.

getTunnelId

public String getTunnelId()

Get the tunnelId property: The Secure MCP Tunnel ID to use instead of a direct server URL. One of `server_url`, `connector_id`, or `tunnel_id` must be provided.

Returns:

the tunnelId value.

getType

public ToolType getType()

Get the type property: The type property.

Overrides:

McpTool.getType()

Returns:

the type value.

isDeferLoading

public Boolean isDeferLoading()

Get the deferLoading property: Whether this MCP tool is deferred and discovered via tool search.

Returns:

the deferLoading value.

setAllowedCallers

public McpTool setAllowedCallers(List<CallableToolAllowedCaller> allowedCallers)

Set the allowedCallers property: The allowed_callers property.

Parameters:

allowedCallers - the allowedCallers value to set.

Returns:

the McpTool object itself.

setAllowedTools

public McpTool setAllowedTools(List<String> allowedTools)

Set the allowedTools property: The allowed_tools property.

Parameters:

allowedTools - the list of tool name strings to set.

Returns:

the McpTool object itself.

setAllowedTools

public McpTool setAllowedTools(McpToolFilter allowedTools)

Set the allowedTools property: The allowed_tools property.

Parameters:

allowedTools - the McpToolFilter to set.

Returns:

the McpTool object itself.

setAuthorization

public McpTool setAuthorization(String authorization)

Set the authorization property: An OAuth access token that can be used with a remote MCP server, either with a custom MCP server URL or a service connector. Your application must handle the OAuth authorization flow and provide the token here.

Parameters:

authorization - the authorization value to set.

Returns:

the McpTool object itself.

setConnectorType

public McpTool setConnectorType(McpToolConnectorId connectorType)

Set the connectorType property: Identifier for service connectors, like those available in ChatGPT. One of `server_url`, `connector_id`, or `tunnel_id` must be provided. Learn more about service connectors [here](https://developers.openai.com/api/docs/guides/tools-connectors-mcp\#connectors). This field is deprecated for models released after September 1, 2026. Use `server_url` to connect to a remote MCP server, or `tunnel_id` to connect through a Secure MCP Tunnel. Currently supported `connector_id` values are: - Dropbox: `connector_dropbox` - Gmail: `connector_gmail` - Google Calendar: `connector_googlecalendar` - Google Drive: `connector_googledrive` - Microsoft Teams: `connector_microsoftteams` - Outlook Calendar: `connector_outlookcalendar` - Outlook Email: `connector_outlookemail` - SharePoint: `connector_sharepoint`.

Parameters:

connectorType - the connectorType value to set.

Returns:

the McpTool object itself.

setDeferLoading

public McpTool setDeferLoading(Boolean deferLoading)

Set the deferLoading property: Whether this MCP tool is deferred and discovered via tool search.

Parameters:

deferLoading - the deferLoading value to set.

Returns:

the McpTool object itself.

setHeaders

public McpTool setHeaders(Map<String,String> headers)

Set the headers property: The headers property.

Parameters:

headers - the headers value to set.

Returns:

the McpTool object itself.

setProjectConnectionId

public McpTool setProjectConnectionId(String projectConnectionId)

Set the projectConnectionId property: The connection ID in the project for the MCP server. The connection stores authentication and other connection details needed to connect to the MCP server.

Parameters:

projectConnectionId - the projectConnectionId value to set.

Returns:

the McpTool object itself.

setRequireApproval

public McpTool setRequireApproval(McpToolRequireApproval requireApproval)

Set the requireApproval property: The require_approval property.

Parameters:

requireApproval - the McpToolRequireApproval filter to set.

Returns:

the McpTool object itself.

setRequireApproval

public McpTool setRequireApproval(String requireApproval)

Set the requireApproval property: The require_approval property.

Parameters:

requireApproval - the approval setting string to set (e.g., "always" or "never").

Returns:

the McpTool object itself.

setServerDescription

public McpTool setServerDescription(String serverDescription)

Set the serverDescription property: Optional description of the MCP server, used to provide more context.

Parameters:

serverDescription - the serverDescription value to set.

Returns:

the McpTool object itself.

setServerUrl

public McpTool setServerUrl(String serverUrl)

Set the serverUrl property: The URL for the MCP server. One of `server_url`, `connector_id`, or `tunnel_id` must be provided.

Parameters:

serverUrl - the serverUrl value to set.

Returns:

the McpTool object itself.

setToolConfigs

public McpTool setToolConfigs(Map<String,ToolConfig> toolConfigs)

Set the toolConfigs property: Deprecated. This property is deprecated and will be removed in a future version.

Parameters:

toolConfigs - the toolConfigs value to set.

Returns:

the McpTool object itself.

setTunnelId

public McpTool setTunnelId(String tunnelId)

Set the tunnelId property: The Secure MCP Tunnel ID to use instead of a direct server URL. One of `server_url`, `connector_id`, or `tunnel_id` must be provided.

Parameters:

tunnelId - the tunnelId value to set.

Returns:

the McpTool object itself.

toJson

public JsonWriter toJson(JsonWriter jsonWriter)

Overrides:

McpTool.toJson(JsonWriter jsonWriter)

Parameters:

jsonWriter

Throws:

Applies to