xkcd Comic Suggester

io.github.papjuli由 GitHub 账号 papjuli 发布v0.2.0更新于 Oct 24, 2026

Suggests a relevant xkcd comic during a conversation, via semantic search over every comic.

已验证Streamable HTTP可网页运行网页搜索与抓取知识与记忆

概览

AI 生成的概览

一个远程 MCP 服务器,按语义检索与当前对话相关的 xkcd 漫画,让助手能引用贴切的漫画。

可以做什么
  • 按语义搜索漫画:find_xkcd 接收一句描述对话主题的短语,返回语义匹配的 xkcd 漫画及相似度分数。
  • 调整结果:max_results 与 min_score(默认 0.62)控制返回的候选数量与匹配严格程度。
  • 判断相关性:工具中说明了分数区间,供调用模型决定是否值得提及某条漫画。
适用场景
适合希望助手在编程、科学、数学、统计、工程、标准之争或日常生活等话题中适时引用一条贴切 xkcd 的场景。它是轻量的只读附加工具,而非核心工作工具。
运行要求
远程端点 xkcdai.onrender.com,需带 /mcp 路径;无需认证、API 密钥或环境变量,在 MCP 客户端中作为自定义连接器添加即可。也可从 Python 项目本地以 stdio 方式运行,此时需设置 XKCDAI_DATA_DIR 并构建数据索引。
安装前请注意
托管服务器公开且无认证,任何拿到网址的人都能使用;README 建议不要将这种模式用于敏感数据。助手只有在被提示或写入常驻指令时才会调用该工具,主动推荐需自行添加指令。随附的漫画与 explainxkcd 数据为非商业、相同方式共享许可,且该项目为非官方粉丝项目,与 xkcd 无关联。

安装

在 SourceWeft 中

  1. 打开 控制台中的 xkcd Comic Suggester,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Web executable,通过 Streamable HTTP。 远程服务在工作区中配置后即可从网页运行时运行。

交给智能体安装

把这段提示词粘贴到 Claude Code、Codex、Cursor 等智能体,或 SourceWeft 对话中。智能体会读取该服务器的安装指南,先向你展示发布者、端点和登录方式,经你同意后再把它添加到你的客户端。密钥不会写进任何命令。

阅读 https://sourceweft.com/mcp/io.github.papjuli%2Fxkcdai/install.md,并按其中说明把这个 MCP 服务器接入我的客户端。修改任何配置之前,先告诉我它的发布者、端点和登录方式,等我确认。不要把 API 密钥写进命令或我会提交的文件;问我密钥应从哪里获取。

查看智能体所依据的安装指南

其他 MCP 客户端

把它添加到你客户端的 mcpServers 配置中。

{
  "mcpServers": {
    "xkcd-comic-suggester": {
      "type": "http",
      "url": "https://xkcdai.onrender.com/mcp"
    }
  }
}

README

xkcdai

An MCP server that surfaces the right xkcd comic during a conversation, if one is relevant.

Live connector: https://xkcdai.onrender.com/mcp — add it in claude.ai → Settings → Connectors. See Use the deployed MCP server.

It builds a semantic index over every xkcd comic (title + mouseover text + transcript) using on-device embeddings, then exposes a single find_xkcd tool. A Claude conversation can call it whenever the topic feels xkcd-shaped; a relevance threshold means weak matches return nothing, so it stays quiet instead of forcing a tenuous reference.

The fetched transcripts, explanations, and the embeddings are currently committed in this repo, under data/.

How it works

xkcd JSON API ─┐               ├─► comics.json + explain.json ─► embeddings.npy ─► find_xkcd ─► Claudeexplainxkcd  ──┘        (cache)                    (bge-small)     (cosine)    (mentions it (transcripts +                                                                 if it fits)  explanations)
  • Data: title + mouseover alt from the official API, plus the community transcript and explanation from explainxkcd.com. The explainxkcd context is essential: the official API dropped transcripts around comic ~1675, so without it the most-shared modern comics (e.g. #2347 Dependency) are unmatchable — their joke text lives only inside the image.
  • Embeddings: fastembed (ONNX) with BAAI/bge-small-en-v1.5 — local, free, offline after first download, no PyTorch. Swap the model in src/xkcdai/embed.py (e.g. BAAI/bge-base-en-v1.5 for marginally better ranking at ~3× the size).
  • Search: a normalized numpy matrix + dot product. No vector DB needed for a few thousand comics.
  • Restraint: because xkcd has a comic for almost everything, a similarity cutoff alone can't judge relevance. min_score (default 0.62) is just a coarse floor; the real "should I bring this up?" decision is made by the calling model, guided by the score bands documented on the find_xkcd tool.

Use the deployed MCP server (as custom connector)

The server is deployed at https://xkcdai.onrender.com on Render. Add it as a Claude custom connector to use it in the Claude web and mobile apps (note: the Free plan only allows one custom connector). Anyone can add the same URL in their own account.

In claude.ai (web — do this once; it then syncs to the mobile app):

  1. Settings → Connectors → Add custom connector.
  2. Paste the connector URL, including the /mcp path: https://xkcdai.onrender.com/mcp
  3. Leave OAuth blank (this server needs no auth) and click Add.
  4. The connector's find_xkcd tool is now available in chats, on desktop and phone. For Claude to suggest comics on its own, also add the instruction from Make Claude suggest comics proactively to your Profile preferences.

Notes

  • The server is public and unauthenticated — fine here (read-only comic search, no secrets). Don't reuse this pattern for anything sensitive without OAuth.
  • Hosted from this repo via the Dockerfile and render.yaml; pushes to main auto-redeploy.
  • GET /healthz reports liveness, whether the index is loaded, and current RSS — handy on a 512 MB instance:
    bash
    curl https://xkcdai.onrender.com/healthz

Local setup

bash
python -m venv .venv# Windows (PowerShell):  .venv\Scripts\Activate.ps1# macOS/Linux:           source .venv/bin/activatepip install -e .
# Fetch comics + their explainxkcd context, then embed (downloads the model once).# First run ~10 min; re-running later only fetches what's new.xkcdai build

Add --no-enrich to skip the explainxkcd fetch (faster/offline, weaker matches).

Test it from the command line:

bash
xkcdai search "my code finally compiled after an hour"xkcdai search "arguing about the correct date format"xkcdai search "spent more time automating it than doing it by hand"

Use locally as an MCP server

The server runs over stdio. Point your MCP host at it.

Claude Desktop (claude_desktop_config.json):

json
{  "mcpServers": {    "xkcdai": {      "command": "C:\\your\\path\\to\\xkcdai\\.venv\\Scripts\\xkcdai-server.exe",      "env": { "XKCDAI_DATA_DIR": "C:\\your\\path\\to\\xkcdai\\data" }    }  }}

Claude Code (-s user makes it available in every project, not just this folder):

bash
claude mcp add xkcdai -s user -e XKCDAI_DATA_DIR=C:\your\path\to\xkcdai\data -- C:\your\path\to\xkcdai\.venv\Scripts\xkcdai-server.exe

Always set XKCDAI_DATA_DIR, since the host launches the server from an arbitrary working directory.

MCP only gives Claude the ability to call find_xkcd — it won't volunteer comics on its own. See Make Claude suggest comics proactively.

Make Claude suggest comics proactively

Connecting the server only gives Claude the ability to call find_xkcd; it won't reach for it unprompted. To make Claude volunteer comics, paste the instruction below wherever that Claude reads persistent instructions:

  • Claude Code — your global ~/.claude/CLAUDE.md (applies everywhere) or a per-repo CLAUDE.md; restart the session to load changes.
  • Claude.ai / Claude Desktop — Settings → Profile → "What personal preferences should Claude consider in responses?" (every plan, including free; syncs to the mobile app). Each person who uses the connector adds it in their own account.
text
When a conversation naturally lands on a topic xkcd is known for — programming,science, math, statistics, engineering, the absurdity of standards, relationships,everyday life — call the find_xkcd tool (xkcdai) with a short phrase describing thetopic. Then judge whether to bring it up:- score >= 0.75 — strong match; mention it if it fits the moment- 0.66-0.75 — only if it genuinely lands- below that — stay silentWhen you share one, give just that single comic: its number and title, its URL, andquote the alt (mouseover) text — that's half the joke. At most one comic per topic,and never force a tangential reference. When in doubt, say nothing.

It's still Claude's judgment, so it won't fire on every borderline topic — asking "is there an xkcd for this?" always triggers a lookup.

Not just Claude — works with any MCP client

The examples above use Claude, but find_xkcd is a standard Model Context Protocol tool, so any MCP-capable host can use it. Point the client at either transport:

The server is LLM-agnostic internally, too: matching runs on a local embedding model. Only the host-specific bits differ — how you register the server, and where you put the "suggest a comic when it fits" instruction (each client has its own system-prompt / rules mechanism, e.g. Cursor Rules or a VS Code .instructions file).

Configuration

  • XKCDAI_DATA_DIR — where comics.json, explain.json, embeddings.npy, and index.json live.
  • find_xkcd(context, max_results=3, min_score=0.62) — lower min_score for more (looser) suggestions, raise it to be stricter.

Maintenance

Re-run xkcdai build periodically to pick up new comics — it incrementally fetches new comics and their explainxkcd context, then re-embeds:

bash
xkcdai build

Use --force to rebuild everything from scratch, or --no-enrich to skip the explainxkcd fetch. xkcdai enrich fetches only the explainxkcd context.

Credits & licensing

This project bundles content from two sources, each under its own license, so the code and the data are licensed separately:

Because data/ mixes xkcd's NonCommercial content with explainxkcd's ShareAlike content, treat the data as non-commercial and keep any redistribution under these terms. The MIT license covers the source code only — not data/. At runtime, find_xkcd results link back to both xkcd and explainxkcd for per-item attribution.

This is an unofficial fan project, not affiliated with or endorsed by xkcd or explainxkcd.

来源:README.md,提交 ef830f1

工具

1

find_xkcd

Find xkcd comics semantically relevant to the current conversation. Call this whenever an xkcd comic might enrich the conversation — when the discussion lands on a topic xkcd is famous for skewering (programming, science, statistics, relationships, the absurdity of standards, etc.). Pass a concise description of the current topic or theme as `context` (a phrase or sentence works better than a whole transcript), e.g. "spending hours automating a task that was faster to do by hand" or "code finally compiling". IMPORTANT — deciding whether to mention one. xkcd has a comic for almost every topic, so this tool will nearly always return something. A result being returned does NOT mean you should bring it up. Use the `score` as a signal and apply your own judgment about conversational fit: score >= 0.75 strong match — usually worth mentioning if it fits the moment 0.66 - 0.75 plausible — mention only if it genuinely lands < 0.66 weak/tangential — almost always better to stay silent Only one comic, at most, per topic — and only when it actually adds something. When you do share one, cite it by number and title with its `url`, and quote the `alt` (mouseover) text — it's half the joke. Returns a dict with a `results` list (num, title, score, url, image, alt, explain_url) and a `count`. An empty list means nothing cleared the floor.

输入参数context必填min_scoremax_results

版本历史

1
  1. v0.2.0最新Sep 16, 2026

评分

已满足适用检查项的 90%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通必需25 分
  • 已声明认证方式必需10 分
  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

    请在仓库或注册中心条目中声明许可证。