Agent skill

Lsp Extract Function

by blackwell-systems in blackwell-systems/agent-lsp

Extract a selected code block into a named function. An agent skill from blackwell-systems/agent-lsp.

MITAuto-check passedAgent Workflows

Install Lsp Extract Function

skills CLI
$ npx skills add blackwell-systems/agent-lsp --skill lsp-extract-function -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install blackwell-systems/agent-lsp lsp-extract-function --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/blackwell-systems/agent-lsp.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/lsp-extract-function .claude/skills/lsp-extract-function && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
lsp-extract-function
GitHub stars
157
Token cost
~2k tokens
SKILL.md length
713 words
Files
2 (incl. references)
Skills in repo
24
Repo updated
First seen
Licence
MIT

At a glance

Extract a selected code block into a named function. An agent skill from blackwell-systems/agent-lsp.

  • Works in 5 steps: Get context (document symbols) → Check server capabilities → Primary path: LSP code action → …
  • Agent Workflows work in your project
  • SKILL.md covers Prerequisites, Step 1 — Get context (document…, Step 2 — Check server… and Step 3 — Primary path: LSP…, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Lsp Extract Function is an agent skill from blackwell-systems/agent-lsp. Extract a selected code block into a named function. Primary path uses the language server's extract-function code action; falls back to manual extraction when no code action is available. Validates captured variables, scope shadowing, and compilation after extraction.

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files, including reference files (for example `references/patterns.md`). Compatibility notes: Requires the agent-lsp MCP server (github.com/blackwell-systems/agent-lsp)

It sits in Agent Workflows. It works with Model Context Protocol. The repository describes itself as: MCP server that orchestrates language servers into agent-native workflows. 65 tools, 30 CI-verified languages. The licence is MIT.

When your agent uses it

  • Agent Workflows work in your project

Example prompts

  • “/lsp-extract-function”

Requirements

  • Python 3
  • Compatibility (from SKILL.md): Requires the agent-lsp MCP server (github.com/blackwell-systems/agent-lsp)
  • Pre-approved tools (allowed-tools): mcp__lsp__list_symbols, mcp__lsp__suggest_fixes, mcp__lsp__execute_command, mcp__lsp__apply_edit, mcp__lsp__get_diagnostics, mcp__lsp__open_document, mcp__lsp__format_document, mcp__lsp__get_server_capabilities

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Get context (document symbols)
  2. Check server capabilities
  3. Primary path: LSP code action
  4. Manual fallback
  5. Validate

What it can do on your machine

Read from SKILL.md and the folder at commit 09ea99e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • mcp__lsp__list_symbols
    • mcp__lsp__suggest_fixes
    • mcp__lsp__execute_command
    • mcp__lsp__apply_edit
    • mcp__lsp__get_diagnostics
    • mcp__lsp__open_document
    • mcp__lsp__format_document
    • mcp__lsp__get_server_capabilities

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Requires the agent-lsp MCP server (github.com/blackwell-systems/agent-lsp)

    From compatibility in the SKILL.md frontmatter.

Context cost

Lsp Extract Function loads about 2k tokens when it runs, and up to ~2.5k if it reads all its reference files. Until then it costs about 73 tokens; SKILL.md has 713 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~73
When it runs · the whole SKILL.md, loaded when a task matches
~2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~2.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from blackwell-systems/agent-lsp at commit 09ea99e, republished under its MIT licence (© blackwell-systems). 713 words, ~1,987 tokens.

Download SKILL.mdSave it as .claude/skills/lsp-extract-function/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
lsp-extract-function
description
Extract a selected code block into a named function. Primary path uses the language server's extract-function code action; falls back to manual extraction when no code action is available. Validates captured variables, scope shadowing, and compilation after extraction.
allowed-tools
mcp__lsp__list_symbols, mcp__lsp__suggest_fixes, mcp__lsp__execute_command, mcp__lsp__apply_edit, mcp__lsp__get_diagnostics, mcp__lsp__open_document, mcp__lsp__format_document, mcp__lsp__get_server_capabilities
compatibility
Requires the agent-lsp MCP server (github.com/blackwell-systems/agent-lsp)
argument-hint
[file-path] [start-line] [end-line] [new-function-name]
user-invocable
true
license
MIT
metadata.required-capabilities
codeActionProvider
metadata.optional-capabilities
documentFormattingProvider documentSymbolProvider

Requires the agent-lsp MCP server.

lsp-extract-function: Extract Code Block into a Named Function

This skill RESTRUCTURES existing code — it takes code that already exists and moves it into a new function. This is distinct from /lsp-generate, which creates NEW code that does not yet exist (stubs, mocks, interface implementations). Use this skill when the code is already written; use /lsp-generate when you need to generate code from scratch.

Invocation: User provides file_path (absolute path), start_line and end_line (1-indexed range), and new_function_name (desired name for the extracted function).


Prerequisites

If LSP is not yet initialized, call mcp__lsp__start_lsp with the workspace root first. Auto-inference applies when file paths are provided, but an explicit start is required when switching workspaces.


Step 1 — Get context (document symbols)

Call mcp__lsp__open_document to open the file, then call mcp__lsp__list_symbols to understand the containing function and scope:

mcp__lsp__open_document({ "file_path": "<file_path>" })
mcp__lsp__list_symbols({ "file_path": "<file_path>" })

This establishes:

  • Which function contains the selection
  • Whether new_function_name already exists in the file (name collision check)

Mandatory name collision check: If new_function_name already exists as a symbol in the document symbols list, report the conflict and stop immediately:

Cannot extract: function new_function_name already exists in this file. Choose a different name and retry.


Step 2 — Check server capabilities

Call mcp__lsp__get_server_capabilities to understand what the language server supports:

mcp__lsp__get_server_capabilities({})

Check for codeActionProvider in the response. Note whether execute_command is listed in executeCommandProvider.commands. This determines whether the primary path (Step 3) is available.


Step 3 — Primary path: LSP code action

Call mcp__lsp__suggest_fixes with the selection range:

mcp__lsp__suggest_fixes({
  "file_path": "<file_path>",
  "start_line": N,
  "start_column": 1,
  "end_line": M,
  "end_column": 999
})

Filter the returned actions for extract-function actions: include any action whose kind contains "refactor.extract" OR whose title contains both "Extract" and "function" (case-insensitive).

If an extract-function action is found:

  • Display the action title to the user
  • If the action proposes a different name than new_function_name, ask for confirmation before proceeding
  • Execute via mcp__lsp__execute_command if the action has a command field:
    mcp__lsp__execute_command({
      "command": "<action.command.command>",
      "arguments": <action.command.arguments>
    })
  • OR apply directly via mcp__lsp__apply_edit if the action has an edit field:
    mcp__lsp__apply_edit({ "workspace_edit": <action.edit> })
  • Skip to Step 5 after applying.

If no extract-function action is found: fall through to Step 4 (manual fallback).


Step 4 — Manual fallback

When no code action is available, perform manual extraction:

a) Analyze the selection

Read the selected lines (start_line through end_line) and identify:

  • Parameters: Variables used inside the selection that are declared outside (captured from outer scope — must become function parameters)
  • Return values: Variables declared inside the selection that are used outside (must be returned from the extracted function)
  • Early returns: Return statements inside the selection (the extracted function must wrap these)
b) Construct and confirm the proposed signature

Build the extracted function signature based on the captured variables analysis. Display the proposed signature to the user before writing:

Proposed extraction:

func new_function_name(param1 Type1, param2 Type2) (ReturnType, error) {
    // selected lines
}

Proceed with this signature? [y/n]

Wait for user confirmation before applying any edit.

Show full SKILL.md (292 more words)Show less
c) Apply the extraction (order matters)

Apply edits sequentially — do NOT batch edits from different line regions into a single apply_edit call:

  1. First: Replace the selected lines with a call to the new function:

    mcp__lsp__apply_edit({
      "workspace_edit": {
        "changes": {
          "<file_path>": [{
            "range": { "start": { "line": start_line-1, "character": 0 },
                       "end":   { "line": end_line,     "character": 0 } },
            "newText": "    result := new_function_name(args...)\n"
          }]
        }
      }
    })
  2. Second: Insert the new function definition after the containing function's closing brace:

    mcp__lsp__apply_edit({
      "workspace_edit": {
        "changes": {
          "<file_path>": [{
            "range": { "start": { "line": insert_line, "character": 0 },
                       "end":   { "line": insert_line, "character": 0 } },
            "newText": "\nfunc new_function_name(params) ReturnType {\n    ...\n}\n"
          }]
        }
      }
    })

Apply call-site replacement first, then insert the new function. This order preserves line numbers during editing: replacing call site does not shift the insertion point for the new function definition.


Step 5 — Validate

After extraction via either path:

1. Check diagnostics
mcp__lsp__get_diagnostics({ "file_path": "<file_path>" })

If errors are reported, display them with the table of common causes below.

2. Common post-extraction errors
Error typeLikely causeFix
Undefined variableCaptured var not passed as parameterAdd parameter
Type mismatchReturn type inferred incorrectlyAdjust return type in signature
Name shadows outerNew function name matches outer scopeChoose different name
Unused variableReturn value not captured at call siteAdd variable at call site
3. Format the document
mcp__lsp__format_document({ "file_path": "<file_path>" })

This cleans up indentation introduced by the extraction.


Output Format

After completing extraction, display:

## Extraction Summary
- File:           path/to/file.go
- Extracted:      lines N–M
- New function:   new_function_name
- Path used:      LSP code action / Manual fallback
- Post-extraction errors: 0

Follow with the Diagnostic Summary if any errors changed (format in references/patterns.md).


Language-Specific Notes

  • Go: gopls may offer "Extract function" in code actions for selection ranges. Check code actions first; gopls support varies by version.
  • TypeScript/JavaScript: typescript-language-server may offer "Extract to function in global scope" or "Extract to inner function" — filter for these titles in Step 3.
  • Python: pylsp and pyright-langserver typically do NOT offer extract-function code actions. Manual fallback (Step 4) is required for Python files.

© blackwell-systems, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file (references) in skills/lsp-extract-function of blackwell-systems/agent-lsp.

  • SKILL.md
  • references/patterns.md

Open the folder on GitHubat commit 09ea99e

Compare with similar skills

Lsp Extract Function next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Lsp Extract Function compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Lsp Extract Function this skillblackwell-systems/agent-lsp157—~2kAutomated safety check: PassMIT
MCP Server Builderanthropics/skills180k62 repos~2.3kAutomated safety check: PassApache-2.0
MCP Server BuildershareAI-lab/learn-claude-code78k5 repos~1.2kAutomated safety check: PassMIT
MCP Integration for Pluginsanthropics/claude-plugins-official37k11 repos~3.1kAutomated safety check: PassApache-2.0
Fastmcp Client CLIPrefectHQ/fastmcp28k1 repos~823Automated safety check: PassApache-2.0
MemPalace Memory SearchMemPalace/mempalace59k—~1.4kAutomated safety check: PassMIT

Similar skills

  • MCP Server Builder

    anthropics/skills

    Official

    Guides the design and implementation of Model Context Protocol servers in TypeScript or Python, from tool naming and error messages to evaluation.

    180k GitHub starsUsed in 62 repos~2.3k tokens
    Agent WorkflowsAuto-check passed
  • MCP Server Builder

    shareAI-lab/learn-claude-code

    Walks through building MCP servers in Python or TypeScript that expose tools, resources and prompts to Claude, with templates, registration and testing.

    78k GitHub starsUsed in 5 repos~1.2k tokens
    Agent WorkflowsAuto-check passed
  • MCP Integration for Plugins

    anthropics/claude-plugins-official

    Official

    Explains how to bundle Model Context Protocol servers in a Claude Code plugin, covering config files, stdio, SSE, HTTP and WebSocket server types, and authentication.

    37k GitHub starsUsed in 11 repos~3.1k tokens
    Agent WorkflowsAuto-check passed
  • Fastmcp Client CLI

    PrefectHQ/fastmcp

    Query and invoke tools on MCP servers using fastmcp list and fastmcp call.

    28k GitHub starsUsed in 1 repo~823 tokens
    Agent WorkflowsAuto-check passed
  • MemPalace Memory Search

    MemPalace/mempalace

    Mines project files and conversation exports into a local, searchable memory palace and recalls past work by semantic search through the mempalace CLI.

    59k GitHub stars~1.4k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed
  • Crush Configuration

    charmbracelet/crush

    Explains how to configure the Crush coding agent with crushrc or crush.json, covering providers, models, LSPs, MCP servers, hooks, permissions and config precedence.

    29k GitHub stars~3.7k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed

More from blackwell-systems/agent-lsp

All 24 skills in this repo
  • Lsp Dead Code

    blackwell-systems/agent-lsp

    Enumerate exported symbols in a file and surface those with zero references across the workspace.

    157 GitHub stars~2.4k tokensUpdated today
    Auto-check passed
  • Lsp Edit Export

    blackwell-systems/agent-lsp

    Safe workflow for editing exported symbols or public APIs. An agent skill from blackwell-systems/agent-lsp.

    157 GitHub stars~1.9k tokensUpdated today
    Auto-check passed
  • Lsp Fix All

    blackwell-systems/agent-lsp

    Apply available quick-fix code actions for all current diagnostics in a file, one at a time with re-collection between each fix.

    157 GitHub stars~1.6k tokensUpdated today
    Auto-check passed
  • Lsp Generate

    blackwell-systems/agent-lsp

    Trigger language server code generation — implement interface stubs, generate test skeletons, add missing methods, generate mock types.

    157 GitHub stars~1.4k tokensUpdated today
    Auto-check passed
  • Lsp Impact

    blackwell-systems/agent-lsp

    Blast-radius analysis for a symbol or file — shows all callers, type supertypes/subtypes, and reference count before you change it.

    157 GitHub stars~1.8k tokensUpdated today
    Auto-check passed
  • Lsp Rename

    blackwell-systems/agent-lsp

    Two-phase safe rename across the entire workspace. An agent skill from blackwell-systems/agent-lsp.

    157 GitHub stars~1.9k tokensUpdated today
    Auto-check passed

Categories

Questions about Lsp Extract Function

What does Lsp Extract Function do?

Extract a selected code block into a named function. An agent skill from blackwell-systems/agent-lsp. Lsp Extract Function is an agent skill from blackwell-systems/agent-lsp. Extract a selected code block into a named function.

When should I use Lsp Extract Function?

Lsp Extract Function fits situations like: agent Workflows work in your project.

How do I install Lsp Extract Function in Claude Code?

Run `npx skills add blackwell-systems/agent-lsp --skill lsp-extract-function -a claude-code`. Or copy the skill folder (skills/lsp-extract-function in blackwell-systems/agent-lsp) into .claude/skills/lsp-extract-function in your project. Claude Code loads it when a task matches its description.

How do I install Lsp Extract Function in Codex?

Run `npx skills add blackwell-systems/agent-lsp --skill lsp-extract-function -a codex`. Or copy the skill folder (skills/lsp-extract-function in blackwell-systems/agent-lsp) into .agents/skills/lsp-extract-function in your project. Codex loads it when a task matches its description.

Can I use Lsp Extract Function in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add blackwell-systems/agent-lsp --skill lsp-extract-function -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/lsp-extract-function, .gemini/skills/lsp-extract-function, .github/skills/lsp-extract-function and .opencode/skills/lsp-extract-function in your project.

What does Lsp Extract Function need to run?

SKILL.md names no scripts, command-line tools or credentials: Lsp Extract Function is instructions for the agent only. Our summary lists: Python 3. Its frontmatter pre-approves these tools: mcp__lsp__list_symbols, mcp__lsp__suggest_fixes, mcp__lsp__execute_command, mcp__lsp__apply_edit, mcp__lsp__get_diagnostics, mcp__lsp__open_document, mcp__lsp__format_document, mcp__lsp__get_server_capabilities. Compatibility (from SKILL.md): Requires the agent-lsp MCP server (github.com/blackwell-systems/agent-lsp).

Does Lsp Extract Function access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Lsp Extract Function safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Lsp Extract Function use?

Lsp Extract Function is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Lsp Extract Function use?

About 2k tokens (SKILL.md is roughly 7.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 499 tokens, read only when the agent opens those files.

What are the alternatives to Lsp Extract Function?

Skills that share tags, products or a category with Lsp Extract Function: MCP Server Builder (anthropics/skills, 180k stars), MCP Server Builder (shareAI-lab/learn-claude-code, 78k stars), MCP Integration for Plugins (anthropics/claude-plugins-official, 37k stars) and Fastmcp Client CLI (PrefectHQ/fastmcp, 28k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Lsp Extract Function?

blackwell-systems (a GitHub user) maintains it in blackwell-systems/agent-lsp, which has 157 GitHub stars. The repository holds 24 skills in this directory. The repository was last updated on October 7, 2026.

Source: blackwell-systems/agent-lsp on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.