MCPTool class

A tool that connects to Model Context Protocol (MCP) servers. Supports managing MCP server connections and allowed tools dynamically.

Constructors

MCPTool(string, string, string[])

Constructor initializes the tool with MCP server configuration.

Properties

allowedTools

Get the list of allowed tools for the MCP server.

definition

Get the MCP tool definition.

headers

Get the headers for the MCP tool.

resources

Get the tool resources for the agent.

serverLabel

Get the server label for the MCP tool.

serverUrl

Get the server URL for the MCP tool.

Methods

allowTool(string)

Add a tool to the list of allowed tools.

disallowTool(string)

Remove a tool from the list of allowed tools.

mergeResources(MCPTool[])

Merge the tool resources from multiple MCPTool instances into a single ToolResources object.

This is useful when creating a run that should have access to multiple MCP servers at once.

setApprovalMode("always" | "never")

Update the approval mode for the MCP tool.

updateHeaders(string, string)

Update the headers for the MCP tool.

Constructor Details

MCPTool(string, string, string[])

Constructor initializes the tool with MCP server configuration.

new MCPTool(serverLabel: string, serverUrl: string, allowedTools?: string[])

Parameters

serverLabel

string

The label for the MCP server

serverUrl

string

The endpoint for the MCP server

allowedTools

string[]

List of allowed tools for MCP server

Property Details

allowedTools

Get the list of allowed tools for the MCP server.

string[] allowedTools

Property Value

string[]

definition

Get the MCP tool definition.

MCPToolDefinition definition

Property Value

A list containing the MCP tool definition

headers

Get the headers for the MCP tool.

Record<string, string> headers

Property Value

Record<string, string>

resources

Get the tool resources for the agent.

ToolResources resources

Property Value

serverLabel

Get the server label for the MCP tool.

string serverLabel

Property Value

string

serverUrl

Get the server URL for the MCP tool.

string serverUrl

Property Value

string

Method Details

allowTool(string)

Add a tool to the list of allowed tools.

function allowTool(toolName: string)

Parameters

toolName

string

The name of the tool to allow

disallowTool(string)

Remove a tool from the list of allowed tools.

function disallowTool(toolName: string)

Parameters

toolName

string

The name of the tool to remove from allowed tools

mergeResources(MCPTool[])

Merge the tool resources from multiple MCPTool instances into a single ToolResources object.

This is useful when creating a run that should have access to multiple MCP servers at once.

static function mergeResources(mcpTools: MCPTool[]): ToolResources

Parameters

mcpTools

MCPTool[]

An array of MCPTool instances whose resources will be merged.

Returns

A ToolResources object containing all MCP tool resources from the provided tools.

setApprovalMode("always" | "never")

Update the approval mode for the MCP tool.

function setApprovalMode(requireApproval?: "always" | "never")

Parameters

requireApproval

"always" | "never"

The require_approval setting to update

updateHeaders(string, string)

Update the headers for the MCP tool.

function updateHeaders(key: string, value: string)

Parameters

key

string

The header key to update

value

string

The new value for the header key