Skip to main content
Glama
ts-mcp-server

ts-mcp-server

by AndyLiner13

Extract Function

extractFunction
Destructive

Extract a selected code range into a new function with automatic parameter and return type detection. Get rename locations for meaningful naming.

Instructions

Extract the selected code range into a new function. TypeScript auto-detects parameters and return type. The response includes renameFilename/renameLocation so you can follow up with rename_symbol to give the function a meaningful name.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "file": "<file>",
      "startLine": "<startLine>",
      "startOffset": "<startOffset>",
      "endLine": "<endLine>",
      "endOffset": "<endOffset>",
      "preview": "<preview>"
    },
    "name": "extractFunction"
  }
}

Input Schema

NameRequiredDescriptionDefault
fileYesFile path (absolute or relative to cwd)
endLineYes1-based end line
previewYesIf true, only preview changes
endOffsetYes1-based end character offset
startLineYes1-based start line
startOffsetYes1-based start character offset

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.1.1

TDQS

A4.2/5.0
Behavior4/5

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

Annotations already mark destructiveHint=true, but the description adds value by mentioning auto-detection of parameters and return type, and the response includes renameFilename/renameLocation for follow-up. This informs the agent about side effects and response structure.

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?

Two concise sentences: first states the primary action, second provides key follow-up information. No redundant or unnecessary words.

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?

For a tool with 6 required params and no output schema, the description covers the core action, behavioral notes, and follow-up steps. It could mention that the original code is replaced with a function call, but the destructive hint implies that.

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 coverage is 100% with descriptions for all 6 parameters. The description does not add additional semantics beyond what is already in the schema; it only reiterates the purpose in general terms.

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 verb 'Extract' and resource 'selected code range into a new function'. It distinguishes from sibling tools like extractConstant and extractType by specifying 'function'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides follow-up guidance to use rename_symbol for naming, which helps the agent understand the workflow. However, it does not explicitly contrast with other extraction tools or indicate when function extraction is preferred over constant/type extraction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.