Skip to main content
Glama

rename_symbol

Rename variables, functions, or classes across all files in a project. Update symbol names consistently throughout your codebase to maintain clarity and avoid errors.

Instructions

Rename a symbol (variable, function, class, etc.) across all files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesFile containing the symbol
lineYesLine number of the symbol
characterNoCharacter position of the symbol
newNameYesNew name for the symbol
languageNoProgramming languagetypescript

Implementation Reference

  • The main handler function that executes the rename_symbol tool using LSP textDocument/rename request and applies the workspace edit.
    export async function renameSymbol(args: RenameSymbolArgs, clientManager: LSPClientManager) { const { file, line, character = 0, newName, language = 'typescript' } = args; const workspaceRoot = findWorkspaceRoot(file); try { const client = await clientManager.getOrCreateLSPClient(language, workspaceRoot); // Open the file const content = await fs.readFile(file, 'utf-8'); await clientManager.sendLSPNotification(client, 'textDocument/didOpen', { textDocument: { uri: `file://${file}`, languageId: language, version: 1, text: content, }, }); const workspaceEdit = await clientManager.sendLSPRequest(client, 'textDocument/rename', { textDocument: { uri: `file://${file}` }, position: { line: line - 1, character }, newName, }); if (workspaceEdit) { const edit = workspaceEdit as LSPWorkspaceEdit; await applyWorkspaceEdit(edit); const changedFiles = Object.keys(edit.changes || {}); return { content: [ { type: 'text', text: `Successfully renamed symbol to '${newName}' across ${changedFiles.length} files`, }, ], }; } else { throw new Error('No workspace edit returned from LSP server'); } } catch (error) { throw new Error(`Failed to rename symbol: ${error instanceof Error ? error.message : String(error)}`); } }
  • src/server.ts:171-202 (registration)
    Registration of the 'rename_symbol' tool in the listTools response, including name, description, and input schema.
    { name: 'rename_symbol', description: 'Rename a symbol (variable, function, class, etc.) across all files', inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'File containing the symbol', }, line: { type: 'number', description: 'Line number of the symbol', }, character: { type: 'number', description: 'Character position of the symbol', default: 0, }, newName: { type: 'string', description: 'New name for the symbol', }, language: { type: 'string', description: 'Programming language', default: 'typescript', }, }, required: ['file', 'line', 'newName'], }, },
  • src/server.ts:220-221 (registration)
    Handler dispatch in the switch statement for the 'rename_symbol' tool call.
    case 'rename_symbol': return await renameSymbol(args as unknown as RenameSymbolArgs, this.clientManager);
  • TypeScript interface defining the arguments for the rename_symbol tool.
    export interface RenameSymbolArgs { file: string; line: number; character?: number; newName: string; language?: string; }

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/sminnee/lsp-mcp'

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