简介本文档介绍如何在 Cursor 编辑器中设置规则(rules)并使用 mcp 工具,实现基于 Manus 的研究工作流。Manus 研究方式是一种结构化的任务处理方法,通过明确的步骤、工具和文件组...
本文档介绍如何在 Cursor 编辑器中设置规则(rules)并使用 mcp 工具,实现基于 Manus 的研究工作流。Manus 研究方式是一种结构化的任务处理方法,通过明确的步骤、工具和文件组织方式来高效完成数据分析和研究任务。
Cursor Rules 是提供给 AI 助手的额外上下文和指导,让 AI 更好地理解用户的需求和代码库。通过设置 Rules,我们可以自定义 AI 助手的行为模式,使其按照我们期望的方式工作。
在项目根目录下创建一个 .cursor
目录(如果不存在的话),然后在该目录下创建一个规则文件。常见的规则文件格式有:
.mdc
(Markdown 文件)
.py
(Python 文件)
.json
(JSON 文件)
对于 Manus 研究方式,我们创建名为 formanus.mdc
的文件:
mkdir -p .cursor
touch .cursor/formanus.mdc
编辑 formanus.mdc
文件,添加以下内容:
# 使用manus的方式研究
- You can @ files here
- You can use markdown but dont have to
- You are a assistant, when you get a task, you will do it step by step. you will generate a todo.md, and you will update it when you finish a step.
- If you get data analysis task, you will use Python-based data science
- Use Python 3.12 as the primary programming language
- Use NumPy for numerical computing and array operations
- Use Pandas for data manipulation and analysis
- Use conda for environment and package management
- Use Dash for web based report
- Use a seperated file to Generate a web based report, pretty, modern and interactive
- Run a web server And give me the url
- Use Website Preview and firecrawl to get web content
- Use a seperated file to store project summary
- Use a seperated file to store todo list
- Use a seperated directory to store all files from one task
- Store all process data in files under the task directory
这个规则定义了以下主要内容:
任务处理方式:逐步执行,维护 todo.md 记录进度
技术栈选择:Python 3.12, NumPy, Pandas, conda
报告生成:使用 Dash 创建交互式网页报告
文件组织:为每个任务创建独立目录,分离存储项目摘要、任务列表和处理数据
创建规则后,可以通过以下方式验证规则是否生效:
在 Cursor 中打开一个新的聊天窗口
询问 AI 关于当前规则的内容
AI 应该能够识别并引用 formanus 规则
Manus 研究方式中的一个重要组成部分是使用 mcp 工具(尤其是 firecrawl 相关功能)获取网页内容。以下是使用这些工具的方法:
使用mcp__firecrawl_scrape工具抓取单个网页内容:
- url参数指定要抓取的网页URL
- formats参数可以指定返回格式,如markdown、html等
- onlyMainContent设为true可以过滤掉导航栏、页脚等内容
使用mcp__firecrawl_search工具搜索网络内容:
- query参数指定搜索查询
- limit参数限制返回结果数量
- 可以通过scrapeOptions参数指定是否需要抓取搜索结果的详细内容
使用mcp__firecrawl_deep_research工具进行深入研究:
- query参数指定研究主题
- maxDepth参数控制研究深度
- maxUrls参数限制分析的URL数量
以下是一个典型的 Manus 研究工作流程:
接收任务:得到一个研究或数据分析任务
创建任务目录和初始文件:
mkdir task_name
cd task_name
touch todo.md project_summary.md
生成初始 todo 列表:在 todo.md 中列出任务步骤
数据获取:使用 firecrawl 相关工具获取 Web 内容或其他数据源
数据处理:使用 Python、Pandas 等工具进行数据清洗和分析
报告生成:使用 Dash 创建交互式 Web 报告
运行 Web 服务器:展示分析结果
更新任务进度:不断更新 todo.md 反映完成情况
假设我们有一个分析某公司股票价格趋势的任务:
创建目标文件和初始 todo.md
使用 firecrawl 获取股票历史数据
使用 Pandas 处理数据
使用 Dash 创建交互式可视化
生成分析报告和结论
下面我们通过一个完整的示例,展示如何使用 Manus 研究方式结合 MCP 工具进行数据分析:
假设我们要分析某科技公司(如 Apple)的市场表现和新闻情况:
首先创建任务目录和初始文件:
mkdir apple_market_analysis
cd apple_market_analysis
touch todo.md project_summary.md
初始化 todo.md 文件内容:
# Apple市场分析任务清单
- [ ] 获取Apple公司基本信息
- [ ] 搜集最近一个月的Apple相关新闻
- [ ] 获取Apple股票价格数据
- [ ] 分析股价与新闻事件的相关性
- [ ] 使用Dash创建交互式数据可视化
- [ ] 生成分析报告
# 在Cursor聊天窗口中使用以下方式调用工具:
# 获取Apple公司的基本信息
使用mcp__firecrawl_scrape工具:
- url: "https://en.wikipedia.org/wiki/Apple_Inc."
- formats: ["markdown"]
- onlyMainContent: true
Cursor 会调用 firecrawl_scrape 工具并返回 Apple 公司的维基百科页面内容。将返回的内容保存到文件:
# 将结果保存到文件
with open('apple_info.md', 'w') as f:
f.write(scrape_result)
# 搜索Apple公司相关的最新新闻
使用mcp__firecrawl_search工具:
- query: "Apple Inc. news last month financial performance"
- limit: 10
- scrapeOptions:
- formats: ["markdown"]
- onlyMainContent: true
将搜索结果保存:
# 将新闻搜索结果保存到文件
with open('apple_news.md', 'w') as f:
f.write(news_results)
我们可以使用 firecrawl_scrape 获取 Yahoo Finance 上的股票数据:
# 获取Apple股票数据
使用mcp__firecrawl_scrape工具:
- url: "https://finance.yahoo.com/quote/AAPL/history/"
- formats: ["html"]
- onlyMainContent: true
创建一个数据处理脚本:
# 创建名为process_data.py的文件
import pandas as pd
import numpy as np
import re
from datetime import datetime
# 处理股票数据
def extract_stock_data(html_content):
# 使用pandas从HTML中提取表格数据
tables = pd.read_html(html_content)
stock_data = tables[0] # 假设股票历史数据在第一个表格
# 清洗和处理数据
stock_data['Date'] = pd.to_datetime(stock_data['Date'])
stock_data.sort_values('Date', inplace=True)
# 保存处理后的数据
stock_data.to_csv('apple_stock_data.csv', index=False)
return stock_data
# 处理新闻数据
def process_news(news_content):
# 简单的正则表达式提取日期和标题
pattern = r'(\d{1,2}\s+[A-Za-z]+\s+\d{4}).*?([A-Z].*?)(?=\n)'
matches = re.findall(pattern, news_content)
if matches:
news_data = []
for date_str, title in matches:
try:
date = datetime.strptime(date_str, '%d %B %Y')
news_data.append({'Date': date, 'Title': title})
except ValueError:
continue
news_df = pd.DataFrame(news_data)
news_df.to_csv('apple_news_processed.csv', index=False)
return news_df
return pd.DataFrame()
# 分析股价与新闻的相关性
def analyze_correlation(stock_df, news_df):
# 合并数据集
merged_data = pd.merge_asof(
stock_df.sort_values('Date'),
news_df.sort_values('Date'),
on='Date',
direction='nearest'
)
# 简单分析:计算有新闻和无新闻天的股价变化差异
with_news = merged_data.dropna(subset=['Title'])
without_news = merged_data[~merged_data.index.isin(with_news.index)]
avg_change_with_news = with_news['Close'].pct_change().mean()
avg_change_without_news = without_news['Close'].pct_change().mean()
results = {
'avg_change_with_news': avg_change_with_news,
'avg_change_without_news': avg_change_without_news,
'difference': avg_change_with_news - avg_change_without_news
}
with open('correlation_analysis.txt', 'w') as f:
for k, v in results.items():
f.write(f"{k}: {v}\n")
return results
# 主函数
def main():
with open('apple_stock_data.html', 'r') as f:
html_content = f.read()
with open('apple_news.md', 'r') as f:
news_content = f.read()
stock_df = extract_stock_data(html_content)
news_df = process_news(news_content)
if not news_df.empty:
results = analyze_correlation(stock_df, news_df)
print("分析完成,结果已保存到correlation_analysis.txt")
if __name__ == "__main__":
main()
创建一个 Dash 应用来展示分析结果:
# 创建名为visualization.py的文件
import dash
from dash import dcc, html
import plotly.graph_objs as go
import pandas as pd
import numpy as np
from datetime import datetime, timedelta
# 加载数据
stock_data = pd.read_csv('apple_stock_data.csv')
stock_data['Date'] = pd.to_datetime(stock_data['Date'])
news_data = pd.read_csv('apple_news_processed.csv')
news_data['Date'] = pd.to_datetime(news_data['Date'])
# 初始化Dash应用
app = dash.Dash(__name__)
# 创建布局
app.layout = html.Div([
html.H1("Apple公司市场表现分析"),
html.Div([
html.H2("股票价格走势"),
dcc.Graph(
id='stock-price-chart',
figure={
'data': [
go.Scatter(
x=stock_data['Date'],
y=stock_data['Close'],
mode='lines',
name='收盘价'
)
],
'layout': go.Layout(
xaxis={'title': '日期'},
yaxis={'title': '价格'},
hovermode='closest'
)
}
)
]),
html.Div([
html.H2("新闻事件与股价关系"),
dcc.Graph(
id='news-stock-chart',
figure={
'data': [
go.Scatter(
x=stock_data['Date'],
y=stock_data['Close'],
mode='lines',
name='收盘价'
),
go.Scatter(
x=news_data['Date'],
y=[stock_data.loc[stock_data['Date'] == date, 'Close'].values[0]
if any(stock_data['Date'] == date) else np.nan
for date in news_data['Date']],
mode='markers',
marker={'size': 10, 'color': 'red'},
name='新闻事件'
)
],
'layout': go.Layout(
xaxis={'title': '日期'},
yaxis={'title': '价格'},
hovermode='closest'
)
}
)
]),
html.Div([
html.H2("新闻列表"),
html.Ul([
html.Li([
html.Span(f"{row['Date'].strftime('%Y-%m-%d')}: "),
html.Span(row['Title'])
]) for _, row in news_data.iterrows()
])
])
])
# 运行服务器
if __name__ == '__main__':
app.run_server(debug=True)
完成上述步骤后,更新 todo.md 文件:
# Apple市场分析任务清单
- [x] 获取Apple公司基本信息
- [x] 搜集最近一个月的Apple相关新闻
- [x] 获取Apple股票价格数据
- [x] 分析股价与新闻事件的相关性
- [x] 使用Dash创建交互式数据可视化
- [x] 生成分析报告
创建项目摘要文件:
# Apple市场分析项目摘要
## 项目目标
分析Apple公司股票价格与新闻事件的关系,探索市场新闻对股价的影响。
## 数据来源
- Apple公司基本信息:维基百科
- 股票数据:Yahoo Finance
- 新闻数据:搜索引擎结果
## 主要发现
1. 新闻发布日的股价波动比非新闻日平均高出X%
2. 积极新闻与股价上涨有明显相关性
3. 产品发布相关新闻对股价影响最大
## 工具与方法
- 数据获取:MCP Firecrawl工具
- 数据处理:Pandas
- 数据可视化:Dash和Plotly
## 结论
通过分析发现,Apple公司的重大新闻事件确实会对股价产生短期影响,特别是产品发布和财报相关的新闻。投资者可以利用这一发现进行投资决策。
## 下一步研究方向
1. 扩大时间范围,分析长期趋势
2. 加入情感分析,区分积极/消极新闻的影响
3. 比较Apple与其他科技公司的情况
python visualization.py
服务器运行后,可以通过浏览器访问 http://localhost:8050 查看交互式数据可视化。
Q: 如何确认我的 Cursor 规则已经生效?
A: 在 Cursor 聊天窗口中,询问 AI 关于当前规则的内容。例如:"请告诉我当前的 formanus 规则内容是什么?"如果 AI 能够正确回答,说明规则已生效。
Q: 我可以同时设置多个规则吗?
A: 是的,你可以在 .cursor
目录下创建多个规则文件,Cursor 会根据上下文和需求应用相应的规则。
Q: 规则文件支持哪些格式?
A: Cursor 规则主要支持以下格式:
.mdc
(Markdown)
.py
(Python)
.json
(JSON)
其他文本格式
Q: firecrawl 工具是否会记住之前的会话上下文?
A: 不会,每次调用 firecrawl 工具都是独立的,不会保留之前会话的上下文。因此,在连续使用时需要手动保存和传递必要的信息。
Q: 使用 firecrawl_search 时如何获得更精确的结果?
A: 使用更具体的搜索词,并利用以下参数优化搜索:
添加地理位置参数(country)
设置语言参数(lang)
使用时间筛选(tbs)
限制结果数量(limit)
Q: 网站内容抓取被阻止怎么办?
A: 有些网站可能会阻止自动抓取。在这种情况下,你可以:
使用 skipTlsVerification: true
参数(如果问题是 SSL 证书相关)
尝试设置 mobile: true
来模拟移动设备
添加等待时间 waitFor: 5000
(以毫秒为单位)让动态内容加载
对于需要交互的网站,使用 actions
参数模拟点击、滚动等操作
Q: 推荐的 conda 环境设置是什么?
A: 以下是一个示例的 environment.yml
文件,适用于 Manus 研究方式:
name: manus_research
channels:
- conda-forge
- defaults
dependencies:
- python=3.12
- pandas
- numpy
- dash
- plotly
- jupyterlab
- scikit-learn
- matplotlib
- seaborn
- requests
- beautifulsoup4
- nltk
- pip
- pip:
- dash-bootstrap-components
Q: 如何处理大量数据导致的性能问题?
A: 处理大数据集时的建议:
使用数据采样进行初步分析
考虑使用 dask
或 vaex
等库处理超大规模数据
实现增量处理逻辑,分批处理数据
优化数据类型(如使用 categoricals、减少精度等)
实现缓存机制,避免重复计算
Q: Dash 应用如何部署到生产环境?
A: Dash 应用的部署选项:
使用 Heroku:heroku create && git push heroku main
使用 AWS Elastic Beanstalk
使用 Docker 容器化:创建 Dockerfile 并部署到任何支持 Docker 的服务
本地部署:使用 Gunicorn 作为 WSGI 服务器 gunicorn app:server
Q: 如何有效地组织多个相关研究任务?
A: 建议采用以下方式组织多个相关任务:
创建一个主项目目录
在其下创建子目录,每个子目录对应一个具体任务
创建一个主摘要文件,链接到各个子任务
使用版本控制(如 Git)跟踪所有变更
维护一个统一的数据字典,记录所有数据字段的含义和来源
Q: 如何在团队中共享 Manus 研究方式?
A: 团队协作的最佳实践:
将 .cursor
目录加入版本控制
创建项目级的 README,说明工作流程和规则
标准化文件命名和目录结构
使用共享的 conda 环境定义
创建模板脚本作为起点
定期同步和讨论 todo.md 的更新情况
Q: 如何自动化重复性任务?
A: 自动化 Manus 工作流的方法:
创建可重用的 Python 模块封装常见功能
使用 Airflow 或 luigi 等工具构建数据处理管道
设置 GitHub Actions 自动运行分析和生成报告
创建自定义的命令行工具简化操作
实现自动化测试确保分析质量
通过在 Cursor 中设置 formanus 规则并结合 mcp 工具,我们可以实现结构化、高效的研究工作流程。这种方式的优点包括:
任务透明度高:通过 todo.md 可以清晰跟踪进度
工具链统一:使用一致的技术栈进行分析
结果可视化强:通过 Dash 生成交互式报告
文件组织清晰:每个任务独立存储,结构明确
网络内容获取便捷:集成 firecrawl 等工具
通过这种方式,可以极大提高研究和数据分析任务的效率和质量。