CustomContentsTool
extends BaseMcpTool
in package
カスタムコンテンツツールクラス
カスタムコンテンツのCRUD操作を提供
Table of Contents
Constants
- ANNOTATION_CREATE : mixed = ['readOnlyHint' => false, 'destructiveHint' =>...
- 追加系ツールの注釈
- ANNOTATION_DELETE : mixed = ['readOnlyHint' => false, 'destructiveHint' =>...
- 削除系ツールの注釈
- ANNOTATION_READ : mixed = ['readOnlyHint' => true, 'openWorldHint' => false]
- 読み取り専用ツールの注釈
- ANNOTATION_UPDATE : mixed = ['readOnlyHint' => false, 'destructiveHint' =>...
- 更新系ツールの注釈
- OUTPUT_SCHEMA : mixed = ['type' => 'object']
- ツールの戻り値のスキーマ
Methods
- addCustomContent() : array<string|int, mixed>
- カスタムコンテンツを追加
- deleteCustomContent() : array<string|int, mixed>
- カスタムコンテンツを削除
- editCustomContent() : array<string|int, mixed>
- カスタムコンテンツを編集
- getCustomContent() : array<string|int, mixed>
- カスタムコンテンツを取得
- getCustomContents() : array<string|int, mixed>
- カスタムコンテンツ一覧を取得
- getPermissionUrl() : false|array<string|int, string>
- 権限チェック用のURLを取得する
- getService() : array<string|int, mixed>|mixed|object
- Get Service
- hasService() : bool
- Has Service
- registerTools() : McpServer
- カスタムコンテンツ関連のツールをサーバーに登録する
- cleanupTempFile() : void
- 一時ファイルをクリーンアップ
- createErrorResponse() : array<string|int, mixed>
- エラー時の戻り値を作成
- createSuccessResponse() : array<string|int, mixed>
- 成功時の戻り値を作成
- createUploadedFileFromArray() : UploadedFileInterface
- 配列データからCakePHPのUploadedFileオブジェクトを作成
- detectMimeTypeFromContent() : string
- ファイル内容からMIMEタイプを検出
- executeWithErrorHandling() : array<string|int, mixed>
- try-catchブロックを共通化してエラーハンドリングを実行
- getExtensionFromMimeType() : string
- MIMEタイプから拡張子を取得
- getMimeTypeFromExtension() : string
- 拡張子からMIMEタイプを取得
- isAllowedExtension() : bool
- 許可された拡張子かチェック
- isFileUploadable() : bool
- 値がファイルアップロード可能な形式かどうかを判定
- processBase64File() : array<string|int, mixed>
- Base64エンコードされたファイルデータを処理
- processFileUpload() : array<string|int, mixed>|false
- ファイルアップロード処理
- processImageUpload() : array<string|int, mixed>|false
- 画像ファイル専用のアップロード処理
- processUrlFile() : array<string|int, mixed>
- URLからファイルをダウンロードして処理
- resolveLoginUserId() : int|null
- 操作者のユーザーIDを解決する
- saveDblog() : void
- 操作ログを保存する
Constants
ANNOTATION_CREATE
追加系ツールの注釈
protected
mixed
ANNOTATION_CREATE
= ['readOnlyHint' => false, 'destructiveHint' => false, 'idempotentHint' => false, 'openWorldHint' => false]
追加のみで既存データを壊さない。同じ引数で繰り返すと重複が増えるため 冪等ではない。
ANNOTATION_DELETE
削除系ツールの注釈
protected
mixed
ANNOTATION_DELETE
= ['readOnlyHint' => false, 'destructiveHint' => true, 'idempotentHint' => true, 'openWorldHint' => false]
削除済みのものを再度削除しても結果は変わらない。
ANNOTATION_READ
読み取り専用ツールの注釈
protected
mixed
ANNOTATION_READ
= ['readOnlyHint' => true, 'openWorldHint' => false]
クライアントが読み取りと書き込みを区別できるようにする。Claude の Research はツール呼び出しに都度承認を挟まないため、区別できる情報を 提供する意味がある。readOnlyHint が true のとき、destructiveHint と idempotentHint は意味を持たないため宣言しない。
ANNOTATION_UPDATE
更新系ツールの注釈
protected
mixed
ANNOTATION_UPDATE
= ['readOnlyHint' => false, 'destructiveHint' => true, 'idempotentHint' => true, 'openWorldHint' => false]
既存データを上書きするため破壊的とみなす。同じ引数なら結果は同じ。
OUTPUT_SCHEMA
ツールの戻り値のスキーマ
protected
mixed
OUTPUT_SCHEMA
= ['type' => 'object']
各ツールは配列(エンティティを配列化したものや一覧)を返す。SDK は outputSchema を宣言したツールに限り配列の戻り値を許容し、その値を structuredContent として返しつつ JSON を TextContent にも載せる (SEP-2106)。宣言が無いと戻り値は文字列か CallToolResult に限られる。
個々のツールの戻り値の構造はエンティティの構成に依存するため、 ここでは型のみを宣言する。
Methods
addCustomContent()
カスタムコンテンツを追加
public
addCustomContent(string $name, string $title, int $customTableId[, int|null $siteId = 1 ][, int|null $parentId = 1 ][, string|null $description = null ][, int|null $authorId = null ][, string|null $layoutTemplate = null ][, bool|null $status = false ][, string|null $publishBegin = null ][, string|null $publishEnd = null ][, bool|null $excludeSearch = false ][, bool|null $excludeMenu = false ][, bool|null $blankLink = false ][, string|null $template = 'default' ][, int|null $widgetArea = null ][, int|null $listCount = 10 ][, string|null $listOrder = 'published' ][, string|null $listDirection = 'DESC' ][, int|null $loginUserId = null ]) : array<string|int, mixed>
Parameters
- $name : string
- $title : string
- $customTableId : int
- $siteId : int|null = 1
- $parentId : int|null = 1
- $description : string|null = null
- $authorId : int|null = null
- $layoutTemplate : string|null = null
- $status : bool|null = false
- $publishBegin : string|null = null
- $publishEnd : string|null = null
- $excludeSearch : bool|null = false
- $excludeMenu : bool|null = false
- $blankLink : bool|null = false
- $template : string|null = 'default'
- $widgetArea : int|null = null
- $listCount : int|null = 10
- $listOrder : string|null = 'published'
- $listDirection : string|null = 'DESC'
- $loginUserId : int|null = null
Return values
array<string|int, mixed>deleteCustomContent()
カスタムコンテンツを削除
public
deleteCustomContent(int $id[, int|null $loginUserId = null ]) : array<string|int, mixed>
Parameters
- $id : int
- $loginUserId : int|null = null
Return values
array<string|int, mixed>editCustomContent()
カスタムコンテンツを編集
public
editCustomContent(int $id[, string|null $name = null ][, string|null $title = null ][, int|null $customTableId = null ][, int|null $siteId = null ][, int|null $parentId = null ][, string|null $description = null ][, string|null $authorId = null ][, string|null $layoutTemplate = null ][, bool|null $status = false ][, string|null $publishBegin = null ][, string|null $publishEnd = null ][, bool|null $excludeSearch = false ][, bool|null $excludeMenu = false ][, bool|null $blankLink = false ][, string|null $template = null ][, int|null $widgetArea = null ][, int|null $listCount = null ][, string|null $listOrder = null ][, string|null $listDirection = null ][, int|null $loginUserId = null ]) : array<string|int, mixed>
Parameters
- $id : int
- $name : string|null = null
- $title : string|null = null
- $customTableId : int|null = null
- $siteId : int|null = null
- $parentId : int|null = null
- $description : string|null = null
- $authorId : string|null = null
- $layoutTemplate : string|null = null
- $status : bool|null = false
- $publishBegin : string|null = null
- $publishEnd : string|null = null
- $excludeSearch : bool|null = false
- $excludeMenu : bool|null = false
- $blankLink : bool|null = false
- $template : string|null = null
- $widgetArea : int|null = null
- $listCount : int|null = null
- $listOrder : string|null = null
- $listDirection : string|null = null
- $loginUserId : int|null = null
Return values
array<string|int, mixed>getCustomContent()
カスタムコンテンツを取得
public
getCustomContent(int $id) : array<string|int, mixed>
Parameters
- $id : int
Return values
array<string|int, mixed>getCustomContents()
カスタムコンテンツ一覧を取得
public
getCustomContents([string|null $status = null ][, int|null $limit = null ][, int|null $page = 1 ]) : array<string|int, mixed>
Parameters
- $status : string|null = null
- $limit : int|null = null
- $page : int|null = 1
Return values
array<string|int, mixed>getPermissionUrl()
権限チェック用のURLを取得する
public
static getPermissionUrl(mixed $action[, mixed $args = [] ]) : false|array<string|int, string>
Parameters
- $action : mixed
- $args : mixed = []
Return values
false|array<string|int, string>getService()
Get Service
public
getService(mixed $service) : array<string|int, mixed>|mixed|object
Parameters
- $service : mixed
Tags
Return values
array<string|int, mixed>|mixed|objecthasService()
Has Service
public
hasService(mixed $service) : bool
Parameters
- $service : mixed
Tags
Return values
boolregisterTools()
カスタムコンテンツ関連のツールをサーバーに登録する
public
registerTools(McpServer $server) : McpServer
Parameters
- $server : McpServer
-
SDK のサーバー
Return values
McpServercleanupTempFile()
一時ファイルをクリーンアップ
protected
cleanupTempFile(string $tmpPath) : void
Parameters
- $tmpPath : string
-
一時ファイルのパス
createErrorResponse()
エラー時の戻り値を作成
protected
createErrorResponse(string $message[, Throwable|null $exception = null ]) : array<string|int, mixed>
Parameters
- $message : string
-
エラーメッセージ
- $exception : Throwable|null = null
-
例外オブジェクト(トレース情報用)
Return values
array<string|int, mixed> —MCP仕様に準拠したエラーレスポンス
createSuccessResponse()
成功時の戻り値を作成
protected
createSuccessResponse(mixed $content[, array<string|int, mixed> $meta = [] ][, mixed $message = '' ][, mixed $userId = null ]) : array<string|int, mixed>
Parameters
- $content : mixed
-
戻り値のコンテンツ
- $meta : array<string|int, mixed> = []
-
追加のメタデータ(paginationなど)
- $message : mixed = ''
- $userId : mixed = null
Return values
array<string|int, mixed> —MCP仕様に準拠した成功レスポンス
createUploadedFileFromArray()
配列データからCakePHPのUploadedFileオブジェクトを作成
protected
createUploadedFileFromArray(array<string|int, mixed> $fileData) : UploadedFileInterface
Parameters
- $fileData : array<string|int, mixed>
-
ファイル情報の配列
Return values
UploadedFileInterfacedetectMimeTypeFromContent()
ファイル内容からMIMEタイプを検出
protected
detectMimeTypeFromContent(string $fileData) : string
Parameters
- $fileData : string
-
ファイルのバイナリデータ
Return values
string —MIMEタイプ
executeWithErrorHandling()
try-catchブロックを共通化してエラーハンドリングを実行
protected
executeWithErrorHandling(callable $callback) : array<string|int, mixed>
Parameters
- $callback : callable
-
実行する処理
Return values
array<string|int, mixed> —MCP仕様に準拠したレスポンス
getExtensionFromMimeType()
MIMEタイプから拡張子を取得
protected
getExtensionFromMimeType(string $mimeType) : string
Parameters
- $mimeType : string
-
MIMEタイプ
Return values
string —ファイル拡張子
getMimeTypeFromExtension()
拡張子からMIMEタイプを取得
protected
getMimeTypeFromExtension(string $extension) : string
Parameters
- $extension : string
-
ファイル拡張子
Return values
string —MIMEタイプ
isAllowedExtension()
許可された拡張子かチェック
protected
isAllowedExtension(string $extension) : bool
Parameters
- $extension : string
-
ファイル拡張子
Return values
bool —許可されている場合はtrue
isFileUploadable()
値がファイルアップロード可能な形式かどうかを判定
protected
isFileUploadable(mixed $value) : bool
ファイルアップロード可能な形式は data: URI と http(s) URL の2方式のみ (チャンクアップロードは廃止したため、拡張子付きの文字列は対象外)
Parameters
- $value : mixed
-
判定対象の値
Return values
bool —ファイルアップロード可能な形式の場合true
processBase64File()
Base64エンコードされたファイルデータを処理
protected
processBase64File(string $base64Data) : array<string|int, mixed>
Parameters
- $base64Data : string
-
base64エンコードされたファイルデータ
Tags
Return values
array<string|int, mixed> —アップロード情報の配列
processFileUpload()
ファイルアップロード処理
protected
processFileUpload(string $fileData[, string $fieldName = 'file' ]) : array<string|int, mixed>|false
Parameters
- $fileData : string
-
画像の URL、または data: URI 形式の base64 データ
- $fieldName : string = 'file'
-
フィールド名(ログ用)
Return values
array<string|int, mixed>|false —アップロード情報の配列、失敗時はfalse
processImageUpload()
画像ファイル専用のアップロード処理
protected
processImageUpload(string $imageData) : array<string|int, mixed>|false
Parameters
- $imageData : string
-
画像の URL、または data: URI 形式の base64 データ
Return values
array<string|int, mixed>|false —アップロード情報の配列、失敗時はfalse
processUrlFile()
URLからファイルをダウンロードして処理
protected
processUrlFile(string $url) : array<string|int, mixed>
Parameters
- $url : string
-
ファイルのURL
Tags
Return values
array<string|int, mixed> —アップロード情報の配列
resolveLoginUserId()
操作者のユーザーIDを解決する
protected
resolveLoginUserId([int|null $loginUserId = null ]) : int|null
MCP のツールは JSON-RPC の引数しか受け取らないため、認証済みの操作者は McpContext から取得する。引数で明示された場合はそれを優先する (テストなど、コンテキストを持たない経路のため)。
Parameters
- $loginUserId : int|null = null
-
引数で渡されたユーザーID
Return values
int|nullsaveDblog()
操作ログを保存する
protected
saveDblog(mixed $userId, mixed $message) : void
Parameters
- $userId : mixed
- $message : mixed