Skip to main content
Glama
go0le

pixiv-mcp

by go0le

pixiv-mcp

独立的 Pixiv 插画搜索 / 过滤 / 下载工具,提供三种用法:

  • MCP server(stdio):给 Codex CLI、Claude Desktop / Claude Code、Cursor、Grok Bot 等任意支持 MCP 的 agent 用

  • CLI:pixiv-mcp search 信浓 泳装 2,方便测试,也给不支持 MCP 的 agent 用

  • TypeScript 库:import { PixivService, pixivSearch } from 'pixiv-mcp'

它是从 QQ bot 插件(dsh-qqbot 的 src/pixiv)里拆出来的,过滤规则一条没改,不依赖 QQ bot、cordis/cosmokit、antigravity、会话或传输层。规则细节见 pixiv-feature-spec.md。

运行时依赖只有 @modelcontextprotocol/sdk 和 zod。网络请求用 Node 自带的 fetch,不处理图片、不用浏览器。

安装

需要 Node.js ≥ 20.3(推荐 22 或 24)。

发布包里已经带了编译好的 dist/,服务器上不需要 TypeScript 或 vitest:

tar xzf pixiv-mcp.tgz && cd pixiv-mcp
npm ci --omit=dev          # 只装运行时依赖(约 26 MB)
node dist/bin.js --help

开发 / 改代码:

npm ci
npm run build              # tsc → dist/,bin 入口为 dist/bin.js
npm test                   # 会先 build,再跑 vitest(含 stdio 端到端测试)
npm run typecheck

想要全局命令 pixiv-mcp 时,在目录里执行 npm link 或 npm i -g .。

低内存启动(2 vCPU / 1 GB 机器)

node --max-old-space-size=96 --max-semi-space-size=1 dist/bin.js serve

实测(Linux,Node 24,接本地模拟的 Pixiv):

启动参数

空闲 RSS

跑 20 轮搜索+下载后 RSS(峰值)

--max-old-space-size=128

77 MB

105 MB(107)

--max-old-space-size=96 --max-semi-space-size=1

69 MB

94 MB(100)

再加 --lite-mode

59 MB

68 MB(70),但速度慢很多,不推荐

光是加载官方 MCP SDK 的 stdio 部分(它会带上 zod 协议 schema)就要约 64 MB RSS,裸 Node 约 41 MB,所以用官方 SDK 时 60 MB 以下基本做不到。原图下载是流式写盘的,不会把整张图读进内存。

Related MCP server: ZeroChan MCP

环境变量

变量

说明

PIXIV_REFRESH_TOKEN

Pixiv refresh token。配了且没设 PIXIV_PROXY_BASE_URL 时走 app-api(推荐,R-18 需要登录)

PIXIV_PHPSESSID / PIXIV_COOKIE

网页登录态,加到网页 AJAX 请求的 Cookie 上

PIXIV_PROXY_BASE_URL

www.pixiv.net 的反代源站(路径同网页 AJAX)。设了它就始终走网页接口

PIXIV_MCP_HOME

数据目录,默认 ~/.pixiv-mcp(Windows:C:\Users\<你>\.pixiv-mcp),存历史、元数据、动态标签表

PIXIV_MEDIA_DIR

图片目录,默认 $PIXIV_MCP_HOME/media

PIXIV_COOLDOWN_MS

每个 session 的冷却,默认 15000;设 0 关闭

PIXIV_DOWNLOAD_CONCURRENCY

全局同时下载数,默认 2

PIXIV_MAX_IMAGE_MB

单张原图上限,默认 50

PIXIV_CACHE_MAX_MB

本地图片缓存上限,超出按最久未用淘汰,默认 512

PIXIV_TIMEOUT_MS

单次请求超时,默认 15000(下载为它的 2 倍)

PIXIV_LLM_TAGS=1

可选:把没映射的中文词交给 OpenAI 兼容模型翻成 Pixiv 标签

PIXIV_LLM_BASE_URL / PIXIV_LLM_API_KEY / PIXIV_LLM_MODEL

上一项用到的接口,如 https://api.openai.com/v1、sk-...、gpt-4o-mini

NODE_USE_ENV_PROXY=1 + HTTPS_PROXY

需要走 HTTP 代理时用(Node ≥ 24 的原生 fetch 支持),图片下载同样走代理

LLM 不是必须的。 推荐让调用方 agent 自己把中文描述翻成 Pixiv 常用日文标签再传进来(比如 水手服→セーラー服)。内置的中文角色映射表照样生效,没映射的词按原样当标签用。

怎么拿 refresh token

Pixiv 没有官方开发者入口,refresh token 只能从官方 App 的 OAuth 登录流程里拿:

  1. gppt(最省事,会开一个浏览器让你登录):pip install gppt,然后运行 gppt login-interactive(或 gppt login -u 邮箱 -p 密码),输出里的 refresh_token 就是。

  2. pixiv_auth.py(ZipFile 的 gist,“Retrieving Auth Token (with Selenium)”那篇):运行 python pixiv_auth.py login,在浏览器里登录,再按说明从开发者工具的网络面板里复制 code,脚本会换出 refresh_token。

拿到之后填进 PIXIV_REFRESH_TOKEN。它长期有效,本工具会自动换 access token 并缓存。token 失效时自动退回网页搜索,日志写到 stderr。

MCP 工具

工具

作用

pixiv_search

搜索并下载。参数:tags(数组或空格分隔字符串,多个标签是 AND)、count(1–3)、r18、allow_gray(oral / creampie / paizuri / footjob / ahegao / sex / r18)、session(去重和冷却按它分开)

pixiv_illust_detail

按 PID 读元数据,并用同一套规则给出 compliant 结论,不下载

pixiv_download

按 PID 下载原图(pages:[0,1] 或 "all",最多 10 页)。不合规的作品拒绝下载

返回 JSON 里的字段:localPath / files[].path 是本地绝对路径,caption(🎨 画师:xxx)给 agent 展示用,url 是作品页地址。

过滤规则和 bot 版完全一致:

  • 多标签 AND

  • 互斥组蹭标签、AI(aiType=2)、动图、黑名单直接丢;请求里出现黑名单词就整次拒绝,而且不扣冷却。短英文关键词(如 bl)以及 腐、グロ 只按整词匹配

  • 灰名单默认避开;显式放行的类别作品必须真有

  • R-18 只认官方 xRestrict

  • 1 年半衰期排序,同一 session 不重复出图,看完一轮自动重新循环

  • 搜索按 10000users入り → … → 纯标签逐档降级

  • 429 / 5xx 指数退避重试

各客户端配置

下面示例用相对路径 ./dist/bin.js(先 cd 到项目根目录再启动)。若写成绝对路径,Windows / Linux / macOS 各自换成你的实际路径即可。

Codex CLI:~/.codex/config.toml(Windows:C:\Users\<你>\.codex\config.toml)

[mcp_servers.pixiv]
command = "node"
args = ['--max-old-space-size=96', './dist/bin.js', 'serve']
startup_timeout_sec = 20
tool_timeout_sec = 120

[mcp_servers.pixiv.env]
PIXIV_REFRESH_TOKEN = "你的token"
PIXIV_MCP_HOME = '~/.pixiv-mcp'

TOML 里用单引号字符串,Windows 反斜杠就不用转义。

Claude Desktop:%APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "pixiv": {
      "command": "node",
      "args": ["--max-old-space-size=96", "./dist/bin.js", "serve"],
      "env": {
        "PIXIV_REFRESH_TOKEN": "你的token",
        "PIXIV_MCP_HOME": "~/.pixiv-mcp"
      }
    }
  }
}

Claude Code

claude mcp add pixiv -s user -e PIXIV_REFRESH_TOKEN=你的token -e "PIXIV_MCP_HOME=~/.pixiv-mcp" -- node --max-old-space-size=96 "./dist/bin.js" serve

Cursor:~/.cursor/mcp.json(全局)或项目里的 .cursor/mcp.json

内容和 Claude Desktop 那段 mcpServers 一样。

Grok Bot(本地 stdio MCP)

在 Grok Bot 添加本地 MCP 时填:

  • 命令:node

  • 参数:--max-old-space-size=96、./dist/bin.js、serve

  • 环境变量:PIXIV_REFRESH_TOKEN,以及可选的 PIXIV_MCP_HOME

如果要求填 JSON,就用和 Claude Desktop 一样的 mcpServers.pixiv 那段。

不支持 MCP 的 agent:直接调 CLI

node dist/bin.js search 信浓 泳装 2 --json
node dist/bin.js search --tags "オリジナル 水着" --gray oral --session alice
node dist/bin.js detail 12345678 --json
node dist/bin.js download 12345678 --pages all --json

退出码:成功为 0;失败、被拦截或冷却中为 1;用法错误为 2。

和 bot 版的差别

  • 数据目录从 ~/.dsh-qqbot 改为 ~/.pixiv-mcp(可用 PIXIV_MCP_HOME 改)

  • LLM 补标签从“拉起本机 agy”改为可选的 OpenAI 兼容接口(默认关闭)

  • 新增 pixiv_illust_detail / pixiv_download(按 PID),规则复用同一套过滤

  • 网络失败、连续失败熔断时,结果里带 notice 说明原因,不再静默返回空

  • 下载改为流式写盘,加了全局并发上限和单图大小上限;本地缓存上限默认从 2 GB 改为 512 MB

  • 不负责发送图片:工具返回本地路径和 caption,由 agent 决定怎么展示。多图间隔 1.5 秒属于 QQ 发图的限制,这里不需要

Available Tools

3 tools
pixiv_downloadPixiv 原图下载A

按 PID 下载原图到本地目录(PIXIV_MEDIA_DIR),返回每页的文件绝对路径与作品元数据。不合规(黑名单/未放行的灰名单/AI/动图)的作品拒绝下载。最多 10 页,下载并发受 PIXIV_DOWNLOAD_CONCURRENCY 限制。

NameRequiredDescriptionDefault
pidYesPixiv 作品 ID
r18No用户明确要求 R-18 时为 true
pagesNo页码(从 0 开始),默认 [0];"all" 下载全部页
allow_grayNo显式放行的灰名单类别(默认全部避开)。只有用户明确点名时才传。放行的类别作品必须真的具备;其余灰名单仍拒绝。可选: r18(官方 R-18) / oral(口交) / creampie(中出) / paizuri(乳交) / footjob(足交) / ahegao(阿黑颜) / sex(性交)

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Since no annotations are supplied, the description must carry the full behavioral load, and it does disclose the key traits: a local-filesystem write into PIXIV_MEDIA_DIR, refusal rules for disallowed works, a 10-page ceiling, and concurrency governed by PIXIV_DOWNLOAD_CONCURRENCY. It omits overwrite behavior for pre-existing files and any auth/cookie requirement, which matter for a writing tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Four dense sentences lead with the core action and destination, then constraints, then limits, with no filler. Every clause carries operational information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

There is no output schema, but the description states what is returned (per-page absolute paths plus work metadata), which compensates. The remaining gap is file-collision/overwrite and error behavior on refusal for a tool that writes to disk with no annotations to fall back on.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents pid, r18, pages, and allow_gray in detail; the description adds only the page cap, which schema maxItems already conveys. Baseline 3 applies because the description adds little parameter meaning beyond the structured fields.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource (download original images by PID) plus the destination directory and the return payload (absolute per-page paths and work metadata). This clearly separates it from the read-only siblings pixiv_search and pixiv_illust_detail, which cannot write files.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description spells out the conditions under which the tool refuses to act (blacklist, unapproved gray list, AI, animated) and caps the operation at 10 pages, so the agent knows the boundaries before calling. It does not explicitly route the agent to pixiv_search or pixiv_illust_detail to obtain the PID, which is the only missing piece.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

pixiv_illust_detailPixiv 作品详情A

按 PID 读取作品元数据(标题、画师、标签、收藏、页数、原图地址、分级),并按同一套黑/灰名单规则给出 compliant 结论。不下载。

NameRequiredDescriptionDefault
pidYesPixiv 作品 ID
r18No用户明确要求 R-18 时为 true
allow_grayNo显式放行的灰名单类别(默认全部避开)。只有用户明确点名时才传。放行的类别作品必须真的具备;其余灰名单仍拒绝。可选: r18(官方 R-18) / oral(口交) / creampie(中出) / paizuri(乳交) / footjob(足交) / ahegao(阿黑颜) / sex(性交)

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It usefully discloses a non-obvious behavior — the tool computes a 'compliant' verdict using black/graylist rules — but '同一套规则' is undefined, and it never says what a non-compliant result looks like (error vs. a compliant:false field), whether Pixiv auth/refresh tokens are required, or whether rate limits apply.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two tight sentences: the read-and-return-fields contract is front-loaded and the non-download constraint closes it. No filler, and the returned-field list is compressed rather than enumerated in prose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the enumerated return fields are exactly the right compensation, and the compliance-verdict behavior is a valuable addition. What's missing is the failure mode for non-compliant works and any auth prerequisite — notable gaps for a tool whose output is a policy decision, but not fatal.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, including detailed enum semantics for allow_gray and the conditional meaning of r18, so the schema already does the heavy lifting. The description only restates that lookup is keyed on PID; it adds no format or validation detail beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('按 PID 读取作品元数据') and enumerates exactly what comes back: title, artist, tags, bookmarks, page count, original image URLs, rating. It also explicitly disclaims the download behavior, which cleanly separates it from the pixiv_download sibling.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The only routing signal is the trailing '不下载', which implicitly points download intent at pixiv_download; it never mentions pixiv_search as the way to obtain a PID in the first place. Some when-to-pass guidance lives in the schema (allow_gray: '只有用户明确点名时才传'), but the description body itself leaves usage to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 3 tool updatesv1.0.0
    • First observedpixiv_download
    • First observedpixiv_illust_detail
    • First observedpixiv_search

TDQS

A3.9/5.0

Scored across 3 tools

Disambiguation3/5

pixiv_detail (metadata only) and pixiv_download (fetch files by PID) are clearly distinct, but pixiv_search already downloads originals and returns metadata, so an agent may not know whether a subsequent pixiv_download call is needed. The descriptions partly resolve this (search = discovery + fetch, download = explicit PID fetch), but the boundary between search and download remains blurred.

Naming Consistency4/5

All names use a consistent pixiv_ prefix with snake_case and a verb/action orientation (search, download) plus one descriptive noun form (illust_detail). Minor deviation in structure but predictable and readable.

Tool Count4/5

Three tools is on the thin side but each maps to a real step of the workflow: discover, inspect, fetch. No redundant or filler tools, so the small surface is justified for the server's scope.

Completeness4/5

Search, metadata inspection, and download cover the core image-retrieval lifecycle with shared filtering rules applied consistently. Gaps exist around artist/user-based browsing or paging beyond search results, but agents can work around these by re-searching with tags.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables browsing, searching, and downloading Pixiv content including illustrations, rankings, recommendations, and user bookmarks. Supports intelligent batch downloads with automatic Ugoira-to-GIF conversion and OAuth 2.0 authentication.
    5
    MIT
  • F
    license
    Not graded
    quality
    A
    maintenance
    Enables AI agents to search and browse manga, inspect album details, comments and rankings, manage favorites, and download albums, chapters, and covers with progress reporting, cancellation, retry, and batch task control. Also supports post-processing downloads into ZIP, PDF, or long images and dynamic runtime configuration, exposed as MCP tools and knowledge resources over stdio, SSE, and HTTP transports.
    -
  • F
    license
    Not graded
    quality
    A
    maintenance
    Enables AI agents to search, browse, and download comics via natural language, manage favorites, read comments and rankings, and convert downloaded content into ZIP, PDF, or long images. It also exposes download planning, background task progress, cancellation, retry, login/session handling, and runtime configuration as MCP tools and resources.
    -