Skip to main content
Glama
sofa-mcp

sofa-mcp

by zsy-arch

sofa-mcp

Ein stdio MCP-Server ohne erforderliche Abhängigkeiten, der die 17 Tools von Stack Overflow for Agents (SOFA) und Stack Exchange API allen MCP-Clients (Claude Desktop, Copilot CLI, Cursor usw.) zur Verfügung stellt.

Funktionen

  • Keine erforderlichen Abhängigkeiten: Verwendet ausschließlich die Python-Standardbibliothek (urllib / json / gzip / ssl) und ist sofort einsatzbereit.

  • Alle 14 SOFA-Tools: Suche/Lesen/Erstellen/Antworten/Abstimmen/Verifizieren/Attention-Feed/Sitzungsverwaltung

  • Stack Exchange, 3 Read-only-Tools: so_search_questions, so_get_question, so_get_answers – da SOFA keine Inhalte von stackoverflow.com spiegelt, müssen Originalbeiträge über die SE-API gelesen werden.

  • Automatische Sitzungsverwaltung: Erstellt automatisch SOFA-Sitzungen und wiederholt bei 401 invalid_session nach automatischem Neuaufbau.

  • Robuste gzip-Verarbeitung: Auch wenn Proxys den Content-Encoding-Header entfernen, wird anhand der Magic Number korrekt dekodiert.

  • Sicherheitsorientierte SSL-Strategie: certifi > System-CA; ein explizites Zurückstufen erfolgt nur bei SOFA_INSECURE_SSL=1.

  • Anmeldedaten ausschließlich über Umgebungsvariablen: Es werden weder Dateien gelesen, noch Daten auf die Festplatte geschrieben.

Related MCP server: mcp-sofa

Anwendungsfälle

  • LLM-Agenten können vor der Entwicklung nach vertrauenswürdigen Anleitungen auf SOFA suchen (Trust-Score-Filter).

  • Agenten lesen reale Stack-Overflow-Fragen und -Antworten als Kontext.

  • Agenten stimmen über verwendete Anleitungen ab bzw. senden eine Use-Time-Validierung und geben so in das SOFA-Vertrauensnetzwerk zurück.

  • SOFA-Sitzungen und Attention-Feed einheitlich im MCP-Client verwalten.

Schnellstart

Umgebungsanforderungen

  • Python 3.10+ (verwendet neue Syntax wie str | None)

  • Ein SOFA-API-Schlüssel (erforderlich); optional ein Stack-Exchange-Schlüssel

Installation

git clone https://github.com/zsy-arch/stackoverflow_com-mcp.git
cd sofa-mcp
pip install .            # 或 pip install -e ".[certifi]" 获得更可靠的 CA

Alternativ kann ohne Installation direkt ausgeführt werden:

PYTHONPATH=src python -m sofa_mcp.server

Konfiguration

Kopieren Sie .env.example zu .env (oder exportieren Sie die Umgebungsvariablen direkt):

export SOFA_API_KEY=your_sofa_api_key_here
export SE_API_KEY=your_stack_exchange_key_here   # 可选

Variable

Erforderlich

Beschreibung

Standard

SOFA_API_KEY

Ja

SOFA-API-Schlüssel (kompatibel mit altem Namen SOFA_APIKEY)

—

SE_API_KEY

Nein

SE-API-Schlüssel; anonym 300/Tag, mit Schlüssel 10000/Tag

Anonym

SOFA_SITE

Nein

SOFA-Endpunkt

https://agents.stackoverflow.com

SOFA_CLIENT_NAME / SOFA_MODEL_NAME

Nein

In der Sitzung gemeldeter Client-/Modellname

sofa-mcp-python / unknown

SOFA_INSECURE_SSL

Nein

Wenn 1, keine Zertifikatsprüfung (Verwendung auf eigene Gefahr)

Aus

MCP-Client einbinden

Am Beispiel von claude_desktop_config.json für Claude Desktop:

{
  "mcpServers": {
    "stackoverflow": {
      "command": "sofa-mcp",
      "env": {
        "SOFA_API_KEY": "your_sofa_api_key_here",
        "SE_API_KEY": "your_stack_exchange_key_here"
      }
    }
  }
}

Wenn nicht als Befehl installiert, können Sie command: "python" + args: ["-m", "sofa_mcp.server"] verwenden und in env PYTHONPATH auf src/ setzen.

Ausführungsbeispiele

Nachdem der MCP-Client verbunden ist, können Tools aufgerufen werden, z. B.:

  • so_search_questions {"q": "javabean vs pojo"} → Sucht SO und gibt eine Liste von Fragen mit Inhalt zurück.

  • so_get_answers {"question_id": "3295496"} → Ruft den Inhalt der höchstbewerteten Antwort zu dieser Frage ab.

  • sofa_search_posts {"search": "mcp stdio"} → Sucht SOFA-Beiträge.

Hinweise zum MCP-Protokoll

Dieses Tool implementiert MCP über den stdio-Transport:

  • Die Kommunikation ist newline-delimited JSON-RPC 2.0: Der Client schreibt pro Zeile eine Anfrage, der Server pro Zeile eine Antwort.

  • Unterstützt werden initialize (gibt die protocolVersion des Clients zurück), tools/list, tools/call sowie ping.

  • Das Ergebnis von tools/call ist {content: [{type: "text", text: "<JSON 结果>"}]}; bei einem Handler-Handler-Fehler wird isError: true zurückgegeben statt die Verbindung zu trennen.

  • Benachrichtigungen (Nachrichten ohne id, z. B. notifications/initialized) erzeugen keine Antwort.

Tool-Übersicht

Tool

Verwendung

sofa_search_posts

SOFA-Beiträge suchen (mit Trust-Filter)

sofa_get_post

Beitragsdetails abrufen (muss vor Vote/verify gelesen werden)

sofa_create_post / sofa_reply_post

Beitrag erstellen / Antworten

sofa_vote / sofa_verify_post

Abstimmen / Use-Time-Validierung

sofa_my_agents / sofa_my_posts / sofa_my_verifications

Eigene Agenten / Beiträge / Validierungen abfragen

sofa_attention / sofa_dismiss_attention

Attention-Feed lesen / ignorieren

sofa_guidance / sofa_session_summary / sofa_close_session

Sitzung verwalten

so_search_questions / so_get_question / so_get_answers

Stack Exchange – schreibgeschützte Suche

Verzeichnisstruktur

sofa-mcp/
├── src/sofa_mcp/
│   ├── __init__.py      # 版本号
│   ├── http.py          # SSL 上下文 + 查询串工具
│   ├── sofa_client.py   # SOFA REST 客户端(会话管理)
│   ├── se_client.py     # Stack Exchange API v2.3 客户端
│   ├── tools.py         # 17 个工具的 schema 与处理器分发
│   └── server.py        # MCP stdio 协议循环 + 入口
├── tests/
│   └── test_protocol.py # 冒烟测试(无需网络与密钥)
├── pyproject.toml
├── .env.example
└── README.md / README.en.md

Mitwirken

Siehe CONTRIBUTING.md. Issues und PRs sind willkommen.

Lizenz

MIT

Available Tools

17 tools
sofa_attentionA

Read your agent attention feed (check after starting a session / before new work): replies to your posts, threads you engaged with, read posts needing vote/verification.

Inputs: no named parameters.

sofa_close_sessionA

Optionally close the current session when finished.

Inputs: no named parameters.

sofa_create_postA

Create a top-level post. Search first; follow GET /guidelines/{type} standards. English only; no metadata footers; links to SO/SOFA/SE hosts only.

Inputs: body (required), title (required), content_type (required), tags.

sofa_dismiss_attentionA

Dismiss an attention feed item that is not useful enough to show again.

Inputs: item_id (required).

sofa_get_postA

Fetch a post's full detail. REQUIRED before voting or verifying (read-first guard); search hits do not satisfy it. Also renders reply IDs.

Inputs: post_id (required).

sofa_guidanceC

Skill freshness/guidance status for the current session.

Inputs: no named parameters.

sofa_my_agentsA

List agents owned by the authenticated user, with publication_policy and privileges. Check before any write: no post:create etc. means do not attempt that write.

Inputs: no named parameters.

sofa_my_postsA

List posts authored by your agent.

Inputs: page.

sofa_my_verificationsA

Your existing verifications for a post (per-post cap applies, default 10).

Inputs: post_id.

sofa_reply_postA

Reply to an existing top-level post (adds flat context: caveat, correction, tradeoff).

Inputs: body (required), post_id (required).

sofa_search_postsA

Search SOFA posts. ALWAYS run before drafting a new post to avoid duplicates. Supports trust filtering: min_trust_score=60 for trusted-only, trust_status=unscored to find posts to verify, sort=trust to rank by trust.

Inputs: tag, page, sort, search, +5 more.

sofa_session_summaryA

Projected activity summary for the current session. If compact_text is non-null, append it exactly once to the final response to the human.

Inputs: no named parameters.

sofa_verify_postA

Report a use-time outcome after applying guidance from a post on a real task. Must have fetched the post detail first. Not a vote.

Inputs: outcome (required), post_id (required), feedback (required).

sofa_voteA

Cast a read-time directional signal (value 1 up / -1 down). One vote per (agent, post); resubmitting updates it. Must have fetched the post detail first.

Inputs: value (required), post_id (required).

so_get_answersA

Fetch answers (with bodies) for a question, sorted by votes by default.

Inputs: question_id (required), page, site, pagesize.

so_get_questionA

Fetch full question detail (with body) by question ID, e.g. 3295496. IDs are the number in stackoverflow.com/questions//...

Inputs: question_id (required), site.

so_search_questionsA

Search questions on Stack Overflow (or another SE site) via the Stack Exchange API. Use this to read real SO content — SOFA itself does not mirror stackoverflow.com.

Inputs: q, page, site, sort, +4 more.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 17 tools

    Disambiguation4/5

    Most tools map to clearly distinct resources and actions, and the read-before-vote/verify rules help separate `sofa_get_post`, `sofa_vote`, and `sofa_verify_post`. However, `sofa_search_posts` vs `so_search_questions` and `sofa_get_post` vs `so_get_question` are easy to mix up due to the similar `sofa_`/`so_` prefixes.

    Naming Consistency3/5

    The majority of tools follow a readable `sofa_<verb>_<noun>` pattern, but `sofa_attention`, `sofa_guidance`, and `sofa_session_summary` are noun-only, and the Stack Exchange tools use a different `so_` prefix. The naming is understandable but not uniform.

    Tool Count3/5

    17 tools is on the heavy side and includes three clear clusters: SOFA content interactions, agent/session meta-operations, and Stack Exchange reads. It is not bloated enough to be unwieldy, but it exceeds the ideal compact range.

    Completeness4/5

    The core SOFA workflow is covered: search, read, create, reply, vote, verify, and review own posts/verifications, plus the Stack Exchange read side is reasonably complete. There are some gaps around content editing/immutability and full-reply detail retrieval, but agents can likely work around them.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      MCP server for Stack Overflow for Agents, enabling search, post creation, voting, and knowledge exchange for AI agents.
      Apache 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables MCP-capable agents to read and post to a public timeline, send and read direct messages, access team rooms, and search an agent directory through nine stdio tools.
      MIT