We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/oakenai/mcp-edit-file-lines'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
import fs from "fs/promises";
import { normalizeLineEndings } from "./utils.js";
export async function getLineInfo(
filePath: string,
lineNumbers: number[],
context: number = 0
): Promise<string> {
const content = await fs.readFile(filePath, "utf-8");
const lines = normalizeLineEndings(content).split("\n");
const result: string[] = [];
const uniqueLineNumbers = [...new Set(lineNumbers)].sort((a, b) => a - b);
for (const lineNum of uniqueLineNumbers) {
const lineIndex = lineNum - 1;
if (lineIndex < 0 || lineIndex >= lines.length) {
result.push(
`Line ${lineNum}: Invalid line number (file has ${lines.length} lines)`
);
continue;
}
const startLine = Math.max(0, lineIndex - context);
const endLine = Math.min(lines.length - 1, lineIndex + context);
result.push(`Line ${lineNum}:`);
for (let i = startLine; i <= endLine; i++) {
const prefix = i === lineIndex ? ">" : " ";
result.push(`${prefix} ${i + 1}: ${lines[i]}`);
}
result.push("");
}
return result.join("\n");
}