class McpTool implements Approvable, Tool

Traits

Constants

protected MCP_CLIENT_TOOL

The MCP client tool primitive class name.

protected NAME_PREFIX

The prefix applied to MCP client tool names.

Properties

protected Approval|bool|null $approvalRequirement from  InteractsWithApprovals

Methods

requireApproval(string|null $reason = null)

Indicate that the tool requires approval before execution.

withoutApproval()

Indicate that the tool may execute without approval.

Approval|null
shouldRequestApproval(Request $request)

Determine whether the tool should request approval for the given request.

Approval|bool
needsApproval(Request $request)

Determine whether the tool needs approval for the given request.

string
errorMessage(string $text)

Format an MCP error payload into tool output.

string
json(array $content)

Encode structured MCP content as JSON.

__construct(object $tool)

Create a new MCP client tool wrapper instance.

static bool
supports(mixed $tool)

Determine whether the given value is an MCP client tool primitive.

string
name()

Get the name of the tool.

Stringable|string
description()

Get the description of the tool's purpose.

array
annotations()

Get the MCP annotations describing the tool's behavior.

Stringable|string
handle(Request $request)

Execute the tool.

array
schema(JsonSchema $schema)

Get the tool's schema definition.

string
convertResult(object $result)

Convert an MCP tool result into tool output.

string
errorResult(object $result)

Convert an MCP error result into tool output.

string
text(object $result)

Extract the text content from an MCP tool result.

Details

InteractsWithApprovals requireApproval(string|null $reason = null)

Indicate that the tool requires approval before execution.

Parameters

string|null $reason

Return Value

InteractsWithApprovals

InteractsWithApprovals withoutApproval()

Indicate that the tool may execute without approval.

Return Value

InteractsWithApprovals

Approval|null shouldRequestApproval(Request $request)

Determine whether the tool should request approval for the given request.

Parameters

Request $request

Return Value

Approval|null

at line 151
protected Approval|bool needsApproval(Request $request)

Determine whether the tool needs approval for the given request.

Parameters

Request $request

Return Value

Approval|bool

protected string errorMessage(string $text)

Format an MCP error payload into tool output.

Parameters

string $text

Return Value

string

protected string json(array $content)

Encode structured MCP content as JSON.

Parameters

array $content

Return Value

string

at line 38
__construct(object $tool)

Create a new MCP client tool wrapper instance.

Parameters

object $tool

at line 45
static bool supports(mixed $tool)

Determine whether the given value is an MCP client tool primitive.

Parameters

mixed $tool

Return Value

bool

at line 53
string name()

Get the name of the tool.

Return Value

string

at line 61
Stringable|string description()

Get the description of the tool's purpose.

Return Value

Stringable|string

at line 71
array annotations()

Get the MCP annotations describing the tool's behavior.

Return Value

array

at line 79
Stringable|string handle(Request $request)

Execute the tool.

Parameters

Request $request

Return Value

Stringable|string

at line 89
array schema(JsonSchema $schema)

Get the tool's schema definition.

Parameters

JsonSchema $schema

Return Value

array

at line 111
protected string convertResult(object $result)

Convert an MCP tool result into tool output.

Parameters

object $result

Return Value

string

at line 127
protected string errorResult(object $result)

Convert an MCP error result into tool output.

Parameters

object $result

Return Value

string

at line 141
protected string text(object $result)

Extract the text content from an MCP tool result.

Parameters

object $result

Return Value

string