Coding standards
Security in ResourceSpace
Developer reference
Database
Mcp browse functions
Mcp report functions
Mcp management functions
Core feature functions
Embed functions

mcp_read_tool()

Description

Dispatch only the explicitly registered, read-only MCP capabilities.

Parameters

ColumnTypeDefaultDescription
$name string
$args: array $args['ref'] ?? null; if issetmcp_management_tools[$name]

Location

include/mcp_browse_functions.php lines 356 to 447

Definition

 
function mcp_read_tool(string $name, array $args): array
{
    
$ref = $args['ref'] ?? null;
    if (isset(
mcp_management_tools()[$name])) {
        return 
mcp_management_read($name, $args);
    }
    if (
$name === 'get_system_info') {
        
$plugins = $GLOBALS['plugins'];
        
$features = [
            
'comments' => (bool) $GLOBALS['comments_resource_enable'], 'relationships' => (bool) $GLOBALS['enable_related_resources'],
            
'licences' => in_array('licensemanager', $plugins, true), 'consent' => in_array('consentmanager', $plugins, true),
            
'stored_image_similarity' => in_array('clip', $plugins, true) && !checkperm('clip-v'),
            
'rse_version' => core_feature_enabled('rse_version'), 'rse_workflow' => core_feature_enabled('rse_workflow'),
            
'named_person_tags' => in_array('faces', $plugins, true) && !checkperm('faces-v'),
            
'user_administration' => checkPermission_manage_users(), 'installation_statistics' => checkperm('a') && checkperm('t'),
            
'workflow_requests' => checkperm('R'), 'report_catalogue' => checkperm('t'),
        ];
        return 
mcp_result(['name' => $GLOBALS['applicationname'], 'version' => $GLOBALS['productversion'],
            
'tools' => array_keys(mcp_tools()), 'read_only' => true, 'timezone' => date_default_timezone_get(),
            
'language' => $GLOBALS['language'] ?? 'en', 'plugins' => array_values(array_intersect(
                [
'licensemanager', 'consentmanager', 'clip', 'faces', 'whisper', 'tesseract', 'brand_guidelines', 'google_vision'],
                
$GLOBALS['plugins']
            )),
            
'features' => $features, 'mcp_version' => $GLOBALS['productversion'], 'preview_sizes' => ['thumbnail', 'screen', 'large'],
            
'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') {
        
$size = $args['size'] ?? 'screen';
        
$image = mcp_preview_image($resource, $size !== 'thumbnail', $args['page'] ?? 1, $size === 'large');
        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, 'page' => $args['page'] ?? 1, '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 4th December 2026 17:35 Europe/London time based on the source file dated 4th December 2026 14:10 Europe/London time.