baserCMS クラスリファレンス

CustomFieldsTool 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']
ツールの戻り値のスキーマ
TYPES  : mixed = ['BcCcAutoZip' => '郵便番号', 'BcCcCheckbox' => 'チェ...
タイプ
VALIDATION_RULES  : mixed = ['EMAIL' => 'Eメール形式チェック', 'EMAIL_CONFIRM' => 'E...

Methods

addCustomField()  : array<string|int, mixed>
カスタムフィールドを追加
deleteCustomField()  : array<string|int, mixed>
カスタムフィールドを削除
editCustomField()  : array<string|int, mixed>
カスタムフィールドを編集
getCustomField()  : array<string|int, mixed>
カスタムフィールドを取得
getCustomFields()  : 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 に限られる。

個々のツールの戻り値の構造はエンティティの構成に依存するため、 ここでは型のみを宣言する。

TYPES

タイプ

private mixed TYPES = ['BcCcAutoZip' => '郵便番号', 'BcCcCheckbox' => 'チェックボックス', 'BcCcDate' => '日付', 'BcCcDateTime' => '日時', 'BcCcEmail' => 'メールアドレス', 'BcCcFile' => 'ファイルアップロード', 'BcCcHidden' => '隠しフィールド', 'BcCcMultiple' => '複数選択', 'BcCcPassword' => 'パスワード', 'BcCcPref' => '都道府県リスト', 'BcCcRadio' => 'ラジオボタン', 'BcCcRelated' => '関連データ', 'BcCcSelect' => 'セレクトボックス', 'BcCcTel' => '電話番号', 'BcCcText' => '1行テキスト', 'BcCcTextarea' => '複数行テキスト', 'BcCcWysiwyg' => 'WYSIWYGエディタ', 'CuCcBurgerEditor' => 'ブロックエディタ']

VALIDATION_RULES

private mixed VALIDATION_RULES = ['EMAIL' => 'Eメール形式チェック', 'EMAIL_CONFIRM' => 'Eメール比較チェック、比較対象のフィールド名を、`meta` フィールドに配列として、キー `BcCustomContent` 配下に、キー `email_confirm` として指定', 'NUMBER' => '数値チェック', 'HANKAKU' => '半角英数チェック', 'ZENKAKU_KATAKANA' => '全角カタカナチェック', 'ZENKAKU_HIRAGANA' => '全角ひらがなチェック', 'DATETIME' => '日付チェック', 'MAX_FILE_SIZE' => 'ファイルアップロードサイズ制限、上限となる数値を単位MBで、`meta` フィールドに配列として、キー `BcCustomContent` 配下に、キー `max_file_size` として指定', 'FILE_EXT' => 'ファイル拡張子チェック、アップロードを許可する拡張子をカンマ区切りで、`meta` フィールドに配列として、キー `BcCustomContent` 配下に、キー `file_ext` として指定']

Methods

addCustomField()

カスタムフィールドを追加

public addCustomField(string $name, string $title, string $type[, int $status = 1 ][, string|null $defaultValue = null ][, array<string|int, mixed>|null $validate = null ][, string|null $regex = null ][, string|null $regexErrorMessage = null ][, bool|null $counter = null ][, string|null $autoConvert = null ][, string|null $placeholder = null ][, int|null $size = null ][, int|null $line = null ][, int|null $maxLength = null ][, string|null $source = null ][, string|null $meta = null ][, int|null $loginUserId = null ]) : array<string|int, mixed>
Parameters
$name : string
$title : string
$type : string
$status : int = 1
$defaultValue : string|null = null
$validate : array<string|int, mixed>|null = null
$regex : string|null = null
$regexErrorMessage : string|null = null
$counter : bool|null = null
$autoConvert : string|null = null
$placeholder : string|null = null
$size : int|null = null
$line : int|null = null
$maxLength : int|null = null
$source : string|null = null
$meta : string|null = null
$loginUserId : int|null = null
Return values
array<string|int, mixed>

deleteCustomField()

カスタムフィールドを削除

public deleteCustomField(int $id[, int|null $loginUserId = null ]) : array<string|int, mixed>
Parameters
$id : int
$loginUserId : int|null = null
Return values
array<string|int, mixed>

editCustomField()

カスタムフィールドを編集

public editCustomField(int $id[, string|null $name = null ][, string|null $title = null ][, string|null $type = null ][, int|null $status = null ][, string|null $defaultValue = null ][, array<string|int, mixed>|null $validate = null ][, string|null $regex = null ][, string|null $regexErrorMessage = null ][, bool|null $counter = null ][, string|null $autoConvert = null ][, string|null $placeholder = null ][, int|null $size = null ][, int|null $line = null ][, int|null $maxLength = null ][, string|null $source = null ][, string|null $meta = null ][, int|null $loginUserId = null ]) : array<string|int, mixed>
Parameters
$id : int
$name : string|null = null
$title : string|null = null
$type : string|null = null
$status : int|null = null
$defaultValue : string|null = null
$validate : array<string|int, mixed>|null = null
$regex : string|null = null
$regexErrorMessage : string|null = null
$counter : bool|null = null
$autoConvert : string|null = null
$placeholder : string|null = null
$size : int|null = null
$line : int|null = null
$maxLength : int|null = null
$source : string|null = null
$meta : string|null = null
$loginUserId : int|null = null
Return values
array<string|int, mixed>

getCustomField()

カスタムフィールドを取得

public getCustomField(int $id) : array<string|int, mixed>
Parameters
$id : int
Return values
array<string|int, mixed>

getCustomFields()

カスタムフィールド一覧を取得

public getCustomFields([string|null $name = null ][, string|null $title = null ][, string|null $type = null ][, int|null $status = null ]) : array<string|int, mixed>
Parameters
$name : string|null = null
$title : string|null = null
$type : string|null = null
$status : int|null = null
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
checked
noTodo
unitTest
Return values
array<string|int, mixed>|mixed|object

hasService()

Has Service

public hasService(mixed $service) : bool
Parameters
$service : mixed
Tags
checked
noTodo
unitTest
Return values
bool

registerTools()

カスタムフィールド関連のツールをサーバーに登録する

public registerTools(McpServer $server) : McpServer
Parameters
$server : McpServer

SDK のサーバー

Return values
McpServer

cleanupTempFile()

一時ファイルをクリーンアップ

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
UploadedFileInterface

detectMimeTypeFromContent()

ファイル内容から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
throws
Exception
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
throws
Exception
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|null

saveDblog()

操作ログを保存する

protected saveDblog(mixed $userId, mixed $message) : void
Parameters
$userId : mixed
$message : mixed
On this page

Search results