@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 ADDED
@@ -0,0 +1,5 @@
1
+ python3 -m pip install --upgrade pip setuptools wheel \
2
+ -i https://pypi.tuna.tsinghua.edu.cn/simple
3
+
4
+ python3 -m pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
5
+ python main.py
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@templmf/temp-solf-lmf",
3
- "version": "0.0.145",
3
+ "version": "0.0.146",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,6 @@
1
+ cryptography==44.0.2
2
+ litellm==1.63.14
3
+ crawl4ai==0.7.4
4
+ mcp==1.8.0
5
+ uvicorn==0.34.0
6
+ starlette==0.46.2
File without changes
File without changes