@templmf/temp-solf-lmf 0.0.145 → 0.0.146
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.md +5 -0
- package/main.py +48 -0
- package/package.json +1 -1
- package/requirements.txt +6 -0
- /package/{McpHttpClient.js → new/McpHttpClient.js} +0 -0
- /package/{server.js → new/server.js} +0 -0
package/README.md
ADDED
package/main.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
from crawl4ai import AsyncWebCrawler, BrowserConfig
|
|
6
|
+
from mcp.server.fastmcp import FastMCP
|
|
7
|
+
|
|
8
|
+
mcp = FastMCP("crawl4ai-mcp")
|
|
9
|
+
|
|
10
|
+
browser_config = BrowserConfig(
|
|
11
|
+
browser_type="chromium",
|
|
12
|
+
chrome_channel="chrome", # 复用系统安装的正式版 Chrome
|
|
13
|
+
headless=True,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
crawler: AsyncWebCrawler | None = None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async def get_crawler():
|
|
20
|
+
global crawler
|
|
21
|
+
if crawler is None:
|
|
22
|
+
crawler = AsyncWebCrawler(config=browser_config)
|
|
23
|
+
await crawler.__aenter__()
|
|
24
|
+
return crawler
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@mcp.tool()
|
|
28
|
+
async def crawl_url(url: str) -> str:
|
|
29
|
+
"""Crawl a webpage and return markdown content. Suitable for RAG and LLM analysis."""
|
|
30
|
+
c = await get_crawler()
|
|
31
|
+
result = await c.arun(url=url)
|
|
32
|
+
return result.markdown
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@mcp.tool()
|
|
36
|
+
async def crawl_urls(urls: list[str]) -> str:
|
|
37
|
+
"""Crawl multiple webpages."""
|
|
38
|
+
c = await get_crawler()
|
|
39
|
+
results = []
|
|
40
|
+
for url in urls:
|
|
41
|
+
r = await c.arun(url=url)
|
|
42
|
+
results.append({"url": url, "content": r.markdown})
|
|
43
|
+
return str(results)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
# 直接用 streamable-http transport 启动,FastMCP 内部会处理好 ASGI/uvicorn
|
|
48
|
+
mcp.run(transport="streamable-http")
|
package/package.json
CHANGED
package/requirements.txt
ADDED
|
File without changes
|
|
File without changes
|