# 怎样把 MCP 的小红书搜索响应转换成表格数据

[规范网址](https://social2api.com/guides/rednote-mcp-rednote-result-json-to-table/)

先解析 MCP result.content 中的 JSON，再按 columns 和 rows 输出表格并保留 warnings。

## Agent 提示词

~~~~text
请在 Social2api 使用Social2api 的 MCP 取数服务，执行以下任务。
目标：解析 search_rednote 返回的 JSON 文本并生成可归档的行。
输入与对照示例：样例解析。调用参数用「城市骑行」和 2026-01-15 的单日窗口。解析首个文本内容后，以 ID、标题、日期三列写入暂存表。
检查客户端是否支持 MCP，使用已授权的连接或凭据。核对免费示例与实时模式。
按以下步骤完成：通过工具列表确认 search_rednote 已授权 调用工具时在 arguments 中显式传 mode=demo、query、since 与 until 解析 result.content 中的 JSON 文本，将 rows 映射成列并单独保存错误与警告
交付能核对的结果和必要字段：result.isError、result.content[].text、columns、rows、warnings。注明来源或限制，并以本页为操作参考。
https://social2api.com/guides/rednote-mcp-rednote-result-json-to-table/
~~~~

[查看 MCP 接入文档](https://social2api.com/docs/api/mcp/)

## 本页用到的 Social2api 接口

| 接口与参数文档 | 用途 |
| --- | --- |
| [调用 MCP 服务](https://social2api.com/docs/api/mcp/) · POST /mcp | 使用 JSON-RPC 查找并调用与密钥授权范围相符的取数工具。 |
| [小红书公开笔记搜索](https://social2api.com/docs/api/rednote-notes-search/) · POST /api/run · task=rednote | 按关键词搜索公开笔记，并可用发布日期和结果条数收窄范围。 |

## 在 Social2api 使用Social2api 的 MCP 取数服务

1. 通过工具列表确认 search\_rednote 已授权
2. 调用工具时在 arguments 中显式传 mode=demo、query、since 与 until
3. 解析 result.content 中的 JSON 文本，将 rows 映射成列并单独保存错误与警告

## 复制请求并试跑

用 HTTP 合成响应核对单日笔记行和 ID、标题、日期列，MCP 的文本包装由授权客户端另外验收。

这条请求使用合成样例，免登录、免 API Key，上游请求数为 0。要查真实数据，将 mode 改为 live，换成实际输入，并在 Authorization 中提供有相应任务权限的 Bearer API Key。可用 maxRequests 限制实时上游请求数。

~~~~bash
curl --fail-with-body -sS 'https://social2api.com/api/run' \
  -H 'Content-Type: application/json' \
  --data-binary @- <<'JSON'
{
  "task": "rednote",
  "mode": "demo",
  "params": {
    "query": "城市骑行",
    "limit": 4,
    "since": "2026-01-15",
    "until": "2026-01-15"
  }
}
JSON
~~~~

## 用 MCP 工具原始回包生成三列 CSV

使用具有对应任务权限的 Social2api Key。以下脚本明确发送 demo，可验收 JSON-RPC 和 MCP 文本包装，样例实际发往上游的请求数为 0。留存 JSON 回包并输出 CSV。服务错误和工具 isError 分开处理，两种错误均停止导出。

如果客户端只显示普通 JSON rows，先确认调用的是 /mcp。读取 tools/list 才能验证当前连接可见的工具。工具 live 请求另行配置授权和 maxRequests。

~~~~bash
set -euo pipefail
: "${SOCIAL2API_API_KEY:?请设置获准该任务的 Social2api Key}"
rpc() {
  curl -fsS 'https://social2api.com/mcp' \
    -H "Authorization: Bearer $SOCIAL2API_API_KEY" \
    -H 'Content-Type: application/json' \
    -H 'MCP-Protocol-Version: 2025-11-25' \
    --data-binary "$1"
}
rpc '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"csv-check","version":"1"}}}' |
  jq -e '.result.protocolVersion' >/dev/null
rpc '{"jsonrpc":"2.0","method":"notifications/initialized"}' >/dev/null
rpc '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' |
  jq -e '.result.tools | any(.name == "search_rednote")' >/dev/null
rpc '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"search_rednote","arguments":{"mode":"demo","query":"城市骑行","since":"2026-01-15","until":"2026-01-15","limit":1}}}' > mcp-result.json
jq -er '
  if .error then error(.error.message)
  elif .result.isError then error(.result.content[0].text)
  else .result.content[] | select(.type == "text") | .text | fromjson end
  | if .mode != "demo" or .requestCount != 0 then error("Expected a demo response") else . end
  | (["id","title","publishedAt"], (.rows[] | [.id, .title, .publishedAt])) | @csv
' mcp-result.json > result.csv
~~~~

## 操作示例与核对

样例解析。调用参数用「城市骑行」和 2026-01-15 的单日窗口。解析首个文本内容后，以 ID、标题、日期三列写入暂存表。

## 需要核对的字段

result.isError、result.content\[\].text、columns、rows、warnings。

## 接口文档

- [调用 MCP 服务](https://social2api.com/docs/api/mcp/)
- [小红书公开笔记搜索](https://social2api.com/docs/api/rednote-notes-search/)

## 相关用户讨论

- [用户讨论 · 小红书 · 获取小红书笔记、评论的工具是否支持 Claude Code？](https://x.com/cnyzgkc/status/2039264634348458207)
- [用户讨论 · 小红书 · 怎样把小红书结果映射到飞书字段并做增量更新？](https://x.com/tangpingxiaobai/status/2078390775889658092)

## 相关指南和问答

- [如何按关键词搜索小红书笔记并导出 CSV](https://social2api.com/guides/xiaohongshu-keyword-search-export/)

[查看 MCP 接入文档](https://social2api.com/docs/api/mcp/)
