获取mcp-rs
高级Rust MCP服务器,用于使用13多种专用工具获取web内容。将HTML转换为Markdown、提取元数据、解析提要、搜索Reddit/维基百科等。
 
特性
核心能力
- HTML到Markdown -可读性算法+干净的降价转换
- 元数据抽取 -Open Graph、Schema.org、推特卡片、HTML元标签
- 提要解析 -RSS 0.9/1.0/2.0,Atom,JSON Feed支持
- CSS选择器 -从HTML中提取特定元素
- 表格提取 -将HTML表解析为结构化JSON
- 网站地图解析 -解析sitemap.xml和站点地图索引
- 链接提取 -使用内部/外部过滤提取所有链接
- 批量抓取 -具有速率限制的并行URL获取
- 内容搜索 -在具有上下文提取功能的页面内搜索
- Reddit集成 -搜索帖子、子版块,并提取评论
- 维基百科API -搜索、摘要、全文、随机文章
- PDF文本提取 -从PDF中提取文本和元数据(可选)
- 图像信息 -获取图像尺寸和格式(可选)
高级功能
- 🤖 Robots.txt验证 -遵守爬行规则(可选)
- 🔄 内存缓存 -5分钟TTL用于性能
- ⚡ 速率限制 -令牌桶算法
- 🌐 代理支持 -HTTP/HTTPS代理配置
- 📝 传输感知日志记录 -stdio模式下无stderr污染
- 🎯 双用户代理 -自主与手动取数模式
安装
来源
git clone https://github.com/ssoj13/fetch-mcp-rs
cd fetch-mcp-rs
cargo build --release二进制
编译后的二进制文件将位于 target/release/fetch-mcp-rs 或 target/release/fetch-mcp-rs.exe (Windows)。
用法
命令行选项
fetch-mcp-rs [OPTIONS]
Options:
--user-agent User agent string for HTTP requests
--ignore-robots-txt Ignore robots.txt restrictions (use with caution)
--proxy-url
HTTP proxy URL (e.g., http://proxy:8080)
--log-file Log file path (optional, for debugging)
--port
Enable HTTP stream mode on specified port
-h, --help Print helpMCP配置
添加到MCP设置中:
{
"mcpServers": {
"fetch": {
"command": "/path/to/fetch-mcp-rs",
"args": []
}
}
}使用自定义选项:
{
"mcpServers": {
"fetch": {
"command": "/path/to/fetch-mcp-rs",
"args": [
"--user-agent", "MyBot/1.0",
"--proxy-url", "http://proxy:8080",
"--log-file", "/tmp/fetch.log"
]
}
}
}工具参考
1.取回
获取URL内容,并使用可读性算法将HTML转换为Markdown。
参数:
url(字符串,必填)-要获取的URLraw(boolean,可选)-返回原始HTML而不是Markdown
例子:
{
"url": "https://example.com/article",
"raw": false
}输出:
{
"content": "# Article Title\n\nContent here...",
"url": "https://example.com/article"
}______________________________________________________________________
2.获取元数据
从URL中提取Open Graph、Schema.org和HTML元数据。
参数:
url(字符串,必填)-从中获取元数据的URL
例子:
{
"url": "https://example.com"
}输出:
{
"title": "Example Domain",
"description": "Example description",
"og_image": "https://example.com/image.jpg",
"og_title": "Example Title",
"author": "John Doe",
"published_date": "2024-01-01",
"language": "en",
"keywords": ["example", "demo"],
"twitter_card": "summary_large_image"
}______________________________________________________________________
3.饲料
解析RSS/Atom提要并提取条目。
参数:
url(字符串,必填)-源URLmax_entries(数字,可选)-返回的最大条目数(默认值:10)
例子:
{
"url": "https://example.com/feed.xml",
"max_entries": 5
}输出:
{
"title": "Blog Feed",
"description": "Latest posts",
"link": "https://example.com",
"entries": [
{
"title": "Post Title",
"link": "https://example.com/post",
"published": "2024-01-01T12:00:00Z",
"summary": "Post summary...",
"author": "Author Name"
}
]
}______________________________________________________________________
4.带选择器的fetch\_
使用CSS选择器提取特定的HTML元素。
参数:
url(字符串,必填)-要获取的URLselector(字符串,必填)-CSS选择器(例如,“div.content”、“a\[href\]”)attribute(字符串,可选)-提取特定属性而不是文本
例子:
{
"url": "https://example.com",
"selector": "a.link",
"attribute": "href"
}输出:
[
{
"text": "Link text",
"html": "Link text",
"attributes": {
"href": "/page",
"class": "link"
}
}
]______________________________________________________________________
5.可提取表
将HTML表格提取为结构化JSON。
参数:
url(字符串,必填)-要获取的URLtable_index(数字,可选)-按索引提取特定表(从0开始)
例子:
{
"url": "https://example.com/data",
"table_index": 0
}输出:
[
{
"headers": ["Name", "Age", "City"],
"rows": [
["John", "30", "NYC"],
["Jane", "25", "LA"]
]
}
]______________________________________________________________________
6.fetch_sitemap
解析sitemap.xml并提取URL。
参数:
url(字符串,必填)-网站地图URL
例子:
{
"url": "https://example.com/sitemap.xml"
}输出:
{
"urls": [
{
"loc": "https://example.com/page1",
"lastmod": "2024-01-01",
"changefreq": "weekly",
"priority": 0.8
}
],
"sitemaps": [
{
"loc": "https://example.com/sitemap2.xml",
"lastmod": "2024-01-01"
}
]
}______________________________________________________________________
7.fetch_links
使用筛选选项从页面中提取所有链接。
参数:
url(字符串,必填)-要获取的URLinternal_only(布尔值,可选)-仅内部链接(同一域)external_only(布尔值,可选)-仅外部链接(不同域)
例子:
{
"url": "https://example.com",
"internal_only": true
}输出:
{
"base_url": "https://example.com",
"links": [
{
"href": "https://example.com/page",
"text": "Page Title",
"title": "Link title",
"rel": "nofollow",
"is_internal": true
}
]
}______________________________________________________________________
8.fetch_batch
在速率限制的情况下并行获取多个URL。
参数:
urls(字符串数组,必填)-要获取的URLmax_concurrent(数量,可选)-最大并发请求数(默认值:5)timeout(数字,可选)-每个请求的超时时间(秒)(默认值:30)
例子:
{
"urls": [
"https://example.com/page1",
"https://example.com/page2",
"https://example.com/page3"
],
"max_concurrent": 3,
"timeout": 10
}输出:
[
{
"url": "https://example.com/page1",
"status": 200,
"success": true,
"content_length": 1024,
"error": null
}
]______________________________________________________________________
9.搜索_页面
使用上下文提取在页面中搜索文本。
参数:
url(字符串,必填)-要搜索的URLquery(字符串,必填)-搜索查询context_chars(数字,可选)-匹配周围的上下文字符(默认值:100)max_results(数字,可选)-返回的最大结果数(默认值:10)case_sensitive(布尔值,可选)-区分大小写的搜索(默认值:false)
例子:
{
"url": "https://example.com",
"query": "search term",
"context_chars": 50,
"max_results": 5
}输出:
{
"query": "search term",
"total_matches": 3,
"results": [
{
"match": "search term",
"context": "...text before search term text after...",
"position": 1234
}
]
}______________________________________________________________________
10.红点
使用高级过滤功能搜索Reddit帖子。
参数:
query(字符串,可选)-搜索查询(在浏览subreddit时省略)subreddit(字符串,可选)-特定子版块(例如“rust”)sort(字符串,可选)-排序方式:“热”、“新”、“顶部”、“上升”(默认:“热“)time(字符串,可选)-“顶部”的时间过滤器:“小时”、“天”、“周”、“月”、“年”、“全部”limit(数字,可选)-帖子数量(默认值:10,最大值:100)include_comments(boolean,可选)-获取顶部注释(默认值:false)comment_limit(数量,可选)-每篇帖子的最大评论数(默认值:5)
例子:
{
"query": "rust programming",
"subreddit": "rust",
"sort": "top",
"time": "week",
"limit": 5,
"include_comments": true
}输出:
[
{
"title": "Post Title",
"author": "username",
"subreddit": "rust",
"score": 123,
"url": "https://example.com",
"permalink": "https://reddit.com/r/rust/comments/...",
"selftext": "Post content...",
"created_utc": 1234567890,
"num_comments": 45,
"comments": [
{
"author": "commenter",
"body": "Comment text...",
"score": 10
}
]
}
]______________________________________________________________________
11.维基
搜索并获取维基百科文章。
参数:
action(字符串,必填)-操作:“搜索”、“摘要”、“完整”、“随机”query(字符串,可选)-搜索查询(“搜索”和“摘要”需要)limit(数字,可选)-搜索结果限制(默认值:10)language(字符串,可选)-维基百科语言代码(默认值:“en”)
示例:
搜索:
{
"action": "search",
"query": "Rust programming",
"limit": 5,
"language": "en"
}摘要:
{
"action": "summary",
"query": "Rust (programming language)"
}完整文章:
{
"action": "full",
"query": "Rust (programming language)"
}随机文章:
{
"action": "random",
"language": "en"
}输出(摘要/完整):
{
"title": "Rust (programming language)",
"extract": "Rust is a multi-paradigm...",
"url": "https://en.wikipedia.org/wiki/Rust_(programming_language)",
"content": "Full article content..." // only in "full" action
}______________________________________________________________________
12.fetch_pdf_text(可选)
从PDF文件中提取文本。
参数:
url(字符串,必填)-PDF URLmax_pages(数字,可选)-要提取的最大页面数(默认值:全部)
要求: pdf 功能已启用(默认)
______________________________________________________________________
13.fetch_image_info(可选)
在不完全下载的情况下获取图像元数据。
参数:
url(字符串,必填)-图像URL
要求: images 功能已启用(默认)
______________________________________________________________________
功能配置
默认功能
default = ["pdf", "images"]构建无可选功能
# No PDF support
cargo build --no-default-features
# Only PDF, no images
cargo build --no-default-features --features pdf
# Full features
cargo build --features full发展
运行测试
cargo test构建发布
cargo build --release启用调试日志
RUST_LOG=debug cargo run建筑
模块
- main.rs -带有13个工具实现的MCP服务器
- fetch.rs -具有缓存和速率限制的核心HTTP客户端
- html_convert.rs -可读性+html2text转换
- 元数据.rs -HTML元标记提取(Open Graph,Schema.org)
- feed.rs -RSS/Atom/JSON提要解析
- 选择器.rs -CSS选择器提取
- 网站地图.rs -网站地图XML解析
- links.rs -链接提取与过滤
- batch.rs -具有并发控制的并行取数
- search.rs -带上下文的页面内文本搜索
- reddit.rs -Reddit JSON API客户端
- wiki.rs -维基百科媒体维基API客户端
- 机器人 -robots.txt验证
- logging.rs -传输感知日志记录
依赖项
核心:
rmcp 0.9.1-带有新API的MCP SDKreqwest 0.12-HTTP客户端tokio 1.48-异步运行时
HTML/内容:
readability 0.3-内容提取scraper 0.24-HTML解析html2text 0.16-HTML到文本转换
馈送和数据:
feed-rs 2.3-提要解析webpage 2.0-元数据提取quick-xml 0.38-XML解析
可选:
lopdf 0.38-PDF文本提取image 0.25-图像处理
演出
cached 0.56-内存缓存governor 0.10-速率限制
许可证
MIT许可证-有关详细信息,请参阅许可证文件。
贡献
欢迎投稿!拜托:
- 复刻仓库
- 创建要素分支
- 添加新功能的测试
- 确保
cargo test通过 - 提交拉取请求
路线图
- \[\]HTTP流模式实现
- \[\]屏幕截图支持
- \[\]JavaScript渲染(无头浏览器)
- \[\]Archive.org Wayback机器集成
- \[\]自定义标头支持
- \[\]Cookie持久性
- \[\]重试策略
- \[\]大文件的响应流
支持
- 问题:https://github.com/ssoj13/fetch-mcp-rs/issues
- 讨论:https://github.com/ssoj13/fetch-mcp-rs/discussions
