【墨言开发文档】【小红书笔记发布MCP服务】使用说明

194 阅读3分钟

摘要:【墨言】不止是个科学与工程计算软件,用它同样可以玩转MCP,本文介绍了在【墨言】中操作MCP的一个示例:【小红书笔记发布】

一、服务来源

💡 xhs-mcp-server

二、功能总览

💡 该 MCP 服务器提供以下工具函数:

  1. 📚 创建图片笔记
  2. 📚 创建视频笔记

三、运行环境

💡 该 MCP 服务器依赖于以下运行环境:

  1. Python 3.10+
  2. Node.js 16.0.0+
  3. npm
  4. 安装python3后使用指令安装uv "pip install uv"

四、安装步骤

  1. 安装chromedriver
npx @puppeteer/browsers install chromedriver@134.0.6998.166
  1. 安装小红书服务
pip install xhs-mcp-server
  1. 在【墨言】MCP配置json文件中更改 Python.exe 文件的位置,填写你的小红书注册手机号:
    "小红书自动发布MCP": {
      "command": "C:/Users/Administrator/AppData/Local/Programs/Python/Python312/Python.exe",
      "args": [
        "-m",
        "xhs_mcp_server"
      ],
      "env": {
        "phone": "18800008888"
      }
    },

🔥 一键安装的方法

在【墨言】软件中运行以下代码,可以一键执行以上安装步骤:

// 第一步:安装
执行操作系统命令批处理(【"npx @puppeteer/browsers install chromedriver@135.0.7049.96 | pip install xhs-mcp-server"】)

// 第二步:在json中修改Python.exe文件的位置和小红书注册手机号
MCP配置文件路径 = MCP配置Json文件地址()
打开MCP配置文件 = 连接字符串(【"notepad.exe "】, 【MCP配置文件路径】)
执行操作系统命令批处理(【打开MCP配置文件】)

五、MCP工具函数用法

在【墨言】软件中执行以下代码,就可以查询得到本MCP的所有工具函数:

获取预置MCP服务Json配置(【"小红书自动发布MCP"】) 保存到:【发布Json字串】
创建MCP服务执行器(【发布Json字串】) 保存到:【发布服务执行器】

获取MCP服务的工具列表(【发布服务执行器】)

执行结果显示,该MCP服务共有2个工具函数 create_note 和 create_video_note。

create_note():Create a note (post) to xiaohongshu (rednote) with title, description, and images

    Args:
        title: the title of the note (post), which should not exceed 20 words
        content: the description of the note (post).
        images: the list of image paths or URLs to be included in the note (post)
    
create_video_note():Create a note (post) to xiaohongshu (rednote) with title, description, and videos

    Args:
        title: the title of the note (post), which should not exceed 20 words
        content: the description of the note (post).
        videos: the list of video paths or URLs to be included in the note (post)

🔍 以下是这些工具函数的使用示例:

create_note(title, content, images)函数。

【墨言】执行语法示例:

// 填写你自己的小红书注册手机号,登录小红书帐号:
执行操作系统命令(【"set phone=18800008888&& python.exe -m xhs_mcp_server.__login__"】)

// 创建小红书服务
获取预置MCP服务Json配置(【"小红书自动发布MCP"】) 保存到:【发布Json字串】
创建MCP服务执行器(【发布Json字串】) 保存到:【发布服务执行器】

// 执行小红书服务
执行MCP服务的工具函数(【发布服务执行器】,【"create_note"】,【"['title'|'你的笔记标题'];['content'|'你的笔记文本内容'];['images'|['d:\images\pic1.jpg'|'d:\images\pic2.jpg'|'d:\images\pic3.jpg']]"】) 保存到:【小红书执行结果】

以上程序首次执行时,需要用手机收验证码登录一次,第二次执行时就不需要验证码了。

执行成功后,就能看到你的小红书中增加了一条笔记啦。

🔍 录像教程:

player.bilibili.com/player.html…