linkbrief-mcp 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +390 -0
- package/README.md +266 -187
- package/browser.mjs +7 -1
- package/office.mjs +155 -0
- package/package.json +22 -5
- package/page.mjs +324 -37
- package/robots.mjs +48 -0
- package/server.mjs +4 -58
- package/sites.mjs +141 -2
- package/tools.mjs +101 -0
package/browser.mjs
CHANGED
|
@@ -47,7 +47,13 @@ async function renderNow(url, checkUrl) {
|
|
|
47
47
|
throw new Error("JavaScript rendering needs the optional puppeteer-core package (npm install puppeteer-core).");
|
|
48
48
|
}
|
|
49
49
|
const userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "linkbrief-")); // fresh profile: no cookies or logins
|
|
50
|
-
const
|
|
50
|
+
const args = ["--no-first-run", "--no-default-browser-check", "--lang=ko-KR"];
|
|
51
|
+
// Same proxy as plain requests (see page.mjs); Chrome takes NO_PROXY as a semicolon list.
|
|
52
|
+
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
|
53
|
+
const noProxy = process.env.NO_PROXY || process.env.no_proxy;
|
|
54
|
+
if (proxy) args.push(`--proxy-server=${proxy}`);
|
|
55
|
+
if (proxy && noProxy) args.push(`--proxy-bypass-list=${noProxy.split(",").map((s) => s.trim()).filter(Boolean).join(";")}`);
|
|
56
|
+
const browser = await puppeteer.launch({ executablePath, headless: true, userDataDir, args });
|
|
51
57
|
try {
|
|
52
58
|
const page = await browser.newPage();
|
|
53
59
|
await page.setRequestInterception(true);
|
package/office.mjs
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Office documents from links: .docx, .pptx, .xlsx and .hwpx (Hangul). All are ZIP files of XML;
|
|
2
|
+
// only the XML parts that hold text are unpacked. Binary .hwp is reported as unsupported.
|
|
3
|
+
import { strFromU8, unzipSync } from "fflate";
|
|
4
|
+
|
|
5
|
+
const TYPES = {
|
|
6
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
7
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
|
|
8
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
9
|
+
"application/hwp+zip": "hwpx",
|
|
10
|
+
"application/vnd.hancom.hwpx": "hwpx",
|
|
11
|
+
"application/x-hwp": "hwp",
|
|
12
|
+
"application/haansofthwp": "hwp",
|
|
13
|
+
"application/vnd.hancom.hwp": "hwp",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Document kind from the Content-Type, or from the file extension when the server sends a generic type.
|
|
17
|
+
export function officeKind(type, url) {
|
|
18
|
+
const t = (type || "").split(";")[0].trim().toLowerCase();
|
|
19
|
+
if (TYPES[t]) return TYPES[t];
|
|
20
|
+
if (t && !/^(application\/(octet-stream|zip|x-zip-compressed|download|force-download)|binary\/octet-stream)$/.test(t)) return null;
|
|
21
|
+
return /\.(docx|pptx|xlsx|hwpx|hwp)$/i.exec(new URL(url).pathname)?.[1].toLowerCase() ?? null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const MAX_UNPACKED = 60 * 1024 * 1024;
|
|
25
|
+
const WANTED = /^(word\/document\.xml|ppt\/slides\/slide\d+\.xml|xl\/(workbook\.xml|sharedStrings\.xml|styles\.xml|worksheets\/sheet\d+\.xml|_rels\/workbook\.xml\.rels)|docProps\/core\.xml|Contents\/section\d+\.xml)$/;
|
|
26
|
+
|
|
27
|
+
// Unpacks only the XML parts we read, refusing archives that declare more than MAX_UNPACKED.
|
|
28
|
+
// shortcut: trusts the sizes declared in the ZIP headers; switch to streaming inflate with a running cap if hostile files become a concern.
|
|
29
|
+
function unpack(bytes) {
|
|
30
|
+
let total = 0;
|
|
31
|
+
const files = unzipSync(new Uint8Array(bytes), {
|
|
32
|
+
filter: (f) => {
|
|
33
|
+
if (!WANTED.test(f.name)) return false;
|
|
34
|
+
total += f.originalSize;
|
|
35
|
+
if (total > MAX_UNPACKED) throw new Error("Document unpacks to more than 60 MB; not read");
|
|
36
|
+
return true;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return Object.fromEntries(Object.entries(files).map(([k, v]) => [k, strFromU8(v)]));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const unxml = (s) => s
|
|
43
|
+
.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'")
|
|
44
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, h) => String.fromCodePoint(parseInt(h, 16)))
|
|
45
|
+
.replace(/&#(\d+);/g, (_, d) => String.fromCodePoint(Number(d)))
|
|
46
|
+
.replace(/&/g, "&");
|
|
47
|
+
const texts = (xml, tag) => [...xml.matchAll(new RegExp(`<${tag}(?:\\s[^>]*)?>([^<]*)</${tag}>`, "g"))].map((m) => unxml(m[1])).join("");
|
|
48
|
+
const byNumber = (prefix, files) => Object.keys(files).filter((k) => k.startsWith(prefix)).sort((a, b) => Number(/(\d+)\.xml$/.exec(a)[1]) - Number(/(\d+)\.xml$/.exec(b)[1]));
|
|
49
|
+
const cell = (s) => s.replace(/\s+/g, " ").replace(/\|/g, "\\|").trim();
|
|
50
|
+
const table = (rows) => {
|
|
51
|
+
const width = Math.max(...rows.map((r) => r.length));
|
|
52
|
+
const line = (r) => `| ${Array.from({ length: width }, (_, i) => cell(r[i] ?? "")).join(" | ")} |`;
|
|
53
|
+
return [line(rows[0]), line(Array(width).fill("---")), ...rows.slice(1).map(line)].join("\n");
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function docx(files) {
|
|
57
|
+
const body = files["word/document.xml"] || "";
|
|
58
|
+
const out = [];
|
|
59
|
+
// Top-level paragraphs and tables in document order.
|
|
60
|
+
for (const [block] of body.matchAll(/<w:tbl>[\s\S]*?<\/w:tbl>|<w:p[ >][\s\S]*?<\/w:p>|<w:p\/>/g)) {
|
|
61
|
+
if (block.startsWith("<w:tbl>")) {
|
|
62
|
+
const rows = [...block.matchAll(/<w:tr[ >][\s\S]*?<\/w:tr>/g)].map(([tr]) => [...tr.matchAll(/<w:tc[ >][\s\S]*?<\/w:tc>/g)].map(([tc]) => texts(tc, "w:t")));
|
|
63
|
+
if (rows.length) out.push(table(rows));
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const text = texts(block.replace(/<w:tab\/>/g, "<w:t>\t</w:t>").replace(/<w:br\/>/g, "<w:t>\n</w:t>"), "w:t").trim();
|
|
67
|
+
if (!text) continue;
|
|
68
|
+
const style = /<w:pStyle w:val="([^"]+)"/.exec(block)?.[1] || "";
|
|
69
|
+
const level = /^title$/i.test(style) ? 1 : Number(/^heading\s?(\d)$/i.exec(style)?.[1] || 0);
|
|
70
|
+
out.push(level ? `${"#".repeat(Math.min(level + 1, 6))} ${text}` : text);
|
|
71
|
+
}
|
|
72
|
+
return out.join("\n\n");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function pptx(files) {
|
|
76
|
+
return byNumber("ppt/slides/slide", files).map((name, i) => {
|
|
77
|
+
const paras = [...files[name].matchAll(/<a:p>[\s\S]*?<\/a:p>/g)].map(([p]) => texts(p, "a:t").trim()).filter(Boolean);
|
|
78
|
+
return `## Slide ${i + 1}\n\n${paras.join("\n\n")}`;
|
|
79
|
+
}).join("\n\n");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const MAX_ROWS = 200;
|
|
83
|
+
const MAX_COLS = 50;
|
|
84
|
+
|
|
85
|
+
// Excel stores dates as day counts; a cell whose number format is a date or time is shown as ISO text.
|
|
86
|
+
// Built-in format ids for dates/times (including the CJK locale ones 27-36 and 50-58).
|
|
87
|
+
const BUILTIN_DATE = new Set([14, 15, 16, 17, 22, 27, 28, 29, 30, 31, 34, 35, 36, 50, 51, 52, 53, 54, 57, 58]);
|
|
88
|
+
const BUILTIN_TIME = new Set([18, 19, 20, 21, 32, 33, 45, 46, 47, 55, 56]);
|
|
89
|
+
// Per cell style index (the "s" attribute): "date", "datetime", "time" or undefined.
|
|
90
|
+
function dateStyles(stylesXml) {
|
|
91
|
+
const custom = Object.fromEntries([...stylesXml.matchAll(/<numFmt [^>]*numFmtId="(\d+)"[^>]*formatCode="([^"]*)"/g)].map(([, id, code]) => [id, unxml(code)]));
|
|
92
|
+
const xfs = /<cellXfs[^>]*>([\s\S]*?)<\/cellXfs>/.exec(stylesXml)?.[1] || "";
|
|
93
|
+
return [...xfs.matchAll(/<xf [^>]*?numFmtId="(\d+)"/g)].map(([, id]) => {
|
|
94
|
+
if (BUILTIN_DATE.has(Number(id))) return Number(id) === 22 ? "datetime" : "date";
|
|
95
|
+
if (BUILTIN_TIME.has(Number(id))) return "time";
|
|
96
|
+
const code = (custom[id] || "").replace(/"[^"]*"|\[[^\]]*\]|\\./g, ""); // drop literals, colours, locales
|
|
97
|
+
if (/[dy]/i.test(code)) return /h/i.test(code) ? "datetime" : "date";
|
|
98
|
+
if (/h/i.test(code)) return "time";
|
|
99
|
+
return undefined;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// shortcut: ignores Excel's 1900 leap-year bug, so serials before 1900-03-01 are one day off; such dates are rare in practice.
|
|
103
|
+
function excelDate(value, kind, date1904) {
|
|
104
|
+
const n = Number(value);
|
|
105
|
+
if (!Number.isFinite(n)) return value;
|
|
106
|
+
const iso = new Date(Date.UTC(1899, 11, 30) + Math.round((n + (date1904 ? 1462 : 0)) * 86400000)).toISOString();
|
|
107
|
+
return kind === "time" ? iso.slice(11, 16) : kind === "datetime" ? `${iso.slice(0, 10)} ${iso.slice(11, 16)}` : iso.slice(0, 10);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function xlsx(files) {
|
|
111
|
+
const styles = dateStyles(files["xl/styles.xml"] || "");
|
|
112
|
+
const date1904 = /date1904="(1|true)"/.test(files["xl/workbook.xml"] || "");
|
|
113
|
+
const shared = [...(files["xl/sharedStrings.xml"] || "").matchAll(/<si>([\s\S]*?)<\/si>/g)].map(([, si]) => texts(si, "t"));
|
|
114
|
+
const rels = Object.fromEntries([...(files["xl/_rels/workbook.xml.rels"] || "").matchAll(/<Relationship [^>]*Id="([^"]+)"[^>]*Target="([^"]+)"/g)].map(([, id, t]) => [id, `xl/${t.replace(/^\/?xl\//, "")}`]));
|
|
115
|
+
const sheets = [...(files["xl/workbook.xml"] || "").matchAll(/<sheet [^>]*name="([^"]+)"[^>]*r:id="([^"]+)"/g)].map(([, name, id]) => ({ name: unxml(name), file: rels[id] }));
|
|
116
|
+
const col = (ref) => [...ref.replace(/\d+/g, "")].reduce((n, ch) => n * 26 + ch.charCodeAt(0) - 64, 0) - 1;
|
|
117
|
+
return sheets.filter((s) => files[s.file]).map((s) => {
|
|
118
|
+
const rows = [...files[s.file].matchAll(/<row [^>]*>([\s\S]*?)<\/row>/g)].map(([, row]) => {
|
|
119
|
+
const values = [];
|
|
120
|
+
for (const [, attrs, inner] of row.matchAll(/<c ([^>]*?)(?:\/>|>([\s\S]*?)<\/c>)/g)) {
|
|
121
|
+
const ref = /r="([A-Z]+)\d+"/.exec(attrs)?.[1];
|
|
122
|
+
const kind = /t="(\w+)"/.exec(attrs)?.[1];
|
|
123
|
+
const v = /<v>([^<]*)<\/v>/.exec(inner || "")?.[1];
|
|
124
|
+
const dateKind = !kind || kind === "n" ? styles[Number(/\bs="(\d+)"/.exec(attrs)?.[1])] : undefined;
|
|
125
|
+
values[ref ? col(ref) : values.length] = kind === "s" ? shared[Number(v)] ?? ""
|
|
126
|
+
: kind === "inlineStr" ? texts(inner || "", "t")
|
|
127
|
+
: dateKind && v != null ? excelDate(v, dateKind, date1904) : unxml(v ?? "");
|
|
128
|
+
}
|
|
129
|
+
return Array.from(values.slice(0, MAX_COLS), (x) => x ?? "");
|
|
130
|
+
}).filter((r) => r.some(Boolean));
|
|
131
|
+
if (!rows.length) return `## Sheet: ${s.name}\n\n(empty)`;
|
|
132
|
+
const note = rows.length > MAX_ROWS ? `\n\n(First ${MAX_ROWS} of ${rows.length} rows.)` : "";
|
|
133
|
+
return `## Sheet: ${s.name}\n\n${table(rows.slice(0, MAX_ROWS))}${note}`;
|
|
134
|
+
}).join("\n\n");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function hwpx(files) {
|
|
138
|
+
return byNumber("Contents/section", files).map((name) =>
|
|
139
|
+
[...files[name].matchAll(/<hp:p[ >][\s\S]*?<\/hp:p>/g)].map(([p]) => texts(p, "hp:t").trim()).filter(Boolean).join("\n\n"),
|
|
140
|
+
).join("\n\n");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function officeToMarkdown(bytes, kind) {
|
|
144
|
+
if (kind === "hwp") throw new Error("Old binary .hwp files are not supported. Save it as .hwpx or PDF, or attach it to your agent directly.");
|
|
145
|
+
const files = unpack(bytes);
|
|
146
|
+
const markdown = { docx, pptx, xlsx, hwpx }[kind](files).trim();
|
|
147
|
+
const core = files["docProps/core.xml"] || "";
|
|
148
|
+
return {
|
|
149
|
+
markdown,
|
|
150
|
+
title: texts(core, "dc:title"),
|
|
151
|
+
byline: texts(core, "dc:creator"),
|
|
152
|
+
published: texts(core, "dcterms:created"),
|
|
153
|
+
siteName: { docx: "Word document", pptx: "PowerPoint presentation", xlsx: "Excel workbook", hwpx: "Hangul document" }[kind],
|
|
154
|
+
};
|
|
155
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linkbrief-mcp",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"mcpName": "io.github.KDDYYY/linkbrief-mcp",
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"description": "MCP server that lets Claude, Codex and other agents read any link — web pages, PDFs, JavaScript pages — as clean Markdown from your own computer, with ~95% fewer tokens than raw HTML. Handles any language and legacy encodings.",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"bin": {
|
|
7
8
|
"linkbrief-mcp": "server.mjs"
|
|
8
9
|
},
|
|
9
10
|
"files": [
|
|
10
11
|
"server.mjs",
|
|
12
|
+
"tools.mjs",
|
|
11
13
|
"page.mjs",
|
|
12
14
|
"browser.mjs",
|
|
15
|
+
"office.mjs",
|
|
16
|
+
"robots.mjs",
|
|
13
17
|
"sites.mjs"
|
|
14
18
|
],
|
|
15
19
|
"engines": {
|
|
@@ -17,18 +21,29 @@
|
|
|
17
21
|
},
|
|
18
22
|
"scripts": {
|
|
19
23
|
"start": "node server.mjs",
|
|
20
|
-
"test": "node test.mjs",
|
|
21
|
-
"check:live": "node scripts/live-check.mjs"
|
|
24
|
+
"test": "node test.mjs && node test-http.mjs && node test-proxy.mjs && node test-fuzz.mjs",
|
|
25
|
+
"check:live": "node scripts/live-check.mjs",
|
|
26
|
+
"build:mcpb": "node scripts/build-mcpb.mjs"
|
|
22
27
|
},
|
|
23
28
|
"keywords": [
|
|
24
29
|
"mcp",
|
|
25
30
|
"model-context-protocol",
|
|
31
|
+
"mcp-server",
|
|
26
32
|
"claude",
|
|
33
|
+
"claude-code",
|
|
34
|
+
"codex",
|
|
35
|
+
"ai-agent",
|
|
27
36
|
"fetch",
|
|
37
|
+
"web-fetch",
|
|
38
|
+
"pdf",
|
|
28
39
|
"readability",
|
|
29
40
|
"markdown",
|
|
41
|
+
"summarize",
|
|
42
|
+
"headless",
|
|
30
43
|
"naver",
|
|
31
|
-
"korean"
|
|
44
|
+
"korean",
|
|
45
|
+
"japanese",
|
|
46
|
+
"chinese"
|
|
32
47
|
],
|
|
33
48
|
"license": "MIT",
|
|
34
49
|
"repository": {
|
|
@@ -40,8 +55,10 @@
|
|
|
40
55
|
"dependencies": {
|
|
41
56
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
42
57
|
"@mozilla/readability": "^0.6.0",
|
|
58
|
+
"fflate": "^0.8.3",
|
|
43
59
|
"linkedom": "^0.18.15",
|
|
44
60
|
"turndown": "^7.2.5",
|
|
61
|
+
"undici": "^7.30.2",
|
|
45
62
|
"unpdf": "1.9.1",
|
|
46
63
|
"zod": "^4.6.7"
|
|
47
64
|
},
|