# ts-mcp-server [Health: Active]

**Category:** 💻 Developer Tools  
**Repository:** https://github.com/AndyLiner13/ts-mcp-server  
**GitHub Stars:** 4  
**Views:** 2  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/ts-mcp-server

## Description
MCP server that renames/moves TypeScript files and updates all imports via tsserver

## Tools
Capabilities this server exposes over MCP:

- **getEditsForFileRename** — Rename or move a TypeScript/JavaScript file OR folder and automatically update all import paths across the project. Supports .ts, .tsx, .js, .jsx. tsserver auto-discovers the relevant tsconfig.json. For folders, all imports referencing files inside the folder are updated.
- **rename** — Rename a TypeScript/JavaScript symbol (variable, function, class, type, property, etc.) and update all references across the project. Provide the file path and the 1-based line/offset of any occurrence of the symbol.
- **getDiagnostics** — Get all errors, warnings, and suggestions for a TypeScript/JavaScript file. Reports type errors, unused variables, unused imports, unreachable code, and more. Requires the file to be part of a tsconfig.json project. Unused-code diagnostics only appear if tsconfig has noUnusedLocals/noUnusedParameters enabled.
- **references** — Find all usages of a symbol across the project. Provide the file path and 1-based line/offset of any occurrence of the symbol. Returns references grouped by file with line text for context.
- **organizeImports** — Sort, coalesce, and remove unused imports in a TypeScript/JavaScript file. Uses TypeScript's native organizeImports with mode 'All' (sorts, coalesces, and removes unused). Requires the file to be part of a tsconfig.json project.
- **getCodeFixes** — Get available code fixes for specific error codes at a range in a TypeScript/JavaScript file. Returns the raw list of code actions tsserver suggests for the given diagnostics. Use getDiagnostics first to discover error codes and ranges, then pass them here.
- **extractFunction** — 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.
- **extractConstant** — Extract the selected expression into a named constant. TypeScript infers the type. The response includes renameFilename/renameLocation so you can follow up with rename_symbol to give the constant a meaningful name.
- **moveSymbol** — Move top-level declarations (functions, classes, types, constants) to another file. Automatically rewires all imports across the project. If the target file does not exist, tsserver creates it.
- **inlineVariable** — Inline a variable — replace all references with the variable's initializer and delete the declaration. Position must be on the variable name in its declaration or any usage.
- **extractType** — Extract an inline type annotation into a named type alias. Select the type span to extract. The response includes renameFilename/renameLocation so you can follow up with rename_symbol to give the type a meaningful name.
- **inferReturnType** — Add an explicit return type annotation to a function, inferred by TypeScript. Position must be on the function name or declaration keyword.
- **quickinfo** — Get type information, documentation, and JSDoc tags for a symbol at a position. Returns the hover info — kind, display string (full type signature), documentation, and tags.
- **navtree** — Get the complete hierarchical structure of a file — all classes, functions, variables, interfaces, type aliases, enums, and their nesting. Returns kind, name, spans, and child items for every declaration.
- **definition** — Returns the file location(s) where a symbol is defined. The fundamental 'where is this thing declared?' query.
- **navto** — Workspace-wide symbol search by name. Takes a search string and returns matching symbols across all project files with their locations and kinds.
- **fileReferences** — Finds every file that imports or references a given file. The reverse dependency graph for a single file.
- **prepareCallHierarchy** — Returns the call hierarchy item(s) at a position — the entry point for call hierarchy queries. Returns the function/method name, kind, file location, and spans.
- **provideCallHierarchyIncomingCalls** — Returns all functions/methods that call the function at the given position. Answers 'who calls this?'
- **provideCallHierarchyOutgoingCalls** — Returns all functions/methods that the function at the given position calls. Answers 'what does this call?'
- **typeDefinition** — Navigates to the type's definition, not the variable's declaration. Given `const user: UserProfile = ...`, `definition` goes to the variable, but `typeDefinition` goes to the `UserProfile` interface.
- **implementation** — Finds concrete implementations of an interface or abstract class. Given an interface `Serializable`, returns every class that implements it.
- **projectInfo** — Returns the tsconfig.json path, the full list of files in the project, and whether the language service is active.
- **completionInfo** — Get autocomplete suggestions at a position. Returns all possible completions
with their kinds, sort text, and insert text. Useful for understanding what
symbols, methods, or properties are available at a specific location in code.
- **completionEntryDetails** — Get full details for specific completion entries. Follow-up to completion_info
for richer information including documentation, full type signature, JSDoc tags,
and code actions (like auto-imports). Can request details for multiple entries at once.
- **signatureHelp** — Get function/method signature information at a call site. Returns parameter names,
types, and documentation for each overload. Use when the cursor is inside function
call parentheses to understand what arguments are expected.
- **documentHighlights** — Find all occurrences of a symbol within a file (or set of files). Distinguishes
between read and write references. More efficient than find_all_references when
you only need local occurrences within specific files.
- **getApplicableRefactors** — Discover what refactorings are available at a position or selection. Use before
attempting a refactor to see what's possible. Returns a list of available refactors
with their actions, descriptions, and any reasons why certain actions may not apply.
- **docCommentTemplate** — Generate a JSDoc comment template for a function, method, or class at a position.
Returns the template text with @param, @returns, etc. based on the function signature.
The returned text can be inserted above the function declaration.
- **getOutliningSpans** — Get code folding regions for a file. Returns the hierarchical structure of code blocks
including their kinds (comment, region, code, imports). Useful for understanding file
structure, complexity, and navigating large files.
- **provideInlayHints** — Get inlay hints (inline type annotations) for a range. Shows inferred types,
parameter names at call sites, and return types. Useful for understanding what
TypeScript infers without explicit type annotations.
- **getCombinedCodeFix** — Get a combined code fix that applies all instances of a fix across a file in one action.
For example, "Add all missing imports" or "Remove all unused variables". Returns the full set
of file edits as a CombinedCodeActions response. Use getCodeFixes first to discover available
fixId values, then pass the fixId here to get the combined fix for the whole file.
- **todoComments** — Find all TODO, FIXME, HACK, and other configured comment markers in a file.
Returns the location and text of each matching comment. You must provide the
descriptors array specifying which markers to search for.
- **definitionAndBoundSpan** — Like 'definition', but also returns the span of the symbol at the cursor.
Useful for understanding exactly which characters constitute the symbol being queried.
Returns both the definition locations and the textSpan of the queried symbol.
- **findSourceDefinition** — Navigate to the actual TypeScript source instead of .d.ts declaration files.
Useful when working with libraries that have source maps or when you want to see
the implementation rather than just the type declarations.
- **selectionRange** — Get semantically meaningful selection ranges for smart expand/shrink selection.
Returns nested spans that represent progressively larger syntactic constructs.
Useful for structural code selection (e.g., select expression → statement → block → function).
- **format** — Format a range of code according to TypeScript's formatting rules.
Applies consistent indentation, spacing, and line breaks. Specify a range
or use the full file length to format the entire file.
- **getMoveToRefactoringFileSuggestions** — Get suggested target files when moving a symbol to another file.
Returns both a suggested new file name and existing files that would be good
destinations. Use this before moveSymbol to choose the best target location.
- **getSupportedCodeFixes** — Returns the list of all error codes that have available code fixes. Use this as a discovery tool before calling getCodeFixes — it tells you which error codes tsserver can automatically fix. A file path must be provided to establish a project context; omitting it will cause tsserver to throw 'No Project'.
- **mapCode** — Map/insert/replace code snippets into a file. Designed for AI code generation workflows.

How matching works:
1. Without focusLocations → code is ALWAYS appended to end of file (no matching attempted)
2. With focusLocations → TypeScript searches for matching declarations by NAME in the scope
3. Matching works for: functions, classes, methods, interfaces (nodes with a 'name' property)
4. Matching does NOT work for: const/let/var declarations (VariableStatement has no name)

When a match is found:
- The range from first matching statement to last matching statement is REPLACED with new code

When no match is found:
- Code is appended to the end of the scope (file or block)

Multiple contents limitation:
- When providing multiple contents entries, only the FIRST entry's match is applied
- To replace multiple named declarations, call mapCode once per declaration

Non-existent files:
- tsserver opens a virtual file buffer for paths that don't exist on disk
- Edits are returned and written as if the file exists, effectively creating it
- Use preview=true first to verify the output before writing a new file

Usage patterns:
- REPLACE a function: provide contents with same function name + focusLocations anywhere in file
- ADD new code: omit focusLocations (always appends to end)
- REPLACE const/var: NOT SUPPORTED by mapCode — use standard file editing instead
- REPLACE multiple declarations: call mapCode separately for each one
- CREATE a new file: provide the desired path and contents without focusLocations

Example - replacing function 'calculate' (focusLocations just needs to be in the file scope):
  contents: ["export function calculate(x: number) { return x * 2; }"]
  focusLocations: [[{ start: { line: 1, offset: 1 }, end: { line: 1, offset: 1 } }]]

Set preview=true to see edits without applying them.

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `npx` (confidence: high):

```json
"mcpServers": {
  "ts-mcp-server": {
    "command": "npx",
    "args": ["-y","ts-mcp-server"]
  }
}
```

## Documentation

## What ts-mcp-server does

ts-mcp-server exposes TypeScript language-service operations through MCP. Its tools cover both source changes and code intelligence, with each operation corresponding to a tsserver protocol command. Refactoring capabilities include renaming symbols, moving or renaming files and directories, organizing imports, formatting code, extracting functions, constants, and types, inferring return types, moving symbols, and inlining variables.

The server also supports analysis and navigation. Agents can inspect semantic and suggestion diagnostics, find references, look up definitions and implementations, search workspace symbols, inspect file references, explore call hierarchies, request completion details, view signature help, generate documentation comment templates, and find TODO-style comments.

## How it works

The MCP layer communicates with TypeScript's tsserver over Node IPC. Tool inputs are passed to the corresponding tsserver command, and the resulting response is returned as JSON without additional formatting, grouping, or filtering. This preserves TypeScript's native response structure for clients that need exact language-service data.

Project discovery detects `tsconfig.json` automatically. Monorepos, project references, and composite builds are supported, allowing operations to work across multi-project workspaces. Refactoring operations can use preview mode to inspect the proposed changes before applying them. File and symbol changes can update references, imports, `require` paths, and re-exports throughout the project.

## Tools and capabilities

The documented tool set includes:

- `rename` for symbols and their project-wide references.
- `renameFileOrDirectory` for moving or renaming files and directories while updating import paths.
- `references` for locating symbol usages.
- `getDiagnostics` for separate semantic and suggestion diagnostic results.
- `organizeImports` for sorting, combining, and removing unused imports.
- `getCodeFixes` for retrieving fixes for selected diagnostic codes and ranges.
- Refactoring tools for extraction, inlining, return-type inference, symbol movement, formatting, and mapping generated code into a file.
- Code-intelligence tools for definitions, type definitions, implementations, completions, navigation trees, project information, call hierarchy, inlay hints, and workspace symbol search.

Use `getDiagnostics` before `getCodeFixes` to obtain the error codes and source ranges needed by the code-fix request.

## Limitations and notes

Responses are raw tsserver results, so the MCP client must interpret TypeScript's response shapes and text spans. The server is intended for TypeScript and JavaScript workspaces and relies on TypeScript project discovery through `tsconfig.json`. It runs on Windows, macOS, and Linux.

_Full upstream README: https://allmcps.com/mcp/ts-mcp-server/readme_

