Skip to main content
Glama

chown_items

Modify ownership (UID) and group (GID) for multiple files or directories in one operation using this tool on the MCP server 'filesystem-mcp'.

Instructions

Change owner (UID) and group (GID) for multiple specified files/directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
gidYesGroup ID.
pathsYesAn array of relative paths.
uidYesUser ID.

Implementation Reference

  • The main handler function for the 'chown_items' tool. It parses and validates input arguments, performs asynchronous chown operations on multiple file paths using fs.chown, handles errors and results with Promise.allSettled, sorts outputs by original order, and returns a JSON-formatted response.
    const handleChownItemsFunc = async (args: unknown): Promise<McpToolResponse> => {
      const { paths: relativePaths, uid, gid } = parseAndValidateArgs(args);
    
      const chownPromises = relativePaths.map((relativePath) =>
        processSingleChownOperation(relativePath, uid, gid),
      );
      const settledResults = await Promise.allSettled(chownPromises);
    
      const outputResults = processSettledResults(settledResults, relativePaths);
    
      // Sort results by original path order for predictability
      const originalIndexMap = new Map(relativePaths.map((p, i) => [p.replaceAll('\\', '/'), i]));
      outputResults.sort((a, b) => {
        const indexA = originalIndexMap.get(a.path) ?? Infinity;
        const indexB = originalIndexMap.get(b.path) ?? Infinity;
        return indexA - indexB;
      });
    
      return {
        content: [{ type: 'text', text: JSON.stringify(outputResults, undefined, 2) }],
      };
    };
  • Zod schema defining the input arguments for the 'chown_items' tool: an array of relative paths (non-empty), integer UID, and integer GID.
    export const ChownItemsArgsSchema = z
      .object({
        paths: z
          .array(z.string())
          .min(1, { message: 'Paths array cannot be empty' })
          .describe('An array of relative paths.'),
        uid: z.number().int({ message: 'UID must be an integer' }).describe('User ID.'),
        gid: z.number().int({ message: 'GID must be an integer' }).describe('Group ID.'),
      })
      .strict();
  • The tool definition object for 'chown_items', specifying name, description, input schema, and handler function reference.
    export const chownItemsToolDefinition = {
      name: 'chown_items',
      description: 'Change owner (UID) and group (GID) for multiple specified files/directories.',
      inputSchema: ChownItemsArgsSchema,
      handler: handleChownItemsFunc,
    };
  • Import and inclusion of chownItemsToolDefinition in the allToolDefinitions array for tool registration.
    import { chownItemsToolDefinition } from './chown-items.js';
    import { moveItemsToolDefinition } from './move-items.js';
    import { copyItemsToolDefinition } from './copy-items.js';
    import { searchFilesToolDefinition } from './search-files.js';
    import { replaceContentToolDefinition } from './replace-content.js';
    import { handleApplyDiff } from './apply-diff.js';
    import { applyDiffInputSchema, ApplyDiffOutput } from '../schemas/apply-diff-schema.js';
    import fs from 'node:fs';
    import path from 'node:path';
    
    // Define the structure for a tool definition (used internally and for index.ts)
    import type { ZodType } from 'zod';
    import type { McpToolResponse } from '../types/mcp-types.js';
    
    // Define local interfaces based on usage observed in handlers
    // Define the structure for a tool definition
    // Matches the structure in individual tool files like applyDiff.ts
    export interface ToolDefinition<TInput = unknown, TOutput = unknown> {
      name: string;
      description: string;
      inputSchema: ZodType<TInput>;
      outputSchema?: ZodType<TOutput>;
      handler: (args: TInput) => Promise<McpToolResponse>; // Changed _args to args
    }
    
    // Helper type to extract input type from a tool definition
    export type ToolInput<T extends ToolDefinition> =
      T extends ToolDefinition<infer I, unknown> ? I : never;
    
    // Define a more specific type for our tool definitions to avoid naming conflicts
    type HandlerToolDefinition = {
      name: string;
      description: string;
      inputSchema: ZodType<unknown>;
      outputSchema?: ZodType<unknown>;
      handler: (args: unknown) => Promise<{ content: Array<{ type: 'text'; text: string }> }>;
    };
    
    // Aggregate all tool definitions into a single array
    // Use our more specific type to avoid naming conflicts
    export const allToolDefinitions: HandlerToolDefinition[] = [
      listFilesToolDefinition,
      statItemsToolDefinition,
      readContentToolDefinition,
      writeContentToolDefinition,
      deleteItemsToolDefinition,
      createDirectoriesToolDefinition,
      chmodItemsToolDefinition,
      chownItemsToolDefinition,
  • Core helper function that resolves the path, checks against project root, and performs the actual fs.chown operation for a single path, with error handling.
    async function processSingleChownOperation(
      relativePath: string,
      uid: number,
      gid: number,
    ): Promise<ChownResult> {
      const pathOutput = relativePath.replaceAll('\\', '/');
      try {
        const targetPath = await resolvePath(relativePath);
        if (targetPath === PROJECT_ROOT) {
          return {
            path: pathOutput,
            success: false,
            error: 'Changing ownership of the project root is not allowed.',
          };
        }
        await fs.chown(targetPath, uid, gid);
        return { path: pathOutput, success: true, uid, gid };
      } catch (error: unknown) {
        return handleChownError(error, relativePath, pathOutput);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool changes ownership, implying a mutation operation, but lacks details on permissions required, whether changes are reversible, error handling (e.g., for invalid paths), or side effects (e.g., affecting file access). For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Change owner and group') and target ('multiple specified files/directories'). It avoids redundancy and wastes no words, making it easy to parse quickly. Every part of the sentence contributes directly to understanding the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation operation with 3 required parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like permissions needed, error cases, or return values, leaving gaps that could hinder an agent's ability to use it correctly. More context is needed for a mutation tool in this environment.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for 'gid' (Group ID), 'paths' (array of relative paths), and 'uid' (User ID). The description adds no additional parameter semantics beyond what the schema provides, such as format examples or constraints (e.g., numeric ranges for IDs). Baseline 3 is appropriate since the schema adequately documents parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Change owner and group') and target ('multiple specified files/directories'), which is specific and unambiguous. It distinguishes itself from siblings like 'chmod_items' (change permissions) and 'stat_items' (view metadata), though it doesn't explicitly name these alternatives. The purpose is well-defined but could be slightly more precise about the scope of change.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., requiring appropriate permissions), exclusions (e.g., not for single files), or contextual cues (e.g., use for bulk ownership changes). Given siblings like 'chmod_items' for permissions and 'stat_items' for viewing metadata, explicit differentiation would help agents choose correctly.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SylphxAI/filesystem-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server