Skip to main content
Glama

rename_symbol

Rename Svelte symbols across your workspace with automatic file updates. Change variable, function, or component names while maintaining consistency throughout your project.

Instructions

Rename a symbol across the workspace. Applies changes to disk.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file
symbolNameYesName of the symbol to rename
newNameYesNew name for the symbol
symbolKindNoKind of symbol

Implementation Reference

  • The `rename_symbol` tool is registered and implemented in this block, using LSP `textDocument/prepareRename` and `textDocument/rename` requests, and then applying the changes via `applyWorkspaceEdit`.
    server.registerTool(
      "rename_symbol",
      {
        title: "Rename Symbol",
        description:
          "Rename a symbol across the workspace. Applies changes to disk.",
        inputSchema: z.object({
          filePath: z.string().describe("Absolute path to the file"),
          symbolName: z.string().describe("Name of the symbol to rename"),
          newName: z.string().describe("New name for the symbol"),
          symbolKind: z.string().optional().describe("Kind of symbol"),
        }),
      },
      async ({
        filePath,
        symbolName,
        newName,
        symbolKind,
      }): Promise<ToolResult> => {
        try {
          const prep = await prepareSymbolRequest(lsp, filePath, symbolName, symbolKind);
          if ("error" in prep) return textResult(prep.error);
    
          // Prepare rename check
          const prepareResult = await lsp.request(
            "textDocument/prepareRename",
            makePositionParams(prep.ctx)
          );
          if (!prepareResult) {
            return textResult(`Symbol '${symbolName}' cannot be renamed.`);
          }
    
          // Execute rename
          const renameParams = {
            ...makePositionParams(prep.ctx),
            newName,
          };
          const result = await lsp.request("textDocument/rename", renameParams);
    
          if (!result) return textResult("Rename failed - no changes returned.");
    
          const applied = await applyWorkspaceEdit(lsp, result);
          const summary = formatRenameEdit(result, symbolName, newName);
          return textResult(
            applied
              ? summary
              : `(dry-run, edits NOT applied to disk)\n\n${summary}`
          );
        } catch (ex) {
          return textResult(formatError(ex));
        }
      }
    );

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/adainrivers/SvelteLS.MCP'

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