io.github.cyanheads/stackexchange-mcp-server
Search Stack Exchange questions, fetch Q&A threads as markdown, look up tag FAQs and user profiles.
ماذا يمكنك أن تفعل مع io.github.cyanheads/stackexchange-mcp-server؟
- HTML→markdown conversion preserves code blocks, tables, links, images, and nested lists
- Shared upstream queue honors response backoff and HTTP 429 cooldowns; each operation has a 50-second budget covering queue time, backoff, requests, and retries
- Quota logging:
quota_remainingandquota_maxsurfaced 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, andupstream_unavailable - Optional
STACKEXCHANGE_API_KEYlifts the per-IP quota from ~300/day to ~10,000/day with no OAuth required - 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
التثبيت
أضف هذا إلى إعدادات MCP في عميلك (Claude Desktop: claude_desktop_config.json، وCursor: .cursor/mcp.json، ويستخدم VS Code وغيره الصيغة نفسها «mcpServers»).
claude mcp add --transport http stackexchange-mcp-server 'https://stackexchange.caseyjhand.com/mcp'
{
"mcpServers": {
"stackexchange-mcp-server": {
"type": "http",
"url": "https://stackexchange.caseyjhand.com/mcp"
}
}
}
@cyanheads/stackexchange-mcp-serverclaude mcp add stackexchange-mcp-server -e 'STACKEXCHANGE_API_KEY=<STACKEXCHANGE_API_KEY>' -e 'MCP_LOG_LEVEL=info' -- npx -y @cyanheads/stackexchange-mcp-server@0.2.0
{
"mcpServers": {
"stackexchange-mcp-server": {
"command": "npx",
"args": [
"-y",
"@cyanheads/stackexchange-mcp-server@0.2.0"
],
"env": {
"STACKEXCHANGE_API_KEY": "<STACKEXCHANGE_API_KEY>",
"MCP_LOG_LEVEL": "info"
}
}
}
}
متغيرات البيئة
STACKEXCHANGE_API_KEYStack Exchange API key — lifts per-IP quota from ~300/day to ~10,000/day.MCP_LOG_LEVELSets the minimum log level for output (e.g., 'debug', 'info', 'warn').
@cyanheads/stackexchange-mcp-serverclaude mcp add stackexchange-mcp-server -e 'MCP_TRANSPORT_TYPE=<MCP_TRANSPORT_TYPE>' -e 'STACKEXCHANGE_API_KEY=<STACKEXCHANGE_API_KEY>' -e 'MCP_HTTP_HOST=127.0.0.1' -e 'MCP_HTTP_PORT=3010' -e 'MCP_HTTP_ENDPOINT_PATH=/mcp' -e 'MCP_AUTH_MODE=none' -e 'MCP_LOG_LEVEL=info' -- npx -y @cyanheads/stackexchange-mcp-server@0.2.0
{
"mcpServers": {
"stackexchange-mcp-server": {
"command": "npx",
"args": [
"-y",
"@cyanheads/stackexchange-mcp-server@0.2.0"
],
"env": {
"MCP_TRANSPORT_TYPE": "<MCP_TRANSPORT_TYPE>",
"STACKEXCHANGE_API_KEY": "<STACKEXCHANGE_API_KEY>",
"MCP_HTTP_HOST": "127.0.0.1",
"MCP_HTTP_PORT": "3010",
"MCP_HTTP_ENDPOINT_PATH": "/mcp",
"MCP_AUTH_MODE": "none",
"MCP_LOG_LEVEL": "info"
}
}
}
}
متغيرات البيئة
MCP_TRANSPORT_TYPESelects the HTTP transport.STACKEXCHANGE_API_KEYStack Exchange API key — lifts per-IP quota from ~300/day to ~10,000/day.MCP_HTTP_HOSTThe hostname for the HTTP server.MCP_HTTP_PORTThe port to run the HTTP server on.MCP_HTTP_ENDPOINT_PATHThe endpoint path for the MCP server.MCP_AUTH_MODEAuthentication mode to use: 'none', 'jwt', or 'oauth'.MCP_LOG_LEVELSets the minimum log level for output (e.g., 'debug', 'info', 'warn').
التوثيق
مأخوذ من ملف README للمشروع على GitHub ويُحدَّث أسبوعيًا. تفتح الروابط على GitHub.
المحتويات
@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
Public Hosted Server: https://stackexchange.caseyjhand.com/mcp
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
| Tool | Description |
|---|---|
stackexchange_search_questions | Search questions across a Stack Exchange site with full-text query, tag filters, score threshold, and sort order |
stackexchange_get_thread | Fetch a question and its answers as markdown, with a configurable answer limit and the accepted answer first |
stackexchange_get_tag_faq | Fetch the highest-voted answered questions for a tag — the canonical "best answers in X" list |
stackexchange_get_user | Fetch a user profile by ID: reputation, badge counts, top tags by answer score, and account metadata |
stackexchange_list_sites | Enumerate all Stack Exchange network sites and their api_site_parameter values |
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);
pagefor more — each page costs one API quota unit, and paging past 25 requiresSTACKEXCHANGE_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
stackexchange_get_thread tool
- Accepts a numeric question ID or a full Stack Exchange question URL; fetches the question and a page of
maxAnswersanswers (1–100, default 10), adding the accepted answer if it falls outside that page - HTML→markdown normalization built in — code blocks, links, lists, headers, and blockquotes all converted
- Optional
includeCommentsfetches up to 20 comments per post, newest first, using two extra API calls (one when there are no answers);commentsTruncatedreports partial lists - Attribution (author name, profile link, score) on every answer per CC BY-SA 4.0
- Quota remaining and max surfaced via enrichment;
truncatedwhen more answers exist upstream thanmaxAnswersreturned
stackexchange_get_tag_faq tool
- Highest-voted answered questions for a tag — maps to
/tags/{tag}/faq, the canonical "best answers in X" list - Up to 30 results per page (default 10);
pagefor more — each page costs one API quota unit, and paging past 25 requiresSTACKEXCHANGE_API_KEY - Returns a question list without bodies; pipe any
questionIdintostackexchange_get_threadfor full content - Quota remaining and max surfaced via enrichment on every response
stackexchange_get_user tool
userIdmust be at most 2,147,483,647 (32-bit) — typically theauthorUserIdfromstackexchange_get_threadoutput- 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_founderror — 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_parametervalue (e.g.stackoverflow,superuser,serverfault) that every other tool'ssiteparameter accepts
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 and HTTP 429 cooldowns; each operation has a 50-second budget covering queue time, backoff, requests, and retries
- Quota logging:
quota_remainingandquota_maxsurfaced 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, andupstream_unavailable - Optional
STACKEXCHANGE_API_KEYlifts 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_founderrors for missing questions and users (SE returns HTTP 200 with emptyitems[]rather than 404)
Getting started
Public Hosted Instance
A public instance is available at https://stackexchange.caseyjhand.com/mcp — no installation required. It serves Streamable HTTP; each client takes its own config shape.
For Claude Code:
claude mcp add --transport http stackexchange-mcp-server https://stackexchange.caseyjhand.com/mcp
For Cline (cline_mcp_settings.json):
{
"mcpServers": {
"stackexchange-mcp-server": {
"type": "streamableHttp",
"url": "https://stackexchange.caseyjhand.com/mcp"
}
}
}
For Cursor (mcp.json):
{
"mcpServers": {
"stackexchange-mcp-server": {
"url": "https://stackexchange.caseyjhand.com/mcp"
}
}
}
Claude Desktop adds remote servers under Settings → Connectors.
Self-Hosted / Local
Add the following to your MCP client configuration file.
{
"mcpServers": {
"stackexchange": {
"type": "stdio",
"command": "bunx",
"args": ["@cyanheads/stackexchange-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info"
}
}
}
}
Or with npx (no Bun required):
{
"mcpServers": {
"stackexchange": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@cyanheads/stackexchange-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info"
}
}
}
}
Or with Docker:
{
"mcpServers": {
"stackexchange": {
"type": "stdio",
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MCP_TRANSPORT_TYPE=stdio",
"ghcr.io/cyanheads/stackexchange-mcp-server:latest"
]
}
}
}
For Streamable HTTP, set the transport and start the server:
MCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 bun run start:http
# Server listens at http://localhost:3010/mcp
Rate limits: The Stack Exchange API allows ~300 requests/day per IP without a key. Set STACKEXCHANGE_API_KEY in env to lift this to ~10,000/day. Register a key at stackapps.com/apps/oauth/register (the OAuth flow is only required for write access — a key alone is sufficient for read-only use).
Prerequisites
- Bun v1.4.0 or higher (or Node.js v24+)
- A
STACKEXCHANGE_API_KEYis optional but strongly recommended for any sustained use
Installation
- Clone the repository:
git clone https://github.com/cyanheads/stackexchange-mcp-server.git
- Navigate into the directory:
cd stackexchange-mcp-server
- Install dependencies:
bun install
- Configure environment:
cp .env.example .env
# edit .env and set STACKEXCHANGE_API_KEY if desired
Configuration
| Variable | Description | Default |
|---|---|---|
STACKEXCHANGE_API_KEY | Optional. Stack Exchange API key — lifts per-IP quota from ~300/day to ~10,000/day. | — |
MCP_TRANSPORT_TYPE | Transport: stdio or http. | stdio |
MCP_HTTP_PORT | Port for HTTP server. | 3010 |
MCP_HTTP_HOST | Host for HTTP server. | 127.0.0.1 |
MCP_SESSION_MODE | HTTP 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_MODE | Auth mode: none, jwt, or oauth. | none |
MCP_LOG_LEVEL | Log level (RFC 5424). | info |
LOGS_DIR | Directory for log files (Node.js only). | <project-root>/logs |
LOG_TOOL_FAILURE_PAYLOADS | Log 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_TYPE | Storage backend. | in-memory |
OTEL_ENABLED | Enable OpenTelemetry instrumentation (spans, metrics, completion logs). | false |
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT | Opt-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
- Build and run:
# One-time build bun run rebuild # Run the built server bun run start:stdio # or bun run start:http - Run checks and tests:
bun run devcheck # Lint, format, typecheck, security bun run test # Vitest test suite bun run lint:mcp # Validate MCP definitions against spec
Docker
docker build -t stackexchange-mcp-server .
docker run --rm -e STACKEXCHANGE_API_KEY=your-key -p 3010:3010 stackexchange-mcp-server
The Dockerfile defaults to HTTP transport, stateless session mode, and logs to /var/log/stackexchange-mcp-server. OpenTelemetry peer dependencies are installed by default — build with --build-arg OTEL_ENABLED=false to omit them.
Project structure
| Path | Purpose |
|---|---|
src/index.ts | createApp() 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. |
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/catchin tool logic - Use
ctx.logfor request-scoped logging,ctx.statefor 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:
bun run devcheck
bun run test
License
Apache-2.0 — see LICENSE for details.
الأسئلة الشائعة
ما هو io.github.cyanheads/stackexchange-mcp-server؟
Search Stack Exchange questions, fetch Q&A threads as markdown, look up tag FAQs and user profiles.
كيف أثبّت io.github.cyanheads/stackexchange-mcp-server؟
يعمل كخادم بعيد. في Claude Code: claude mcp add --transport http stackexchange-mcp-server 'https://stackexchange.caseyjhand.com/mcp'. وفي العملاء الآخرين، الصق إعداد JSON من هذه الصفحة في إعدادات MCP الخاصة بهم.
هل يحتاج io.github.cyanheads/stackexchange-mcp-server إلى مفتاح API؟
لا يذكر إدراجه في السجل أي مفتاح أو سر إلزامي. قد تتطلب بعض الميزات حسابًا لدى الخدمة التي يتصل بها.
هل io.github.cyanheads/stackexchange-mcp-server مفتوح المصدر؟
نعم. شيفرته متاحة على GitHub بترخيص Apache-2.0.
من يصون io.github.cyanheads/stackexchange-mcp-server؟
ينشره cyanheads. يدرجه AI.tn لكنه لا يصونه ولا يوصي به.
من سجل MCP الرسمي. الإدراج ليس توصية: راجع شيفرة الخادم وصلاحياته قبل منحه الوصول إلى بياناتك.