Skip to main content
Glama

Get Code Actions

get_code_actions

List available code actions like quick fixes and refactorings for specific lines in Svelte files to improve code quality and structure.

Instructions

List available code actions (quick fixes, refactorings) for a line or range in a file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file
startLineYesStart line (1-based)
endLineNoEnd line (1-based). Defaults to startLine
kindNoFilter by kind: quickfix, refactor, refactor.extract, refactor.inline, refactor.rewrite, source, source.organizeImports, source.fixAll

Implementation Reference

  • The handler logic for 'get_code_actions' which fetches and formats code actions.
    async ({ filePath, startLine, endLine, kind }): Promise<ToolResult> => {
      try {
        const { actions, error } = await fetchCodeActions(
          lsp,
          filePath,
          startLine,
          endLine,
          kind
        );
        if (error) return textResult(error);
        if (!actions || actions.length === 0) {
          return textResult(
            `No code actions available at line ${startLine}` +
              (kind ? ` (kind: ${kind})` : "") +
              "."
          );
        }
    
        const lines: string[] = [
          `Found ${actions.length} code action(s) at line ${startLine}` +
            (endLine != null && endLine !== startLine
              ? `-${endLine}`
              : "") +
            ":",
          "",
        ];
    
        for (let i = 0; i < actions.length; i++) {
          const action = actions[i];
          const title = action.title ?? "?";
          const actionKind = action.kind ?? "";
          const isPreferred = action.isPreferred === true;
          const disabled = action.disabled?.reason;
    
          let entry = `  ${i + 1}. ${title}`;
          if (actionKind) entry += ` [${actionKind}]`;
          if (isPreferred) entry += " (preferred)";
          if (disabled) entry += ` (disabled: ${disabled})`;
          lines.push(entry);
        }
    
        return textResult(lines.join("\n"));
      } catch (ex) {
        return textResult(formatError(ex));
      }
    }
  • Registration of the 'get_code_actions' tool with its schema definition.
    server.registerTool(
      "get_code_actions",
      {
        title: "Get Code Actions",
        description:
          "List available code actions (quick fixes, refactorings) for a line or range in a file.",
        inputSchema: z.object({
          filePath: z.string().describe("Absolute path to the file"),
          startLine: z.number().describe("Start line (1-based)"),
          endLine: z
            .number()
            .optional()
            .describe("End line (1-based). Defaults to startLine"),
          kind: z
            .string()
            .optional()
            .describe(
              "Filter by kind: quickfix, refactor, refactor.extract, refactor.inline, refactor.rewrite, source, source.organizeImports, source.fixAll"
            ),
        }),
      },
  • Helper function that performs the actual LSP request to fetch code actions.
    async function fetchCodeActions(
      lsp: LspClient,
      filePath: string,
      startLine: number,
      endLine?: number,
      kind?: string
    ): Promise<{ actions?: any[]; error?: string }> {
      const prep = await prepareDocumentRequest(lsp, filePath);
      if ("error" in prep) return { error: prep.error };
    
      // Fetch diagnostics from cache for context
      const cachedDiags = lsp.getCachedDiagnostics(prep.uri);
      const sl = startLine - 1;
      const el = (endLine ?? startLine) - 1;
    
      const diagnosticsForRange = cachedDiags.filter((d: any) => {
        const diagStart = d.range?.start?.line ?? -1;
        const diagEnd = d.range?.end?.line ?? -1;
        return diagEnd >= sl && diagStart <= el;
      });
    
      const context: any = { diagnostics: diagnosticsForRange };
      if (kind) context.only = [kind];
    
      const result = await lsp.request("textDocument/codeAction", {
        textDocument: { uri: prep.uri },
        range: {
          start: { line: sl, character: 0 },
          end: { line: el + 1, character: 0 },
        },
        context,
      });
    
      return { actions: Array.isArray(result) ? result : [] };
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the action as listing code actions, implying a read-only operation, but doesn't specify whether it requires file access permissions, how results are structured (e.g., pagination), or potential errors (e.g., invalid file paths). For a tool with zero annotation coverage, this is insufficient.

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 with zero waste. It front-loads the core purpose and uses parentheses to clarify 'code actions' without redundancy. Every word earns its place, making it highly concise and well-structured.

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 no annotations and no output schema, the description is incomplete for a tool with 4 parameters and behavioral complexity. It lacks details on return values (e.g., format of listed actions), error handling, or operational constraints (e.g., file system access). This leaves significant gaps for an agent to invoke it correctly.

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%, so the schema already documents all parameters (filePath, startLine, endLine, kind) with clear descriptions. The description adds no additional parameter semantics beyond implying a line/range context, which is already covered by the schema. Baseline 3 is appropriate when the schema does the heavy lifting.

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 tool's purpose: 'List available code actions (quick fixes, refactorings) for a line or range in a file.' It specifies the verb ('List'), resource ('code actions'), and scope ('for a line or range in a file'), distinguishing it from siblings like apply_code_action or get_diagnostics. However, it doesn't explicitly differentiate from all siblings (e.g., find_definition), so it's not a perfect 5.

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, when not to use it, or compare it to sibling tools like apply_code_action (which applies actions) or get_diagnostics (which might list issues). This leaves the agent without context for tool selection.

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

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