docusaurus-mcp 1.0.0__py3-none-any.whl
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.
- docusaurus_mcp/__init__.py +6 -0
- docusaurus_mcp/__main__.py +16 -0
- docusaurus_mcp/server.py +560 -0
- docusaurus_mcp-1.0.0.dist-info/METADATA +261 -0
- docusaurus_mcp-1.0.0.dist-info/RECORD +9 -0
- docusaurus_mcp-1.0.0.dist-info/WHEEL +5 -0
- docusaurus_mcp-1.0.0.dist-info/entry_points.txt +2 -0
- docusaurus_mcp-1.0.0.dist-info/licenses/LICENSE +21 -0
- docusaurus_mcp-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Entry point for Docusaurus MCP Server
|
|
4
|
+
Usage: docusaurus-mcp | python -m docusaurus_mcp
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .server import mcp
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def run():
|
|
11
|
+
"""Synchronous entry point"""
|
|
12
|
+
mcp.run()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if __name__ == "__main__":
|
|
16
|
+
run()
|
docusaurus_mcp/server.py
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Docusaurus MCP Server
|
|
4
|
+
Generic MCP server for any Docusaurus documentation site.
|
|
5
|
+
Web-scraping based: works with both standard static and SPA-only sites.
|
|
6
|
+
Automatically detects SPA mode and falls back to webpack chunk parsing.
|
|
7
|
+
|
|
8
|
+
Environment variables:
|
|
9
|
+
DOCUSAURUS_URL (required) Site base URL, e.g. https://docs.example.com
|
|
10
|
+
DOCUSAURUS_DESCRIPTION (optional) Extra context appended to tool descriptions
|
|
11
|
+
DOCUSAURUS_TIMEOUT (optional) HTTP timeout in seconds (default: 30)
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import sys
|
|
18
|
+
import xml.etree.ElementTree as ET
|
|
19
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
20
|
+
from urllib.parse import urljoin, urlparse
|
|
21
|
+
|
|
22
|
+
import httpx
|
|
23
|
+
from bs4 import BeautifulSoup
|
|
24
|
+
from markdownify import markdownify as md
|
|
25
|
+
from mcp.server.fastmcp import FastMCP
|
|
26
|
+
|
|
27
|
+
# ---------------------------------------------------------------------------
|
|
28
|
+
# Configuration
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
SITE_URL = os.environ.get("DOCUSAURUS_URL", "").rstrip("/")
|
|
31
|
+
EXTRA_DESCRIPTION = os.environ.get("DOCUSAURUS_DESCRIPTION", "")
|
|
32
|
+
TIMEOUT = int(os.environ.get("DOCUSAURUS_TIMEOUT", "30"))
|
|
33
|
+
|
|
34
|
+
if not SITE_URL:
|
|
35
|
+
print(
|
|
36
|
+
"HATA: DOCUSAURUS_URL environment variable zorunludur.\n"
|
|
37
|
+
"Örnek: DOCUSAURUS_URL=https://docs.example.com",
|
|
38
|
+
file=sys.stderr,
|
|
39
|
+
)
|
|
40
|
+
sys.exit(1)
|
|
41
|
+
|
|
42
|
+
_client = httpx.Client(
|
|
43
|
+
timeout=TIMEOUT,
|
|
44
|
+
follow_redirects=True,
|
|
45
|
+
headers={"User-Agent": "docusaurus-mcp/1.0"},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# ---------------------------------------------------------------------------
|
|
50
|
+
# Helpers
|
|
51
|
+
# ---------------------------------------------------------------------------
|
|
52
|
+
def _unescape_js(s: str) -> str:
|
|
53
|
+
"""Unescape JavaScript string literal (handles surrogate pairs)."""
|
|
54
|
+
s = s.replace('\\"', '"').replace("\\'", "'")
|
|
55
|
+
s = s.replace("\\n", "\n").replace("\\t", "\t")
|
|
56
|
+
s = re.sub(r"\\u([0-9a-fA-F]{4})", lambda m: chr(int(m.group(1), 16)), s)
|
|
57
|
+
s = re.sub(r"\\x([0-9a-fA-F]{2})", lambda m: chr(int(m.group(1), 16)), s)
|
|
58
|
+
s = s.replace("\\\\", "\\")
|
|
59
|
+
# Combine surrogate pairs (JS UTF-16 → Python str)
|
|
60
|
+
try:
|
|
61
|
+
s = s.encode("utf-16", "surrogatepass").decode("utf-16")
|
|
62
|
+
except (UnicodeEncodeError, UnicodeDecodeError):
|
|
63
|
+
s = s.encode("utf-8", "replace").decode("utf-8")
|
|
64
|
+
return s
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _relpath(url: str) -> str:
|
|
68
|
+
"""URL → relative path (no leading slash)."""
|
|
69
|
+
base = urlparse(SITE_URL).path.rstrip("/")
|
|
70
|
+
path = urlparse(url).path
|
|
71
|
+
if base and path.startswith(base):
|
|
72
|
+
path = path[len(base):]
|
|
73
|
+
return path.strip("/")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# ---------------------------------------------------------------------------
|
|
77
|
+
# Sitemap
|
|
78
|
+
# ---------------------------------------------------------------------------
|
|
79
|
+
def _fetch_sitemap() -> list[str]:
|
|
80
|
+
"""Fetch sitemap.xml and return normalized URLs."""
|
|
81
|
+
resp = _client.get(f"{SITE_URL}/sitemap.xml")
|
|
82
|
+
resp.raise_for_status()
|
|
83
|
+
root = ET.fromstring(resp.text)
|
|
84
|
+
ns = {"s": "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
|
85
|
+
sp = urlparse(SITE_URL)
|
|
86
|
+
urls: list[str] = []
|
|
87
|
+
for loc in root.findall(".//s:loc", ns):
|
|
88
|
+
raw = (loc.text or "").strip()
|
|
89
|
+
if raw:
|
|
90
|
+
p = urlparse(raw)
|
|
91
|
+
urls.append(
|
|
92
|
+
raw.replace(
|
|
93
|
+
f"{p.scheme}://{p.netloc}", f"{sp.scheme}://{sp.netloc}"
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
return urls
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# ---------------------------------------------------------------------------
|
|
100
|
+
# HTML extraction (standard sites)
|
|
101
|
+
# ---------------------------------------------------------------------------
|
|
102
|
+
def _extract_html(html: str, page_url: str) -> tuple[str, str, str]:
|
|
103
|
+
"""Extract (title, description, markdown_content) from Docusaurus HTML."""
|
|
104
|
+
soup = BeautifulSoup(html, "html.parser")
|
|
105
|
+
|
|
106
|
+
title = ""
|
|
107
|
+
h1 = soup.select_one("article h1, .markdown h1, main h1")
|
|
108
|
+
if h1:
|
|
109
|
+
title = h1.get_text(strip=True)
|
|
110
|
+
if not title:
|
|
111
|
+
tag = soup.find("title")
|
|
112
|
+
if tag:
|
|
113
|
+
t = tag.get_text(strip=True)
|
|
114
|
+
for sep in (" | ", " - ", " · ", " — "):
|
|
115
|
+
if sep in t:
|
|
116
|
+
t = t.split(sep)[0].strip()
|
|
117
|
+
break
|
|
118
|
+
title = t
|
|
119
|
+
|
|
120
|
+
desc = ""
|
|
121
|
+
meta = soup.find("meta", attrs={"name": "description"})
|
|
122
|
+
if meta:
|
|
123
|
+
desc = meta.get("content", "")
|
|
124
|
+
|
|
125
|
+
el = (
|
|
126
|
+
soup.select_one("article.markdown")
|
|
127
|
+
or soup.select_one("article")
|
|
128
|
+
or soup.select_one(".markdown")
|
|
129
|
+
or soup.select_one("main")
|
|
130
|
+
)
|
|
131
|
+
if not el:
|
|
132
|
+
return title, desc, ""
|
|
133
|
+
|
|
134
|
+
for sel in (
|
|
135
|
+
"nav", "header", "footer", "aside",
|
|
136
|
+
".pagination-nav", ".theme-doc-sidebar-container",
|
|
137
|
+
".theme-doc-footer", ".theme-doc-toc-mobile",
|
|
138
|
+
".breadcrumbs", ".table-of-contents", "script", "style",
|
|
139
|
+
):
|
|
140
|
+
for tag in el.select(sel):
|
|
141
|
+
tag.decompose()
|
|
142
|
+
|
|
143
|
+
for img in el.find_all("img", src=True):
|
|
144
|
+
img["src"] = urljoin(page_url, img["src"])
|
|
145
|
+
|
|
146
|
+
content = md(str(el), heading_style="ATX")
|
|
147
|
+
content = re.sub(r"\n{3,}", "\n\n", content)
|
|
148
|
+
return title, desc, content.strip()
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# ---------------------------------------------------------------------------
|
|
152
|
+
# SPA chunk extraction
|
|
153
|
+
# ---------------------------------------------------------------------------
|
|
154
|
+
def _parse_runtime_chunks(
|
|
155
|
+
homepage_html: str,
|
|
156
|
+
) -> dict[str, tuple[str, str]]:
|
|
157
|
+
"""Parse runtime.js → {chunk_id: (name_hash, content_hash)}.
|
|
158
|
+
|
|
159
|
+
Docusaurus webpack builds the URL via:
|
|
160
|
+
t.u = e => "assets/js/" + NAME_MAP[e]||e + "." + HASH_MAP[e] + ".js"
|
|
161
|
+
"""
|
|
162
|
+
soup = BeautifulSoup(homepage_html, "html.parser")
|
|
163
|
+
runtime_url = None
|
|
164
|
+
for s in soup.find_all("script", src=True):
|
|
165
|
+
if "/runtime" in s["src"]:
|
|
166
|
+
runtime_url = urljoin(SITE_URL + "/", s["src"])
|
|
167
|
+
break
|
|
168
|
+
if not runtime_url:
|
|
169
|
+
return {}
|
|
170
|
+
|
|
171
|
+
rt = _client.get(runtime_url).text
|
|
172
|
+
|
|
173
|
+
# Name hash map (first object in t.u)
|
|
174
|
+
name_map: dict[str, str] = {}
|
|
175
|
+
nm = re.search(
|
|
176
|
+
r'"assets/js/"\s*\+\s*\(?\{([^}]+)\}\s*\[e\]\s*\|\|\s*e\)?', rt
|
|
177
|
+
)
|
|
178
|
+
if nm:
|
|
179
|
+
name_map = dict(re.findall(r'(\d+):"([^"]+)"', nm.group(1)))
|
|
180
|
+
|
|
181
|
+
# Content hash map (second object in t.u)
|
|
182
|
+
hm = re.search(r'\+"\."\+\{([^}]+)\}\[e\]\+"\.js"', rt)
|
|
183
|
+
if not hm:
|
|
184
|
+
return {}
|
|
185
|
+
|
|
186
|
+
chunks: dict[str, tuple[str, str]] = {}
|
|
187
|
+
for cid, chash in re.findall(r'(\d+):"([^"]+)"', hm.group(1)):
|
|
188
|
+
chunks[cid] = (name_map.get(cid, cid), chash)
|
|
189
|
+
|
|
190
|
+
return chunks
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _fetch_chunk(
|
|
194
|
+
chunk_id: str, name_hash: str, content_hash: str
|
|
195
|
+
) -> dict | None:
|
|
196
|
+
"""Fetch a webpack chunk and extract doc metadata + content.
|
|
197
|
+
Returns a doc dict or None if not a doc chunk.
|
|
198
|
+
"""
|
|
199
|
+
url = f"{SITE_URL}/assets/js/{name_hash}.{content_hash}.js"
|
|
200
|
+
try:
|
|
201
|
+
text = _client.get(url).text
|
|
202
|
+
except httpx.HTTPError:
|
|
203
|
+
return None
|
|
204
|
+
|
|
205
|
+
# Metadata lives in JSON.parse('{...}')
|
|
206
|
+
meta_match = re.search(r"JSON\.parse\('(\{.*?\})'\)", text)
|
|
207
|
+
if not meta_match:
|
|
208
|
+
return None
|
|
209
|
+
|
|
210
|
+
try:
|
|
211
|
+
meta = json.loads(meta_match.group(1))
|
|
212
|
+
except json.JSONDecodeError:
|
|
213
|
+
return None
|
|
214
|
+
|
|
215
|
+
# Only doc pages have sourceDirName
|
|
216
|
+
if "sourceDirName" not in meta:
|
|
217
|
+
return None
|
|
218
|
+
|
|
219
|
+
title = meta.get("title", "")
|
|
220
|
+
description = meta.get("description", "")
|
|
221
|
+
permalink = meta.get("permalink", "")
|
|
222
|
+
meta_id = meta.get("id", "")
|
|
223
|
+
|
|
224
|
+
# --- Extract content from JSX children ---
|
|
225
|
+
parts: list[str] = []
|
|
226
|
+
for m in re.finditer(r'children\s*:\s*"((?:[^"\\]|\\.)*)"', text):
|
|
227
|
+
s = _unescape_js(m.group(1))
|
|
228
|
+
if len(s) >= 2 and s != title:
|
|
229
|
+
parts.append(s)
|
|
230
|
+
|
|
231
|
+
# TOC for section structure
|
|
232
|
+
toc: list[tuple[int, str]] = []
|
|
233
|
+
for val, level in re.findall(
|
|
234
|
+
r'\{value:"((?:[^"\\]|\\.)*)",id:"[^"]*",level:(\d+)\}', text
|
|
235
|
+
):
|
|
236
|
+
toc.append((int(level), _unescape_js(val)))
|
|
237
|
+
|
|
238
|
+
# Build readable markdown
|
|
239
|
+
lines: list[str] = []
|
|
240
|
+
if title:
|
|
241
|
+
lines += [f"# {title}", ""]
|
|
242
|
+
if description:
|
|
243
|
+
lines += [description, ""]
|
|
244
|
+
for lvl, val in toc:
|
|
245
|
+
lines += [f"{'#' * lvl} {val}", ""]
|
|
246
|
+
if parts:
|
|
247
|
+
current: list[str] = []
|
|
248
|
+
for p in parts:
|
|
249
|
+
current.append(p)
|
|
250
|
+
if p.rstrip().endswith((".", ":", "!", "?", ";")):
|
|
251
|
+
lines.append(" ".join(current))
|
|
252
|
+
lines.append("")
|
|
253
|
+
current = []
|
|
254
|
+
if current:
|
|
255
|
+
lines.append(" ".join(current))
|
|
256
|
+
|
|
257
|
+
content = "\n".join(lines).strip()
|
|
258
|
+
|
|
259
|
+
# Category from permalink
|
|
260
|
+
pparts = permalink.strip("/").split("/") if permalink else []
|
|
261
|
+
category = pparts[0] if len(pparts) > 1 else "_root"
|
|
262
|
+
|
|
263
|
+
# Short ID (last segment)
|
|
264
|
+
short_id = meta_id.split("/")[-1] if "/" in meta_id else meta_id
|
|
265
|
+
if not short_id and pparts:
|
|
266
|
+
short_id = pparts[-1]
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
"id": short_id,
|
|
270
|
+
"full_id": meta_id,
|
|
271
|
+
"title": title,
|
|
272
|
+
"url": f"{SITE_URL}{permalink}" if permalink else "",
|
|
273
|
+
"path": permalink.strip("/"),
|
|
274
|
+
"category": category,
|
|
275
|
+
"content": content,
|
|
276
|
+
"description": description,
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
# ---------------------------------------------------------------------------
|
|
281
|
+
# Startup
|
|
282
|
+
# ---------------------------------------------------------------------------
|
|
283
|
+
print(f"Başlatılıyor: {SITE_URL}", file=sys.stderr)
|
|
284
|
+
|
|
285
|
+
# 1. Homepage
|
|
286
|
+
try:
|
|
287
|
+
_homepage_html = _client.get(SITE_URL).text
|
|
288
|
+
except httpx.HTTPError as e:
|
|
289
|
+
print(f"HATA: Ana sayfa alınamadı: {e}", file=sys.stderr)
|
|
290
|
+
sys.exit(1)
|
|
291
|
+
|
|
292
|
+
_site_title = "Docusaurus Docs"
|
|
293
|
+
_soup = BeautifulSoup(_homepage_html, "html.parser")
|
|
294
|
+
if _title_tag := _soup.find("title"):
|
|
295
|
+
_site_title = _title_tag.get_text(strip=True)
|
|
296
|
+
|
|
297
|
+
# 2. Sitemap
|
|
298
|
+
print("Sitemap alınıyor...", file=sys.stderr)
|
|
299
|
+
try:
|
|
300
|
+
_sitemap_urls = _fetch_sitemap()
|
|
301
|
+
except Exception as e:
|
|
302
|
+
print(f"Sitemap alınamadı: {e}", file=sys.stderr)
|
|
303
|
+
_sitemap_urls = []
|
|
304
|
+
|
|
305
|
+
# 3. SPA detection: fetch one doc page, compare with homepage
|
|
306
|
+
_spa_mode = False
|
|
307
|
+
_test_urls = [u for u in _sitemap_urls if _relpath(u)]
|
|
308
|
+
if _test_urls:
|
|
309
|
+
try:
|
|
310
|
+
_spa_mode = _client.get(_test_urls[0]).text == _homepage_html
|
|
311
|
+
except httpx.HTTPError:
|
|
312
|
+
pass
|
|
313
|
+
|
|
314
|
+
# 4. Load content
|
|
315
|
+
_all_docs: list[dict] = []
|
|
316
|
+
|
|
317
|
+
if _spa_mode:
|
|
318
|
+
# --- SPA mode: parse webpack chunks ---
|
|
319
|
+
print("SPA modu algılandı, chunk'lar parse ediliyor...", file=sys.stderr)
|
|
320
|
+
_chunk_info = _parse_runtime_chunks(_homepage_html)
|
|
321
|
+
print(f" {len(_chunk_info)} chunk bulundu", file=sys.stderr)
|
|
322
|
+
|
|
323
|
+
def _do_fetch(item):
|
|
324
|
+
cid, (nhash, chash) = item
|
|
325
|
+
return _fetch_chunk(cid, nhash, chash)
|
|
326
|
+
|
|
327
|
+
with ThreadPoolExecutor(max_workers=15) as pool:
|
|
328
|
+
futs = {pool.submit(_do_fetch, it): it for it in _chunk_info.items()}
|
|
329
|
+
for f in as_completed(futs):
|
|
330
|
+
try:
|
|
331
|
+
doc = f.result()
|
|
332
|
+
if doc:
|
|
333
|
+
_all_docs.append(doc)
|
|
334
|
+
except Exception as exc:
|
|
335
|
+
print(f" Chunk hatası: {exc}", file=sys.stderr)
|
|
336
|
+
|
|
337
|
+
else:
|
|
338
|
+
# --- Standard mode: scrape HTML pages ---
|
|
339
|
+
print("Standart mod (statik HTML)", file=sys.stderr)
|
|
340
|
+
skip = {"blog", "tags", "search", "page", "markdown-page"}
|
|
341
|
+
for url in _sitemap_urls:
|
|
342
|
+
rel = _relpath(url)
|
|
343
|
+
if not rel:
|
|
344
|
+
continue
|
|
345
|
+
parts = rel.split("/")
|
|
346
|
+
if parts[0] in skip:
|
|
347
|
+
continue
|
|
348
|
+
if parts[0] == "docs" and len(parts) > 2:
|
|
349
|
+
cat, did = parts[1], parts[-1]
|
|
350
|
+
elif len(parts) > 1:
|
|
351
|
+
cat, did = parts[0], parts[-1]
|
|
352
|
+
else:
|
|
353
|
+
cat, did = "_root", parts[0]
|
|
354
|
+
_all_docs.append({
|
|
355
|
+
"id": did, "title": did.replace("-", " ").title(),
|
|
356
|
+
"url": url, "path": rel, "category": cat,
|
|
357
|
+
"content": None, "description": "",
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
def _scrape(doc):
|
|
361
|
+
try:
|
|
362
|
+
html = _client.get(doc["url"]).text
|
|
363
|
+
title, desc, content = _extract_html(html, doc["url"])
|
|
364
|
+
if title:
|
|
365
|
+
doc["title"] = title
|
|
366
|
+
if desc:
|
|
367
|
+
doc["description"] = desc
|
|
368
|
+
doc["content"] = content
|
|
369
|
+
except Exception:
|
|
370
|
+
doc["content"] = ""
|
|
371
|
+
|
|
372
|
+
if _all_docs:
|
|
373
|
+
print(f" {len(_all_docs)} sayfa yükleniyor...", file=sys.stderr)
|
|
374
|
+
with ThreadPoolExecutor(max_workers=10) as pool:
|
|
375
|
+
list(pool.map(_scrape, _all_docs))
|
|
376
|
+
|
|
377
|
+
# 5. Build indexes
|
|
378
|
+
_categories = {}
|
|
379
|
+
for d in _all_docs:
|
|
380
|
+
_categories.setdefault(d["category"].lower(), []).append(d)
|
|
381
|
+
|
|
382
|
+
_doc_count = len(_all_docs)
|
|
383
|
+
_by_id: dict[str, dict] = {}
|
|
384
|
+
_by_url: dict[str, dict] = {}
|
|
385
|
+
_by_path: dict[str, dict] = {}
|
|
386
|
+
|
|
387
|
+
for d in _all_docs:
|
|
388
|
+
_by_id[d["id"]] = d
|
|
389
|
+
if d.get("full_id"):
|
|
390
|
+
_by_id[d["full_id"]] = d
|
|
391
|
+
_by_url[d["url"]] = d
|
|
392
|
+
_by_path[d["path"]] = d
|
|
393
|
+
|
|
394
|
+
print(f"Hazır: {_site_title} — {_doc_count} döküman", file=sys.stderr)
|
|
395
|
+
|
|
396
|
+
# ---------------------------------------------------------------------------
|
|
397
|
+
# MCP Server & Tools
|
|
398
|
+
# ---------------------------------------------------------------------------
|
|
399
|
+
mcp = FastMCP("docusaurus-docs")
|
|
400
|
+
_base_desc = f"{_site_title} döküman sitesinde"
|
|
401
|
+
_desc_suffix = f"\n{EXTRA_DESCRIPTION}" if EXTRA_DESCRIPTION else ""
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
@mcp.tool(
|
|
405
|
+
description=f"{_base_desc} tüm döküman yapısını (kategoriler ve sayfalar) gösterir.{_desc_suffix}"
|
|
406
|
+
)
|
|
407
|
+
def get_doc_structure() -> str:
|
|
408
|
+
"""
|
|
409
|
+
Returns:
|
|
410
|
+
Döküman sitesinin kategori ağacı
|
|
411
|
+
"""
|
|
412
|
+
lines = [f"{_site_title} ({_doc_count} döküman)", ""]
|
|
413
|
+
for cat in sorted(_categories.keys()):
|
|
414
|
+
if cat == "_root":
|
|
415
|
+
continue
|
|
416
|
+
docs = _categories[cat]
|
|
417
|
+
lines.append(f"📁 {cat} ({len(docs)} sayfa)")
|
|
418
|
+
for doc in sorted(docs, key=lambda d: d["title"]):
|
|
419
|
+
lines.append(f" ├── {doc['title']} [{doc['id']}]")
|
|
420
|
+
lines.append("")
|
|
421
|
+
|
|
422
|
+
root = _categories.get("_root", [])
|
|
423
|
+
if root:
|
|
424
|
+
lines.append(f"📄 Diğer ({len(root)} sayfa)")
|
|
425
|
+
for doc in sorted(root, key=lambda d: d["title"]):
|
|
426
|
+
lines.append(f" ├── {doc['title']} [{doc['id']}]")
|
|
427
|
+
|
|
428
|
+
return "\n".join(lines)
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
@mcp.tool(
|
|
432
|
+
description=f"{_base_desc} bir kategorideki sayfaları listeler.{_desc_suffix}"
|
|
433
|
+
)
|
|
434
|
+
def list_docs(category: str = "") -> str:
|
|
435
|
+
"""
|
|
436
|
+
Args:
|
|
437
|
+
category: Kategori adı. Boş bırakılırsa tüm kategoriler özetlenir.
|
|
438
|
+
"""
|
|
439
|
+
if not category:
|
|
440
|
+
lines = [f"{_site_title} — Kategoriler:", ""]
|
|
441
|
+
for cat in sorted(_categories.keys()):
|
|
442
|
+
if cat == "_root":
|
|
443
|
+
continue
|
|
444
|
+
lines.append(f" 📁 {cat} — {len(_categories[cat])} sayfa")
|
|
445
|
+
lines.append("")
|
|
446
|
+
lines.append("Detay için: list_docs(category='kategori_adı')")
|
|
447
|
+
return "\n".join(lines)
|
|
448
|
+
|
|
449
|
+
cat_key = category.lower()
|
|
450
|
+
docs = _categories.get(cat_key)
|
|
451
|
+
if not docs:
|
|
452
|
+
available = [c for c in _categories if c != "_root"]
|
|
453
|
+
return (
|
|
454
|
+
f"'{category}' bulunamadı. Mevcut: {', '.join(sorted(available))}"
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
lines = [f"📁 {category} ({len(docs)} sayfa)", ""]
|
|
458
|
+
for doc in sorted(docs, key=lambda d: d["title"]):
|
|
459
|
+
lines.append(f" • {doc['title']}")
|
|
460
|
+
if doc["description"]:
|
|
461
|
+
lines.append(f" {doc['description']}")
|
|
462
|
+
lines.append(f" ID: {doc['id']} | {doc['url']}")
|
|
463
|
+
lines.append("")
|
|
464
|
+
return "\n".join(lines)
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
@mcp.tool(
|
|
468
|
+
description=f"{_base_desc} anahtar kelime araması yapar. Başlık, açıklama ve içerik üzerinde arar.{_desc_suffix}"
|
|
469
|
+
)
|
|
470
|
+
def search_docs(query: str, limit: int = 5) -> str:
|
|
471
|
+
"""
|
|
472
|
+
Args:
|
|
473
|
+
query: Aranacak kelime veya ifade
|
|
474
|
+
limit: Maksimum sonuç sayısı (varsayılan: 5)
|
|
475
|
+
"""
|
|
476
|
+
if not query.strip():
|
|
477
|
+
return "Lütfen bir arama terimi girin."
|
|
478
|
+
|
|
479
|
+
q = query.lower()
|
|
480
|
+
results: list[tuple[int, dict, str]] = []
|
|
481
|
+
|
|
482
|
+
for doc in _all_docs:
|
|
483
|
+
score = 0
|
|
484
|
+
snippet = ""
|
|
485
|
+
|
|
486
|
+
if q in doc["title"].lower():
|
|
487
|
+
score += 10
|
|
488
|
+
if q in doc["description"].lower():
|
|
489
|
+
score += 3
|
|
490
|
+
|
|
491
|
+
content = (doc["content"] or "").lower()
|
|
492
|
+
if q in content:
|
|
493
|
+
count = content.count(q)
|
|
494
|
+
score += min(count, 5)
|
|
495
|
+
idx = content.index(q)
|
|
496
|
+
start = max(0, idx - 100)
|
|
497
|
+
end = min(len(content), idx + len(query) + 200)
|
|
498
|
+
raw = (doc["content"] or "")[start:end].replace("\n", " ").strip()
|
|
499
|
+
snippet = ("..." if start > 0 else "") + raw + (
|
|
500
|
+
"..." if end < len(content) else ""
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
if score > 0:
|
|
504
|
+
results.append((score, doc, snippet))
|
|
505
|
+
|
|
506
|
+
results.sort(key=lambda x: x[0], reverse=True)
|
|
507
|
+
results = results[:limit]
|
|
508
|
+
|
|
509
|
+
if not results:
|
|
510
|
+
return f"'{query}' için sonuç bulunamadı."
|
|
511
|
+
|
|
512
|
+
lines = [f"🔍 '{query}' — {len(results)} sonuç:", ""]
|
|
513
|
+
for _, doc, snippet in results:
|
|
514
|
+
lines.append(f" 📄 {doc['title']}")
|
|
515
|
+
lines.append(f" {doc['url']}")
|
|
516
|
+
if snippet:
|
|
517
|
+
lines.append(f" {snippet}")
|
|
518
|
+
lines.append("")
|
|
519
|
+
return "\n".join(lines)
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
@mcp.tool(
|
|
523
|
+
description=f"{_base_desc} bir dökümanın tam içeriğini markdown olarak döner. ID veya URL ile erişilir.{_desc_suffix}"
|
|
524
|
+
)
|
|
525
|
+
def fetch_doc(doc_ref: str) -> str:
|
|
526
|
+
"""
|
|
527
|
+
Args:
|
|
528
|
+
doc_ref: Döküman ID'si (ör. 'yeni-izin-talebi'), URL'i veya path'i
|
|
529
|
+
"""
|
|
530
|
+
doc = _by_id.get(doc_ref) or _by_url.get(doc_ref) or _by_path.get(doc_ref)
|
|
531
|
+
|
|
532
|
+
if not doc:
|
|
533
|
+
ref_lower = doc_ref.lower()
|
|
534
|
+
for d in _all_docs:
|
|
535
|
+
if (
|
|
536
|
+
d["id"].lower() == ref_lower
|
|
537
|
+
or ref_lower in d["url"].lower()
|
|
538
|
+
or ref_lower in d["path"].lower()
|
|
539
|
+
):
|
|
540
|
+
doc = d
|
|
541
|
+
break
|
|
542
|
+
|
|
543
|
+
if not doc:
|
|
544
|
+
return (
|
|
545
|
+
f"Döküman bulunamadı: '{doc_ref}'\n"
|
|
546
|
+
"Mevcut ID'ler için get_doc_structure() kullanın."
|
|
547
|
+
)
|
|
548
|
+
|
|
549
|
+
header = f"# {doc['title']}\n\n"
|
|
550
|
+
if doc["url"]:
|
|
551
|
+
header += f"**URL:** {doc['url']}\n"
|
|
552
|
+
if doc["description"]:
|
|
553
|
+
header += f"**Açıklama:** {doc['description']}\n"
|
|
554
|
+
header += f"**Kategori:** {doc['category']}\n\n---\n\n"
|
|
555
|
+
|
|
556
|
+
return header + (doc["content"] or "(İçerik yüklenemedi)")
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
if __name__ == "__main__":
|
|
560
|
+
mcp.run()
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docusaurus-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Generic MCP server for any Docusaurus documentation site - search, browse, and read docs
|
|
5
|
+
Author: mytsx
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mytsx/mcp-servers
|
|
8
|
+
Project-URL: Repository, https://github.com/mytsx/mcp-servers
|
|
9
|
+
Project-URL: Issues, https://github.com/mytsx/mcp-servers/issues
|
|
10
|
+
Keywords: mcp,model-context-protocol,docusaurus,documentation,search
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: mcp[cli]>=1.0.0
|
|
19
|
+
Requires-Dist: httpx>=0.27.0
|
|
20
|
+
Requires-Dist: markdownify>=0.14.1
|
|
21
|
+
Requires-Dist: beautifulsoup4>=4.12.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Docusaurus MCP Server
|
|
25
|
+
|
|
26
|
+
[](https://python.org)
|
|
27
|
+
[](https://modelcontextprotocol.io)
|
|
28
|
+
[](LICENSE)
|
|
29
|
+
|
|
30
|
+
Generic MCP server for any [Docusaurus](https://docusaurus.io) documentation site. Point it at a URL and get full-text search, browsing, and content extraction — works with both static HTML and SPA-only builds.
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **Auto SPA Detection** — Detects SPA-only sites and falls back to webpack chunk parsing
|
|
35
|
+
- **Full-Text Search** — Search across titles, descriptions, and page content
|
|
36
|
+
- **Category Browsing** — Navigate the doc structure by categories
|
|
37
|
+
- **Markdown Extraction** — Returns clean markdown from any doc page
|
|
38
|
+
- **Sitemap Support** — Automatically discovers all pages via sitemap.xml
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
### Claude Code
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
claude mcp add docusaurus \
|
|
46
|
+
-e DOCUSAURUS_URL="https://docs.example.com" \
|
|
47
|
+
-- uvx docusaurus-mcp
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Claude Desktop
|
|
51
|
+
|
|
52
|
+
Add to your config file:
|
|
53
|
+
|
|
54
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
55
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"mcpServers": {
|
|
60
|
+
"docusaurus": {
|
|
61
|
+
"command": "uvx",
|
|
62
|
+
"args": ["docusaurus-mcp"],
|
|
63
|
+
"env": {
|
|
64
|
+
"DOCUSAURUS_URL": "https://docs.example.com"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Cursor
|
|
72
|
+
|
|
73
|
+
Add to `~/.cursor/mcp.json`:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"mcpServers": {
|
|
78
|
+
"docusaurus": {
|
|
79
|
+
"command": "uvx",
|
|
80
|
+
"args": ["docusaurus-mcp"],
|
|
81
|
+
"env": {
|
|
82
|
+
"DOCUSAURUS_URL": "https://docs.example.com"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Windsurf
|
|
90
|
+
|
|
91
|
+
Add to Windsurf MCP config:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"mcpServers": {
|
|
96
|
+
"docusaurus": {
|
|
97
|
+
"command": "uvx",
|
|
98
|
+
"args": ["docusaurus-mcp"],
|
|
99
|
+
"env": {
|
|
100
|
+
"DOCUSAURUS_URL": "https://docs.example.com"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### VS Code
|
|
108
|
+
|
|
109
|
+
Add to your VS Code settings (JSON):
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
"mcp": {
|
|
113
|
+
"servers": {
|
|
114
|
+
"docusaurus": {
|
|
115
|
+
"type": "stdio",
|
|
116
|
+
"command": "uvx",
|
|
117
|
+
"args": ["docusaurus-mcp"],
|
|
118
|
+
"env": {
|
|
119
|
+
"DOCUSAURUS_URL": "https://docs.example.com"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Gemini CLI
|
|
127
|
+
|
|
128
|
+
Add to `~/.gemini/settings.json`:
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"mcpServers": {
|
|
133
|
+
"docusaurus": {
|
|
134
|
+
"command": "uvx",
|
|
135
|
+
"args": ["docusaurus-mcp"],
|
|
136
|
+
"env": {
|
|
137
|
+
"DOCUSAURUS_URL": "https://docs.example.com"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### GitHub Copilot
|
|
145
|
+
|
|
146
|
+
Add to `~/.copilot/mcp-config.json`:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"mcpServers": {
|
|
151
|
+
"docusaurus": {
|
|
152
|
+
"command": "uvx",
|
|
153
|
+
"args": ["docusaurus-mcp"],
|
|
154
|
+
"env": {
|
|
155
|
+
"DOCUSAURUS_URL": "https://docs.example.com"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### OpenAI Codex
|
|
163
|
+
|
|
164
|
+
Add to `~/.codex/config.toml`:
|
|
165
|
+
|
|
166
|
+
```toml
|
|
167
|
+
[mcp_servers.docusaurus]
|
|
168
|
+
command = "uvx"
|
|
169
|
+
args = ["docusaurus-mcp"]
|
|
170
|
+
|
|
171
|
+
[mcp_servers.docusaurus.env]
|
|
172
|
+
DOCUSAURUS_URL = "https://docs.example.com"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Install from Source
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
cd docusaurus-mcp
|
|
179
|
+
pip install -e .
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Configuration
|
|
183
|
+
|
|
184
|
+
| Environment Variable | Required | Description |
|
|
185
|
+
|---------------------|----------|-------------|
|
|
186
|
+
| `DOCUSAURUS_URL` | Yes | Docusaurus site base URL (e.g. `https://docs.example.com`) |
|
|
187
|
+
| `DOCUSAURUS_DESCRIPTION` | No | Extra context appended to tool descriptions |
|
|
188
|
+
| `DOCUSAURUS_TIMEOUT` | No | HTTP timeout in seconds (default: `30`) |
|
|
189
|
+
|
|
190
|
+
## Tools
|
|
191
|
+
|
|
192
|
+
<details>
|
|
193
|
+
<summary><code>get_doc_structure</code> — Show full document tree</summary>
|
|
194
|
+
|
|
195
|
+
Returns the complete category and page structure of the documentation site.
|
|
196
|
+
|
|
197
|
+
No parameters required.
|
|
198
|
+
|
|
199
|
+
</details>
|
|
200
|
+
|
|
201
|
+
<details>
|
|
202
|
+
<summary><code>list_docs</code> — List docs by category</summary>
|
|
203
|
+
|
|
204
|
+
Lists all pages in a given category with titles, descriptions, and IDs.
|
|
205
|
+
|
|
206
|
+
| Parameter | Type | Required | Description |
|
|
207
|
+
|-----------|------|----------|-------------|
|
|
208
|
+
| `category` | string | No | Category name. Empty returns all categories. |
|
|
209
|
+
|
|
210
|
+
</details>
|
|
211
|
+
|
|
212
|
+
<details>
|
|
213
|
+
<summary><code>search_docs</code> — Full-text search</summary>
|
|
214
|
+
|
|
215
|
+
Searches across titles, descriptions, and page content. Returns ranked results with snippets.
|
|
216
|
+
|
|
217
|
+
| Parameter | Type | Required | Description |
|
|
218
|
+
|-----------|------|----------|-------------|
|
|
219
|
+
| `query` | string | Yes | Search term or phrase |
|
|
220
|
+
| `limit` | integer | No | Max results (default: `5`) |
|
|
221
|
+
|
|
222
|
+
</details>
|
|
223
|
+
|
|
224
|
+
<details>
|
|
225
|
+
<summary><code>fetch_doc</code> — Read a document</summary>
|
|
226
|
+
|
|
227
|
+
Returns the full content of a document as clean markdown.
|
|
228
|
+
|
|
229
|
+
| Parameter | Type | Required | Description |
|
|
230
|
+
|-----------|------|----------|-------------|
|
|
231
|
+
| `doc_ref` | string | Yes | Document ID, URL, or path |
|
|
232
|
+
|
|
233
|
+
</details>
|
|
234
|
+
|
|
235
|
+
## How It Works
|
|
236
|
+
|
|
237
|
+
1. **Startup**: Fetches the homepage and sitemap.xml
|
|
238
|
+
2. **SPA Detection**: Compares a doc page response with the homepage — if identical, the site is SPA-only
|
|
239
|
+
3. **Static Mode**: Scrapes each page's HTML and extracts article content via BeautifulSoup + markdownify
|
|
240
|
+
4. **SPA Mode**: Parses `runtime.js` to find webpack chunk URLs, fetches each chunk, and extracts doc metadata + content from `JSON.parse()` calls and JSX children
|
|
241
|
+
5. **Indexing**: Builds in-memory indexes by ID, URL, path, and category for fast lookups
|
|
242
|
+
|
|
243
|
+
## Usage Examples
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
# Browse the doc structure
|
|
247
|
+
What categories are in the documentation?
|
|
248
|
+
|
|
249
|
+
# Search for a topic
|
|
250
|
+
Search for "authentication" in the docs
|
|
251
|
+
|
|
252
|
+
# Read a specific page
|
|
253
|
+
Show me the "getting-started" page content
|
|
254
|
+
|
|
255
|
+
# Category browsing
|
|
256
|
+
List all pages in the "guides" category
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
docusaurus_mcp/__init__.py,sha256=A4y6qMxjtavxHIl3r2oHdMQMJtj8EDu-f2MuVaC6y3o,111
|
|
2
|
+
docusaurus_mcp/__main__.py,sha256=HlT5ujyv98rs7yz90ZYYOlv80t8WkIo0hqe8It0LPeg,243
|
|
3
|
+
docusaurus_mcp/server.py,sha256=t4jptW-TalGFSW_sXma0p-WMq9GGhRzqY7ykiH47Oao,18041
|
|
4
|
+
docusaurus_mcp-1.0.0.dist-info/licenses/LICENSE,sha256=geN4XKWlxLA8S01SA9_3thLyxgBWiTazfAAQHkQOo9A,1062
|
|
5
|
+
docusaurus_mcp-1.0.0.dist-info/METADATA,sha256=6Dp4KJIAK8k_gHoYDhkNK5IF_PI2tGFYeSVTmSlxREI,6284
|
|
6
|
+
docusaurus_mcp-1.0.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
7
|
+
docusaurus_mcp-1.0.0.dist-info/entry_points.txt,sha256=uZlUv9N2g2eaJgICCgxidZnORdf00ccY5cBsX951DtY,63
|
|
8
|
+
docusaurus_mcp-1.0.0.dist-info/top_level.txt,sha256=5e24wUudj3Nki0-36wGWSZ3z4cFzBOPRgRSHbatgRjY,15
|
|
9
|
+
docusaurus_mcp-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mytsx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
docusaurus_mcp
|