BlogContentsTool
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
- addBlogContent() : array<string|int, mixed>
- ブログコンテンツを追加
- deleteBlogContent() : array<string|int, mixed>
- ブログコンテンツを削除
- editBlogContent() : array<string|int, mixed>
- ブログコンテンツを編集
- getBlogContent() : array<string|int, mixed>
- ブログコンテンツを取得
- getBlogContents() : 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
addBlogContent()
ブログコンテンツを追加
public
addBlogContent(string $name, string $title[, 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 $listCount = 10 ][, string|null $listDirection = 'DESC' ][, int|null $feedCount = 10 ][, bool|null $commentUse = false ][, bool|null $commentApprove = false ][, bool|null $tagUse = false ][, int|null $eyeCatchSizeThumbWidth = null ][, int|null $eyeCatchSizeThumbHeight = null ][, int|null $eyeCatchSizeMobileThumbWidth = null ][, int|null $eyeCatchSizeMobileThumbHeight = null ][, bool|null $useContent = false ][, int|null $widgetArea = null ][, int|null $loginUserId = null ]) : array<string|int, mixed>
Parameters
- $name : string
- $title : string
- $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'
- $listCount : int|null = 10
- $listDirection : string|null = 'DESC'
- $feedCount : int|null = 10
- $commentUse : bool|null = false
- $commentApprove : bool|null = false
- $tagUse : bool|null = false
- $eyeCatchSizeThumbWidth : int|null = null
- $eyeCatchSizeThumbHeight : int|null = null
- $eyeCatchSizeMobileThumbWidth : int|null = null
- $eyeCatchSizeMobileThumbHeight : int|null = null
- $useContent : bool|null = false
- $widgetArea : int|null = null
- $loginUserId : int|null = null
Return values
array<string|int, mixed>deleteBlogContent()
ブログコンテンツを削除
public
deleteBlogContent(int $id[, int|null $loginUserId = null ]) : array<string|int, mixed>
Parameters
- $id : int
- $loginUserId : int|null = null
Return values
array<string|int, mixed>editBlogContent()
ブログコンテンツを編集
public
editBlogContent(int $id[, string|null $name = null ][, string|null $title = null ][, int|null $siteId = null ][, int|null $parentId = null ][, string|null $description = null ][, int|null $authorId = null ][, string|null $layoutTemplate = null ][, bool|null $status = null ][, string|null $publishBegin = null ][, string|null $publishEnd = null ][, bool|null $excludeSearch = null ][, bool|null $excludeMenu = null ][, bool|null $blankLink = null ][, string|null $template = null ][, int|null $listCount = null ][, string|null $listDirection = null ][, int|null $feedCount = null ][, bool|null $commentUse = null ][, bool|null $commentApprove = null ][, bool|null $tagUse = null ][, int|null $eyeCatchSizeThumbWidth = null ][, int|null $eyeCatchSizeThumbHeight = null ][, int|null $eyeCatchSizeMobileThumbWidth = null ][, int|null $eyeCatchSizeMobileThumbHeight = null ][, bool|null $useContent = null ][, int|null $widgetArea = null ][, int|null $loginUserId = null ]) : array<string|int, mixed>
Parameters
- $id : int
- $name : string|null = null
- $title : string|null = null
- $siteId : int|null = null
- $parentId : int|null = null
- $description : string|null = null
- $authorId : int|null = null
- $layoutTemplate : string|null = null
- $status : bool|null = null
- $publishBegin : string|null = null
- $publishEnd : string|null = null
- $excludeSearch : bool|null = null
- $excludeMenu : bool|null = null
- $blankLink : bool|null = null
- $template : string|null = null
- $listCount : int|null = null
- $listDirection : string|null = null
- $feedCount : int|null = null
- $commentUse : bool|null = null
- $commentApprove : bool|null = null
- $tagUse : bool|null = null
- $eyeCatchSizeThumbWidth : int|null = null
- $eyeCatchSizeThumbHeight : int|null = null
- $eyeCatchSizeMobileThumbWidth : int|null = null
- $eyeCatchSizeMobileThumbHeight : int|null = null
- $useContent : bool|null = null
- $widgetArea : int|null = null
- $loginUserId : int|null = null
Return values
array<string|int, mixed>getBlogContent()
ブログコンテンツを取得
public
getBlogContent(int $id) : array<string|int, mixed>
Parameters
- $id : int
Return values
array<string|int, mixed>getBlogContents()
ブログコンテンツ一覧を取得
public
getBlogContents([string|null $title = null ][, int|null $status = null ][, int|null $limit = null ][, int|null $page = null ]) : array<string|int, mixed>
Parameters
- $title : string|null = null
- $status : int|null = null
- $limit : int|null = null
- $page : 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
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