mcp_read_tool()
Description
Dispatch only the explicitly registered, read-only MCP capabilities.Parameters
| Column | Type | Default | Description |
|---|---|---|---|
| $name | string | ||
| $args: | array |
Location
include/mcp_browse_functions.php lines 277 to 350
Definition
function mcp_read_tool(string $name, array $args): array
{
$ref = $args['ref'] ?? null;
if ($name === 'get_system_info') {
return mcp_result(['name' => $GLOBALS['applicationname'], 'version' => $GLOBALS['productversion'],
'tools' => array_keys(mcp_tools()), 'read_only' => true,
'features' => ['comments' => (bool) $GLOBALS['comments_resource_enable'], 'relationships' => (bool) $GLOBALS['enable_related_resources']],
'search' => ['keywords', 'phrases', 'field shorthands', 'node IDs', 'date ranges', 'orientation', 'workflow state', 'sorting']]);
}
if ($ref !== null) {
$resource = mcp_visible_resource($ref);
}
if ($name === 'get_resource_preview') {
$image = mcp_preview_image($resource, ($args['size'] ?? 'screen') === 'screen');
if (!$image) {
return mcp_error_result('No permitted stored preview is available.', 'preview_unavailable');
}
$bytes = base64_decode($image['data']);
[$width, $height] = getimagesizefromstring($bytes);
$result = mcp_result(['ref' => $ref, 'width' => $width, 'height' => $height, 'mimeType' => $image['mimeType'], 'size' => strlen($bytes)]);
$result['content'][] = $image;
return $result;
}
if ($name === 'get_resource_log') {
return mcp_history($ref, $args);
}
if ($name === 'get_resource_usage') {
require_once __DIR__ . '/log_functions.php';
if (!can_view_download_log($ref, LOG_CODE_DOWNLOADED)) {
throw new DomainException('Usage unavailable.');
}
$range = mcp_event_dates($args);
$count = ps_value(
"SELECT COUNT(*) AS value FROM resource_log r WHERE r.resource = ? AND BINARY r.type = ? AND {$range->sql}",
['i', $ref, 's', LOG_CODE_DOWNLOADED, ...$range->parameters],
0
);
return mcp_result(['ref' => $ref, 'downloads' => (int) $count]);
}
if ($name === 'get_resource_comments') {
if (!$GLOBALS['comments_resource_enable']) {
throw new DomainException('Resource comments unavailable.');
}
require_once __DIR__ . '/comment_functions.php';
$comments = [];
foreach (get_comments_by_ref($ref, limit: $args['limit'] ?? 25, offset: $args['offset'] ?? 0, omit_hidden: true) as $comment) {
$comments[] = ['ref' => (int) $comment['ref'], 'created' => (string) $comment['created'], 'body' => (string) $comment['body']];
}
return mcp_result(['comments' => $comments]);
}
if (!checkperm('s')) {
throw new DomainException('Search unavailable.');
}
switch ($name) {
case 'get_resource_types':
$rows = get_resource_types();
return mcp_list_page('resource_types', array_map(static fn($row) => ['ref' => (int) $row['ref']]
+ array_intersect_key($row, array_flip(['name', 'allowed_extensions'])), $rows), $args);
case 'get_resource_type_fields':
return mcp_list_page('fields', mcp_field_catalogue($args['resource_type'] ?? null), $args);
case 'get_field_options':
return mcp_field_options($args);
case 'get_collection_resources':
return mcp_search(['query' => '!collection' . $args['collection']] + $args);
case 'get_related_resources':
$GLOBALS['related_search_show_self'] = false;
return mcp_search(['query' => '!related' . $ref] + $args);
case 'get_featured_collections':
case 'search_collections':
return mcp_collections($name, $args);
default:
return mcp_report($name, $args);
}
}
This article was last updated 3rd December 2026 19:35 Europe/London time based on the source file dated 3rd December 2026 16:30 Europe/London time.