McpServerTool
class McpServerTool implements Approvable, Tool
Traits
Constants
| protected MCP_SERVER_TOOL |
The MCP server tool class name. |
| protected MCP_REQUEST |
The MCP request class name. |
| protected MCP_RESPONSE |
The MCP response class name. |
| protected MCP_RESPONSE_FACTORY |
The MCP response factory class name. |
Properties
| protected Approval|bool|null | $approvalRequirement | from InteractsWithApprovals |
Methods
Indicate that the tool requires approval before execution.
Indicate that the tool may execute without approval.
Determine whether the tool should request approval for the given request.
Format an MCP error payload into tool output.
Create a new MCP server tool wrapper instance.
Determine whether the given value is an MCP server tool.
Get the name of the tool.
Get the description of the tool's purpose.
Get the MCP annotations describing the tool's behavior.
Convert an MCP server response into tool output.
Flatten Response, ResponseFactory, string, and nested array items into a flat list of Response instances.
Reduce a list of responses to the last non-notification response's text.
Details
in
InteractsWithApprovals at line 17
InteractsWithApprovals
requireApproval(string|null $reason = null)
Indicate that the tool requires approval before execution.
in
InteractsWithApprovals at line 27
InteractsWithApprovals
withoutApproval()
Indicate that the tool may execute without approval.
in
InteractsWithApprovals at line 37
Approval|null
shouldRequestApproval(Request $request)
Determine whether the tool should request approval for the given request.
at line 181
protected Approval|bool
needsApproval(Request $request)
Determine whether the tool needs approval for the given request.
in
NormalizesMcpResult at line 12
protected string
errorMessage(string $text)
Format an MCP error payload into tool output.
in
NormalizesMcpResult at line 24
protected string
json(array $content)
Encode structured MCP content as JSON.
at line 50
__construct(object $tool)
Create a new MCP server tool wrapper instance.
at line 57
static bool
supports(mixed $tool)
Determine whether the given value is an MCP server tool.
at line 65
string
name()
Get the name of the tool.
at line 73
Stringable|string
description()
Get the description of the tool's purpose.
at line 83
array
annotations()
Get the MCP annotations describing the tool's behavior.
at line 91
Stringable|string
handle(Request $request)
Execute the tool.
at line 114
array
schema(JsonSchema $schema)
Get the tool's schema definition.
at line 122
protected string
convertResponse(mixed $response)
Convert an MCP server response into tool output.
at line 147
protected array
normalize(array $items)
Flatten Response, ResponseFactory, string, and nested array items into a flat list of Response instances.
at line 163
protected string
finalResponse(array $responses)
Reduce a list of responses to the last non-notification response's text.