Writer Context Tool for Claude 使用说明
项目简介
Writer Context Tool 是一个基于 Model Context Protocol (MCP) 的服务器实现,旨在将您的 Substack 和 Medium 写作内容连接到 Claude 桌面应用,作为 Claude 的上下文信息来源。通过这个工具,Claude 可以理解您的写作背景,从而为您提供更个性化的写作辅助。
主要功能点
- 博客文章检索与缓存: 自动从您配置的 Substack 和 Medium 博客抓取文章,并进行本地永久缓存,断网后也能使用。
- 语义搜索: 利用文章内容生成嵌入向量,支持基于语义的写作内容搜索,快速找到相关文章。
- 文章资源化: 将每篇文章作为独立的资源提供给 Claude,方便 Claude 直接访问和引用您的具体文章。
- 内容预加载与启动: 在服务器启动时自动预加载所有内容并生成嵌入向量,无需手动操作,即开即用。
- 内容刷新: 提供手动刷新内容工具,确保 Claude 访问到最新的写作内容。
安装步骤
-
克隆仓库
git clone https://github.com/jonathan-politzki/mcp-writer-substack.git cd mcp-writer-substack -
配置 Python 环境 推荐使用 'uv' (更快速的 Python 包管理器):
# 如果没有 uv,先安装 uv curl -LsSf https://astral.sh/uv/install.sh | sh # 创建虚拟环境并安装依赖 uv venv source .venv/bin/activate # 或 .venv\Scripts\activate (Windows) uv pip install -r requirements.txt或者使用标准的 'pip':
python -m venv .venv source .venv/bin/activate # 或 .venv\Scripts\activate (Windows) pip install -r requirements.txt -
配置博客信息
- 复制配置文件示例并重命名:
cp config.example.json config.json - 编辑 'config.json' 文件,填入您的 Substack 和 Medium 博客 URL。例如:
{ "platforms": [ { "type": "substack", "url": "https://yourusername.substack.com", "name": "我的 Substack 博客" }, { "type": "medium", "url": "https://medium.com/@yourusername", "name": "我的 Medium 博客" } ], "max_posts": 100, "cache_duration_minutes": 10080, "similar_posts_count": 10 }- 'platforms': 配置博客平台,支持 'substack' 和 'medium',可配置多个。
- 'url': 博客的 URL 地址。
- 'name': 为博客自定义名称,方便识别。
- 'max_posts': 每个平台抓取的最大文章数量,默认为 100。
- 'cache_duration_minutes': 缓存有效期,单位分钟,默认为一周 (10080 分钟)。
- 'similar_posts_count': 搜索时返回最相关文章的数量,默认为 10。
- 复制配置文件示例并重命名:
-
配置 Claude 桌面应用
-
创建 Claude 桌面应用的配置目录(如果不存在):
# macOS mkdir -p ~/Library/Application\ Support/Claude/ -
创建或编辑 Claude 桌面应用的配置文件 'claude_desktop_config.json',填入以下内容:
{ "mcpServers": { "writer-tool": { "command": "/path/to/your/uv", // 请替换为 uv 命令的绝对路径,例如 /Users/yourusername/.local/bin/uv "args": [ "--directory", "/path/to/mcp-writer-substack", // 请替换为 mcp-writer-substack 仓库的绝对路径 "run", "writer_tool.py" ] } } }配置参数说明:
- 'server name': 'writer-tool',服务器名称,Claude 桌面应用中会显示此名称。
- 'command': MCP 服务器的启动命令,这里配置为 'uv' (或 'python') 命令的绝对路径。如果您使用 'pip' 安装,则需要将 'command' 替换为 Python 解释器的绝对路径,例如 '/usr/bin/python3',并将 'args' 中的 '--directory' 和 'run' 参数移除。
- 'args': 启动命令的参数列表。
- '--directory': 指定 MCP 服务器的工作目录,设置为仓库的绝对路径。
- 'run writer_tool.py': 运行 'writer_tool.py' 脚本启动服务器。
注意: 请务必将 'command' 和 '--directory' 参数替换为您的实际路径。您可以使用 'which uv' (或 'which python3') 命令查找 'uv' (或 'python3') 的绝对路径,使用 'pwd' 命令在仓库目录下查找仓库的绝对路径。
-
-
重启 Claude 桌面应用 重启 Claude 桌面应用后,Writer Context Tool 应该会自动连接。
基本使用方法
- 搜索写作内容: 在 Claude 中提问,例如 "查找关于 [特定主题] 的文章" 或 "我写过关于 [主题] 的哪些内容?"。Claude 会使用 'search_writing' 工具搜索您的博客文章,并返回相关结果。
- 访问特定文章: 在搜索结果中,您可以点击文章标题访问文章全文。或者,您可以让 Claude "显示 [文章标题] 的全文"。Claude 会使用 'essay' 资源获取并显示文章内容。
- 刷新内容: 如果您更新了博客文章,或者想确保 Claude 使用最新的内容,可以告诉 Claude "刷新我的写作内容"。Claude 会调用 'refresh_content' 工具刷新缓存。
可用工具和资源
- 文章资源 (Individual Essay Resources): 每篇博客文章都作为一个独立的资源提供,URI 格式为 'mcp://writer-tool/essay/{文章ID}'。
- 文章列表资源 (Essays List Resource): 提供所有文章的资源列表,URI 为 'mcp://writer-tool/essays'。
- 文章索引资源 (Essays Index Resource): 提供所有文章的 Markdown 格式索引,URI 为 'mcp://writer-tool/essays-index'。
- 搜索工具 (search_writing): 用于在您的写作内容中进行语义搜索。
- 刷新工具 (refresh_content): 用于强制刷新博客内容缓存。
信息
分类
生产力应用