Skip to main content
Glama

switch_directory

Change the root directory for all services. Accepts an absolute path, rebuilds, and returns success confirmation.

Instructions

Accepts { path } (absolute path). Rebuilds all services for the new root directory. Returns { root, switched: true } on success. Call get_stats after switching to verify.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The makeSwitchDirectoryTool function creates the switch_directory ToolHandler. It validates the path is absolute, checks the directory exists via fs.stat, then calls rebuildServices to rebuild all services for the new root path. On success, returns { root, switched: true }.
    function makeSwitchDirectoryTool(
      container: ServiceContainer,
      rebuildServices: RebuildServices,
    ): ToolHandler {
      return {
        name: "switch_directory",
        description:
          "Accepts `{ path }` (absolute path). Rebuilds all services for the new root directory. Returns `{ root, switched: true }` on success. Call `get_stats` after switching to verify.",
        inputSchema: SwitchDirectorySchema,
        async handler(args): Promise<ToolResponse> {
          try {
            const { path: dirPath } = SwitchDirectorySchema.parse(args);
            log.info({ path: dirPath }, "switch_directory called");
    
            if (!path.isAbsolute(dirPath)) {
              return {
                content: [{ type: "text", text: JSON.stringify({
                  root: getRoot(container),
                  error: `Path must be absolute. Received: ${dirPath}`,
                  possibleSolutions: ["Provide a full absolute path (e.g. /home/user/notes or C:\\Users\\user\\notes)"],
                }) }],
                isError: true,
              };
            }
    
            // Validate directory exists
            try {
              const stat = await fs.stat(dirPath);
              if (!stat.isDirectory()) {
                return {
                  content: [{ type: "text", text: JSON.stringify({
                    root: getRoot(container),
                    error: `Path is not a directory: ${dirPath}`,
                    possibleSolutions: ["Check the path points to a directory, not a file"],
                  }) }],
                  isError: true,
                };
              }
            } catch {
              return {
                content: [{ type: "text", text: JSON.stringify({
                  root: getRoot(container),
                  error: `Directory does not exist: ${dirPath}`,
                  possibleSolutions: ["Verify the directory path is correct and the directory exists"],
                }) }],
                isError: true,
              };
            }
    
            const resolvedPath = path.resolve(dirPath);
            container.services = await rebuildServices(resolvedPath);
    
            log.info({ path: resolvedPath }, "switch_directory complete");
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify({ root: resolvedPath, switched: true }),
                },
              ],
            };
          } catch (err) {
            log.error({ err }, "switch_directory failed");
            return {
              content: [{ type: "text", text: JSON.stringify({
                root: getRoot(container),
                error: err instanceof Error ? err.message : String(err),
                possibleSolutions: ["Verify the directory path is correct", "Check that the directory exists and is accessible"],
              }) }],
              isError: true,
            };
          }
        },
      };
    }
  • SwitchDirectorySchema: Zod schema requiring a 'path' string (min 1 char) described as 'Absolute path to the new root directory'.
    const SwitchDirectorySchema = z.object({
      path: z
        .string()
        .min(1)
        .describe("Absolute path to the new root directory."),
    });
  • registerDirectoryTools creates the tool via makeSwitchDirectoryTool(container, rebuildServices) and registers it in the registry Map by name.
    export function registerDirectoryTools(
      registry: Map<string, ToolHandler>,
      container: ServiceContainer,
      rebuildServices: RebuildServices,
    ): void {
      const tools = [
        makeListDirectoryTool(container),
        makeGetStatsTool(container),
        makeSwitchDirectoryTool(container, rebuildServices),
      ];
    
      for (const tool of tools) {
        registry.set(tool.name, tool);
      }
    }
  • registerTools calls registerDirectoryTools which registers switch_directory. The name is also in LITE_TOOL_NAMES set so it survives --lite mode filtering.
    export function registerTools(
      registry: Map<string, ToolHandler>,
      container: ServiceContainer,
      rebuildServices: RebuildServices,
      options: RegisterToolsOptions = {},
    ): void {
      registerNoteTools(registry, container);
      registerDirectoryTools(registry, container, rebuildServices);
      registerFrontmatterTools(registry, container);
      registerSearchTools(registry, container);
      registerSchemaTools(registry, container);
      registerCreateNoteTool(registry, container);
      registerLinkTools(registry, container);
    
      if (options.lite) {
        for (const name of registry.keys()) {
          if (!LITE_TOOL_NAMES.has(name)) registry.delete(name);
        }
      }
    }
  • requireServices throws an error mentioning switch_directory: 'Pass --root <path> when starting the server, or call switch_directory to set one.' This is a helper used by the handler.
    export function requireServices(container: ServiceContainer): Services {
      if (!container.services) {
        throw new Error(
          "No directory is active. Pass --root <path> when starting the server, or call switch_directory to set one.",
        );
      }
      return container.services;
    }
Behavior2/5

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

No annotations provided, so description carries full burden. It mentions rebuilding all services, implying a significant operation, but doesn't disclose potential side effects (e.g., state loss, service downtime, long execution time) or any destructive nature.

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?

Three sentences, no wasted words. Front-loaded input, then action, then return format, then a follow-up recommendation. Highly efficient.

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

Completeness4/5

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

Covers input, action, output, and a verification step. Lacks information about side effects or when the operation is complete (e.g., synchronous vs async). Still fairly complete for a simple switch.

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

Parameters4/5

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

Schema has 100% coverage with a string parameter 'path'. Description adds crucial semantic detail that the path must be absolute, which isn't in schema. This adds value beyond schema.

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

Purpose5/5

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

The description clearly states the tool's action using a specific verb ('rebuilds all services') and resource (new root directory). It distinguishes from sibling note editing tools by indicating it changes the working directory.

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?

No guidance on when to use this tool vs alternatives. It mentions calling get_stats after switching, but doesn't specify prerequisites, exclusions, or contexts where switching might not be appropriate.

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

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/Erodenn/markscribe'

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