Skip to main content
Glama

extract-lines

Extract a specific range of lines from text content while preserving exact formatting and newlines for focused analysis or sharing.

Instructions

Extract a specific range of lines from text content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe full text content to extract lines from
start_lineYesStarting line number (inclusive)
end_lineYesEnding line number (inclusive)

Implementation Reference

  • The handler function that implements the extract-lines tool logic: validates input line numbers, splits text into lines, extracts the specified range, and returns the result or an error.
    async ({ text, start_line, end_line }) => {
        try {
            // Validate line numbers
            if (start_line > end_line) {
                return {
                    isError: true,
                    content: [
                        {
                            type: "text",
                            text: `Error: Start line (${start_line}) cannot be greater than end line (${end_line}).`,
                        },
                    ],
                };
            }
    
            // Split the text into lines
            const allLines = text.split('\n');
            
            // Validate that requested lines are within range
            if (start_line > allLines.length) {
                return {
                    isError: true,
                    content: [
                        {
                            type: "text",
                            text: `Error: Start line (${start_line}) exceeds the total number of lines (${allLines.length}).`,
                        },
                    ],
                };
            }
    
            // Extract the requested lines (adjusting for 0-based array indexing)
            const extractedLines = allLines.slice(
                start_line - 1, 
                Math.min(end_line, allLines.length)
            );
    
            // Return the extracted lines
            return {
                content: [
                    {
                        type: "text",
                        text: extractedLines.join('\n'),
                    },
                ],
            };
        } catch (error: unknown) {
            const errorMessage = error instanceof Error ? error.message : String(error);
            return {
                isError: true,
                content: [
                    {
                        type: "text",
                        text: `Error extracting lines: ${errorMessage}`,
                    },
                ],
            };
        }
    }
  • Zod schema for the tool's input parameters: text (string), start_line (integer >=1), end_line (integer).
        text: z.string().describe("The full text content to extract lines from"),
        start_line: z.number().int().min(1).describe("Starting line number (inclusive)"),
        end_line: z.number().int().describe("Ending line number (inclusive)"),
    },
  • src/index.ts:13-79 (registration)
    Registration of the 'extract-lines' tool on the MCP server, specifying name, description, input schema, and handler function.
        "extract-lines",
        "Extract a specific range of lines from text content",
        {
            text: z.string().describe("The full text content to extract lines from"),
            start_line: z.number().int().min(1).describe("Starting line number (inclusive)"),
            end_line: z.number().int().describe("Ending line number (inclusive)"),
        },
        async ({ text, start_line, end_line }) => {
            try {
                // Validate line numbers
                if (start_line > end_line) {
                    return {
                        isError: true,
                        content: [
                            {
                                type: "text",
                                text: `Error: Start line (${start_line}) cannot be greater than end line (${end_line}).`,
                            },
                        ],
                    };
                }
    
                // Split the text into lines
                const allLines = text.split('\n');
                
                // Validate that requested lines are within range
                if (start_line > allLines.length) {
                    return {
                        isError: true,
                        content: [
                            {
                                type: "text",
                                text: `Error: Start line (${start_line}) exceeds the total number of lines (${allLines.length}).`,
                            },
                        ],
                    };
                }
    
                // Extract the requested lines (adjusting for 0-based array indexing)
                const extractedLines = allLines.slice(
                    start_line - 1, 
                    Math.min(end_line, allLines.length)
                );
    
                // Return the extracted lines
                return {
                    content: [
                        {
                            type: "text",
                            text: extractedLines.join('\n'),
                        },
                    ],
                };
            } catch (error: unknown) {
                const errorMessage = error instanceof Error ? error.message : String(error);
                return {
                    isError: true,
                    content: [
                        {
                            type: "text",
                            text: `Error extracting lines: ${errorMessage}`,
                        },
                    ],
                };
            }
        }
    );
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 mentions the extraction action but doesn't describe what happens with invalid inputs (e.g., start_line > end_line), whether the operation is read-only or has side effects, error handling, or output format. This leaves significant behavioral gaps for an agent.

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 wasted words. It's appropriately sized for this simple tool and front-loads the core functionality clearly.

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

Completeness3/5

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

For a simple text processing tool with no annotations, no output schema, and 100% schema coverage, the description is minimally adequate. It covers the basic purpose but lacks behavioral details and usage context that would help an agent use it correctly in practice.

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?

The schema description coverage is 100%, with all three parameters well-documented in the schema. The description adds no additional parameter semantics beyond implying a range operation. This meets the baseline of 3 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 with a specific verb ('extract') and resource ('lines from text content'), and specifies the scope ('a specific range'). It doesn't need sibling differentiation since there are no sibling tools. However, it could be slightly more specific about what 'extract' means operationally.

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, prerequisites, or constraints. It simply states what the tool does without context about appropriate use cases or limitations.

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/ananddtyagi/copy-paste-mcp'

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