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

mcp_share_inventory()

Description

Summarise recorded shares. Bearer keys are used only to derive an opaque management identifier on the server.

Parameters

ColumnTypeDefaultDescription
$args: array
$args array Validated tool arguments.

Return

array Structured MCP result or permission/availability error.

Location

include/mcp_management_functions.php lines 290 to 338

Definition

 
function mcp_share_inventory(array $args): array
{
    
$filters = ['share_type' => 0];
    if (!
checkperm('a')) {
        
$filters['share_user'] = $GLOBALS['userref'];
        if (!isset(
$args['ref']) && !isset($args['collection'])) {
            return 
mcp_error_result('Select an accessible resource or collection for your own shares.', 'scope_required');
        }
    }
    if (isset(
$args['ref'])) {
        
mcp_visible_resource($args['ref']);
        
$filters['share_resource'] = $args['ref'];
    }
    if (isset(
$args['collection'])) {
        if (
checkperm('b') || !collection_readable($args['collection'])) {
            throw new 
DomainException('Collection unavailable.');
        }
        
$filters['share_collection'] = $args['collection'];
    }
    
$shares = get_external_shares($filters, true);
    
$range = mcp_event_dates($args, 'expires');
    
$sql = "SELECT access_key, user AS creator, resource, collection, date, expires, access, lastused FROM ({$shares->sql}) shares WHERE {$range->sql}";
    if (isset(
$args['status'])) {
        
$sql .= $args['status'] === 'active' ? ' AND (expires IS NULL OR expires >= NOW())' : ' AND expires < NOW()';
    }
    
$rows = sql_limit_with_total_count(new PreparedStatementQuery(
        
$sql . ' ORDER BY date DESC, access_key',
        
array_merge($shares->parameters, $range->parameters)
    ), 
$args['limit'] ?? 25, $args['offset'] ?? 0);
    foreach (
$rows['data'] as &$row) {
        if (!empty(
$GLOBALS['scramble_key'])) {
            
$row['share_reference'] = hash_hmac('sha256', 'mcp-share:' . $row['access_key'], $GLOBALS['scramble_key']);
        }
        unset(
$row['access_key']);
        if (!
is_positive_int_loose($row['collection']) || checkperm('b') || !collection_readable((int) $row['collection'])) {
            unset(
$row['collection']);
        }
        if (
is_positive_int_loose($row['resource'])) {
            try {
                
mcp_visible_resource((int) $row['resource']);
            } catch (
DomainException $error) {
                unset(
$row['resource']);
            }
        } else {
            unset(
$row['resource']);
        }
    }
    return 
mcp_result(['total' => $rows['total'], 'rows' => $rows['data']]);
}

This article was last updated 4th December 2026 11:35 Europe/London time based on the source file dated 4th December 2026 09:40 Europe/London time.