Skip to main content
Glama

roots

Lists allowed workspace directories to scope filesystem operations. Call this tool first to define accessible paths for subsequent actions.

Instructions

List allowed workspace roots. Call first — all other tools are scoped to these directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that executes the logic to fetch and return the allowed workspace directories.
    function handleListAllowedDirectories(): ToolResponse<
      z.infer<typeof ListAllowedDirectoriesOutputSchema>
    > {
      const dirs = getAllowedDirectories();
      const structured = {
        ok: true,
        directories: dirs,
      } as const;
      return buildToolResponse(buildTextRoots(dirs), structured);
    }
  • The tool definition (schema) for the "roots" tool.
    export const LIST_ALLOWED_DIRECTORIES_TOOL: ToolContract = {
      name: 'roots',
      title: 'Workspace Roots',
      description:
        'List allowed workspace roots. Call first \u2014 all other tools are scoped to these directories.',
      inputSchema: ListAllowedDirectoriesInputSchema,
      outputSchema: ListAllowedDirectoriesOutputSchema,
      annotations: READ_ONLY_TOOL_ANNOTATIONS,
      taskSupport: 'forbidden',
    } as const;
  • The registration function that registers the "roots" tool with the MCP server.
    export function registerListAllowedDirectoriesTool(
      server: McpServer,
      options: ToolRegistrationOptions = {}
    ): void {
      const handler = (
        _args: z.infer<typeof ListAllowedDirectoriesInputSchema>,
        extra: ToolExtra
      ): Promise<ToolResult<z.infer<typeof ListAllowedDirectoriesOutputSchema>>> =>
        executeToolWithDiagnostics({
          toolName: 'roots',
          extra,
          outputSchema: ListAllowedDirectoriesOutputSchema,
          run: () => handleListAllowedDirectories(),
          onError: (error) => buildToolErrorResponse(error, ErrorCode.E_UNKNOWN),
        });
    
      const wrappedHandler = wrapToolHandler(handler, {
        guard: options.isInitialized,
        progressMessage: () => '≣ roots',
        completionMessage: (_args, result) => {
          if (result.isError) return `≣ roots • failed`;
          const sc = result.structuredContent;
          const count = sc.directories?.length ?? 0;
          return `≣ roots • ${count} ${count === 1 ? 'root' : 'roots'}`;
        },
      });
    
      const validatedHandler = withValidatedArgs(
        ListAllowedDirectoriesInputSchema,
        wrappedHandler
      );
    
      if (
        registerToolTaskIfAvailable(
          server,
          'roots',
          LIST_ALLOWED_DIRECTORIES_TOOL,
          validatedHandler,
          options.iconInfo,
          options.isInitialized
        )
      )
        return;
      server.registerTool(
        'roots',
        withDefaultIcons({ ...LIST_ALLOWED_DIRECTORIES_TOOL }, options.iconInfo),
        validatedHandler
      );
    }

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/j0hanz/filesystem-mcp'

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