Stackexchange Mcp Server

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

Search Stack Exchange questions, fetch Q&A threads as markdown, look up tag FAQs and user profiles.

已验证Streamable HTTP可网页运行网页搜索与抓取开发者工具

概览

AI 生成的概览

搜索 Stack Exchange 站点,以 Markdown 读取问答帖,并查看标签常见问题、用户资料与站点列表。

可以做什么
  • 列出 Stack Exchange 网络中的站点及其站点参数,可按名称过滤
  • 按全文关键词、标签、最低评分和排序方式搜索站点上的问题
  • 以 Markdown 获取完整问答帖,采纳答案优先,可选附带评论
  • 浏览某个标签的常见问题,并按 ID 查询用户资料
适用场景
适合让助手检索 Stack Overflow、Server Fault、Unix & Linux 等技术社区的问答内容,并在注明作者出处的前提下引用或总结答案。
运行要求
可使用公开托管的 HTTP 端点,或通过 npx(Node.js)、Docker、源码构建(Bun 1.4.0+ 或 Node.js 24+)在本地运行。可选的 STACKEXCHANGE_API_KEY 可将每 IP 配额从约 300 次/天提升到约 10,000 次/天;未设置时无法翻页超过 25 页。需要能访问 Stack Exchange API 的网络。
安装前请注意
仅读取公开内容,不写入数据。可选的 STACKEXCHANGE_API_KEY 属于凭据,应避免放入共享配置。查询与抓取的内容会发送到 Stack Exchange API,使用托管端点时还会经过第三方服务器。可开启失败工具调用载荷日志,其中自由文本里的密钥不会被脱敏。

安装

在 SourceWeft 中

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

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

交给智能体安装

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

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

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

其他 MCP 客户端

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

{
  "mcpServers": {
    "stackexchange": {
      "type": "http",
      "url": "https://stackexchange.caseyjhand.com/mcp"
    }
  }
}

README

@cyanheads/stackexchange-mcp-server

Search Stack Exchange questions, fetch complete Q&A threads as clean markdown, browse tag FAQs, and look up user profiles via MCP. STDIO or Streamable HTTP.

5 Tools


Overview

Stack Overflow and the rest of the Stack Exchange network, from Super User and Server Fault to Unix & Linux. Search questions, read complete Q&A threads as clean markdown, browse tag FAQs, and look up user profiles.

Tools

ToolDescription
stackexchange_search_questionsSearch questions across a Stack Exchange site with full-text query, tag filters, score threshold, and sort order
stackexchange_get_threadFetch a question and its answers as markdown, with a configurable answer limit and the accepted answer first
stackexchange_get_tag_faqFetch a tag's frequently asked questions — Stack Exchange's own selection, in its order rather than by score
stackexchange_get_userFetch a user profile by ID: reputation, badge counts, top tags by answer score, and account metadata
stackexchange_list_sitesEnumerate all Stack Exchange network sites and their api_site_parameter values

Agent skill

skills/stackexchange-guide covers what the tool schemas don't: why IDs never carry across sites and which site a URL or ID is read from, search syntax for error messages and tags, choosing which answer to quote, and what each call costs against the daily quota. Plugin installs (Claude Code, Codex) and the Claude Desktop bundle load it from the package, and MCP clients that support the Skills extension read it from the server through skills/list.


Capability reference

stackexchange_search_questions tool

  • Full-text query with optional tag filters, minimum score threshold, and accepted-only filter; sort by relevance (default), votes, activity, or newest
  • Up to 30 results per page (default 10); page for more — each page costs one API quota unit, and paging past 25 requires STACKEXCHANGE_API_KEY
  • Returns question ID, title, score, answer count, tags, and a ~300-character excerpt — IDs flow directly into stackexchange_get_thread
  • Quota remaining and max surfaced via enrichment on every response
  • Every response reports appliedSort, the order Stack Exchange actually used; minScore forces votes, and sortOverrideReason says so whenever that replaces the requested sort

stackexchange_get_thread tool

  • Accepts a numeric question ID or a full Stack Exchange question URL; fetches the question and a page of maxAnswers answers (1–100, default 10), adding the accepted answer if it falls outside that page
  • A URL is read from the site its host names (unix.stackexchange.com, ru.stackoverflow.com, arqade.com, …), so site applies only to a numeric ID or a hostless /questions/ path; a site naming a different site than the URL is ignored, and a URL whose host is not a Stack Exchange site (a translation proxy) is read from site instead — either way reported as siteConflict on both surfaces. Such a URL sent without site fails as invalid_site
  • HTML→markdown normalization built in — code blocks, links, lists, headers, and blockquotes all converted
  • Optional includeComments fetches up to 20 comments per post, newest first, using two extra API calls (one when there are no answers); commentsTruncated reports partial lists
  • Attribution (author name, profile link, score) on every answer per CC BY-SA 4.0
  • Quota remaining and max surfaced via enrichment; truncated when more answers exist upstream than maxAnswers returned

stackexchange_get_tag_faq tool

  • A tag's frequently asked questions — maps to /tags/{tag}/faq, Stack Exchange's own selection, returned in its order and not sorted by score
  • Up to 30 results per page (default 10); page for more — each page costs one API quota unit, and paging past 25 requires STACKEXCHANGE_API_KEY
  • Returns a question list without bodies; pipe any questionId into stackexchange_get_thread for full content
  • Quota remaining and max surfaced via enrichment on every response

stackexchange_get_user tool

  • userId must be at most 2,147,483,647 (32-bit) — typically the authorUserId from stackexchange_get_thread output
  • Fetches the profile and top tags in two upstream API calls
  • Returns reputation, badge counts (gold/silver/bronze), location, website, answer/question counts, and up to 10 top tags by answer score (empty array for users with no answers)
  • An unknown user ID returns a typed user_not_found error — Stack Exchange answers HTTP 200 with empty results rather than 404

stackexchange_list_sites tool

  • Fetches every site in the Stack Exchange network, walking pages of 100 up to a 10-page cap; an enrichment notice flags a partial list if the network still has more
  • Optional case-insensitive name filter matches against site name and api_site_parameter, applied client-side after the fetch
  • Returns the api_site_parameter value (e.g. stackoverflow, superuser, serverfault) that every other tool's site parameter accepts; the site's domain (e.g. serverfault.com) works there too

Features

Built on @cyanheads/mcp-ts-core: stdio and Streamable HTTP transports, pluggable auth (none / jwt / oauth), swappable storage (in-memory, filesystem, Supabase, Cloudflare KV/R2/D1), structured logging with optional OpenTelemetry tracing.

Stack Exchange-specific:

  • HTML→markdown conversion preserves code blocks, tables, links, images, and nested lists
  • Shared upstream queue honors response backoff, stated throttle waits, and HTTP 429 cooldowns; each operation has a 50-second budget covering queue time, backoff, requests, and retries, a backoff that cannot fit it fails at once, and a queued call sheds before the budget ends, both with retryAfter instead of running out the clock
  • Quota logging: quota_remaining and quota_max surfaced via enrichment on every tool call
  • Typed error contracts on every tool — invalid_site, invalid_parameter, invalid_api_key, invalid_id_or_url, invalid_user_id, question_not_found, user_not_found, paging_depth_limit, quota_exceeded, throttled, pacer_shed, and upstream_unavailable
  • Optional STACKEXCHANGE_API_KEY lifts the per-IP quota from ~300/day to ~10,000/day with no OAuth required

Agent-friendly output:

  • Quota remaining on every response — agents can plan around rate limits without the server needing to fail
  • The accepted answer appears first, followed by the remaining answers sorted by score
  • Each answer includes attribution under CC BY-SA 4.0
  • Typed not_found errors for missing questions and users (SE returns HTTP 200 with empty items[] rather than 404)

Getting started

Connect to the hosted instance, no install:

sh
claude mcp add --transport http stackexchange-mcp-server https://stackexchange.caseyjhand.com/mcp

Or run it locally:

sh
claude mcp add stackexchange-mcp-server -- npx -y @cyanheads/stackexchange-mcp-server

For other clients, add this to the MCP config file:

json
{  "mcpServers": {    "stackexchange-mcp-server": {      "command": "npx",      "args": ["-y", "@cyanheads/stackexchange-mcp-server"]    }  }}

Without a key, the Stack Exchange API allows ~300 requests/day per IP; set STACKEXCHANGE_API_KEY to lift this to ~10,000/day. Register a key at stackapps.com/apps/oauth/register — a key alone covers read-only use. For Docker or a source build, see Running the server.


Configuration

VariableDescriptionDefault
STACKEXCHANGE_API_KEYOptional. Stack Exchange API key — lifts per-IP quota from ~300/day to ~10,000/day.—
MCP_TRANSPORT_TYPETransport: stdio or http.stdio
MCP_HTTP_PORTPort for HTTP server.3010
MCP_HTTP_HOSTHost for HTTP server.127.0.0.1
MCP_SESSION_MODEHTTP session mode: auto, stateful, or stateless. auto resolves to stateful. A meaningful env value overrides this server's stateless source default; blank or unsubstituted placeholders use the source default.stateless
MCP_AUTH_MODEAuth mode: none, jwt, or oauth.none
MCP_LOG_LEVELLog level (RFC 5424).info
LOGS_DIRDirectory for log files (Node.js only).<project-root>/logs
LOG_TOOL_FAILURE_PAYLOADSLog each failed tool call's arguments and result, redacted by key name and capped at LOG_TOOL_FAILURE_PAYLOAD_MAX_BYTES (default 16384). A secret inside a free-form value is not redacted.false
STORAGE_PROVIDER_TYPEStorage backend.in-memory
OTEL_ENABLEDEnable OpenTelemetry instrumentation (spans, metrics, completion logs).false
OTEL_EXPORTER_OTLP_LOGS_ENDPOINTOpt-in OTLP log export (e.g. http://localhost:4318/v1/logs); the base OTEL_EXPORTER_OTLP_ENDPOINT never enables it.—

See .env.example for the full list of optional overrides.


Running the server

Local development

Requires Bun v1.4.0 or higher (or Node.js v24+).

  • Clone and install:

    sh
    git clone https://github.com/cyanheads/stackexchange-mcp-server.gitcd stackexchange-mcp-server && bun installcp .env.example .env   # optionally set STACKEXCHANGE_API_KEY
  • Build and run:

    sh
    # One-time buildbun run rebuild
    # Run the built serverbun run start:stdio# orbun run start:http
  • Run checks and tests:

    sh
    bun run devcheck   # Lint, format, typecheck, securitybun run test       # Vitest test suitebun run lint:mcp   # Validate MCP definitions against spec

Docker

sh
docker run --rm -e STACKEXCHANGE_API_KEY=your-key -p 3010:3010 ghcr.io/cyanheads/stackexchange-mcp-server:latest

The image defaults to HTTP transport, stateless session mode, and logs to /var/log/stackexchange-mcp-server. To run it over stdio from an MCP client, use "command": "docker" with "args": ["run", "-i", "--rm", "-e", "MCP_TRANSPORT_TYPE=stdio", "ghcr.io/cyanheads/stackexchange-mcp-server:latest"]. To build locally, docker build -t stackexchange-mcp-server .; OpenTelemetry peer dependencies are installed by default — build with --build-arg OTEL_ENABLED=false to omit them.


Project structure

PathPurpose
src/index.tscreateApp() entry point — registers tools and inits services.
src/config/Server-specific environment variable parsing with Zod (STACKEXCHANGE_API_KEY).
src/mcp-server/tools/Tool definitions (*.tool.ts).
src/services/stackexchange/Stack Exchange API v2.3 HTTP client, backoff tracking, quota logging, HTML→markdown normalizer.
skills/The stackexchange-guide agent skill, published to installing and connecting clients.
tests/Vitest unit and integration tests.
docs/Design document and directory tree.

Development guide

See CLAUDE.md/AGENTS.md for development guidelines and architectural rules. The short version:

  • Handlers throw, framework catches — no try/catch in tool logic
  • Use ctx.log for request-scoped logging, ctx.state for tenant-scoped storage
  • Register new tools via the barrel in src/mcp-server/tools/definitions/index.ts
  • Wrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields

Contributing

Issues are welcome. Run checks and tests before submitting:

sh
bun run devcheckbun run test

License

Apache-2.0 — see LICENSE for details.

来源:README.md,提交 0d0336f

工具

5

stackexchange_list_sites

List Stack Exchange Sites

Enumerate all sites in the Stack Exchange network — name, api_site_parameter, audience, and URL. The api_site_parameter value is what other tools accept as the `site` input (e.g. "stackoverflow", "superuser", "serverfault"). Results are fetched live and optionally filtered by name. Use this tool to discover valid site parameters before calling other stackexchange_* tools.

输入参数filter

stackexchange_search_questions

Search Stack Exchange Questions

Search questions across a Stack Exchange site. Returns ranked questions with title, score, answer count, accepted status, tags, ask and last-activity dates, and a short excerpt of the question body — not the full body. Results supply question_id values for stackexchange_get_thread, which fetches the full question body and all answers. Results past the pageSize cap are reachable with the `page` parameter. Use the `site` parameter to target a specific community (e.g. "stackoverflow", "superuser", "unix"); call stackexchange_list_sites to discover valid site values.

输入参数pagesitesorttagsquery必填minScorepageSizeacceptedOnly

stackexchange_get_tag_faq

Get Stack Exchange Tag FAQ

Fetch the frequently asked questions for a tag on a Stack Exchange site — Stack Exchange's own "frequently asked" selection, returned in its order, not ranked by score; compare the scores yourself. Returns a question list without bodies; use stackexchange_get_thread to read the full body and answers for any result. Results past the pageSize cap are reachable with the `page` parameter. Use this tool to find the questions a community keeps coming back to on a topic (e.g. tag "javascript" on stackoverflow). Use stackexchange_search_questions for free-text search rather than tag-based browsing.

输入参数tag必填pagesitepageSize

stackexchange_get_user

Get Stack Exchange User Profile

Fetch a Stack Exchange user profile by numeric user ID: reputation, badge counts, answer and question counts, account and last-access dates, and top tags by answer score. Useful for credibility context on an answer author — pass the authorUserId from any question or answer in stackexchange_get_thread output. Returns profile fields plus up to 10 top tags by answer score.

输入参数siteuserId必填

stackexchange_get_thread

Get Stack Exchange Q&A Thread

Fetch a complete Q&A thread — question body and all answers, accepted answer first then sorted by score, rendered as clean markdown with fenced code blocks. Accepts a full Stack Exchange question URL, which is read from the site its host names (e.g. "https://unix.stackexchange.com/questions/88490/how-do-i-use-a-heredoc"), or an integer question ID read from site (e.g. "11227809"). HTML is normalized to markdown automatically; attribution (author + link) included per CC BY-SA 4.0. Get question IDs from stackexchange_search_questions or stackexchange_get_tag_faq.

输入参数sitemaxAnswersincludeCommentsquestionIdOrUrl必填

版本历史

5
  1. v0.2.0最新Oct 29, 2026
  2. v0.1.17Oct 25, 2026
  3. v0.1.16Oct 9, 2026
  4. v0.1.15Sep 19, 2026
  5. v0.1.14Sep 16, 2026

评分

已满足适用检查项的 100%

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

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