Skip to main content
Glama
AndyLiner13

ts-mcp-server

by AndyLiner13

Map Code

mapCode
DestructiveIdempotent

Insert, replace, or append code snippets in files using name-based matching for functions, classes, and methods. Supports preview and file creation.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesFile path (absolute or relative to cwd)
previewYesIf true, return edits without applying them
contentsYesCode snippets to map into the file. Each is parsed independently. Functions/classes are matched by name.
focusLocationsNoRequired to enable name-based matching. Point anywhere in the file/block scope to search. Without this, code is always appended.
Behavior5/5

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

Annotations declare idempotentHint=true and destructiveHint=true. The description goes far beyond by detailing the exact matching algorithm (by name, only for certain node types), the behavior when match found vs. not found, the limitations of multiple contents entries, and the handling of non-existent files via a virtual buffer. There is no contradiction with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-organized with headings, bullet points, and an example. It front-loads the core purpose and then systematically covers matching, limitations, and usage patterns. While every sentence adds value, the length is slightly high for a tool description; a more streamlined version could achieve perfect conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (four parameters, intricate matching logic, multiple edge cases like non-existent files and const/var unsupported) and the absence of an output schema, the description thoroughly covers all essential aspects. It explains matching scope, replacement versus append, how to handle multiple declarations, and how to create new files, leaving no gaps for an AI agent to fill.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

All four parameters are described in the input schema with 100% coverage. The description adds crucial meaning: it explains that without focusLocations, code is always appended; it clarifies that the focusLocations parameter enables name-based matching within a scope; and it provides a concrete example showing how to use contents and focusLocations together. This elevates understanding beyond the raw schema.

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 opens with 'Map/insert/replace code snippets into a file. Designed for AI code generation workflows,' using a specific verb+resource and setting the tool apart. It also details how matching works and when to use alternatives, clearly distinguishing this tool from sibling tools like refactoring or completion services.

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

Usage Guidelines5/5

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

The description provides explicit usage patterns: REPLACE a function, ADD new code, CREATE a new file, and explicitly states what is NOT supported (matching const/let/var) and what to do instead ('use standard file editing'). It also recommends using preview=true to verify output and explains the multiple contents limitation. This leaves no ambiguity about when and how to invoke the tool.

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/AndyLiner13/ts-mcp-server'

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