Skip to main content
Glama
stackoverflow-mcp-server

stackoverflow-mcp-server

by CodexVeritax

Stack Overflow MCP Server

Python Version License

This Model Context Protocol (MCP) server enables AI assistants like Claude to search and access Stack Overflow content through a standardized protocol, providing seamless access to programming solutions, error handling, and technical knowledge.

NOTE

The Stack Overflow MCP Server is currently in Beta. We welcome your feedback and encourage you to report any bugs by opening an issue.

Features

  • šŸ” Multiple Search Methods: Search by query, error message, or specific question ID

  • šŸ“Š Advanced Filtering: Filter results by tags, score, accepted answers, and more

  • 🧩 Stack Trace Analysis: Parse and find solutions for error stack traces

  • šŸ“ Rich Formatting: Get results in Markdown or JSON format

  • šŸ’¬ Comments Support: Optionally include question and answer comments

  • ⚔ Rate Limiting: Built-in protection to respect Stack Exchange API quotas

Example Prompts and Use Cases

Here are some example prompts you can use with Claude when the Stack Overflow MCP server is integrated:

Tool

Example Prompt

Description

search_by_query

"Search Stack Overflow for Django pagination best practices"

Finds the most relevant questions and answers about Django pagination techniques

search_by_query

"Find Python asyncio examples with tags python and asyncio"

Searches for specific code examples filtering by multiple tags

search_by_error

"Why am I getting 'TypeError: object of type 'NoneType' has no len()' in Python?"

Finds solutions for a common Python error

get_question

"Get Stack Overflow question 53051465 about React hooks"

Retrieves a specific question by ID, including all answers

analyze_stack_trace

"Fix this error: ReferenceError: useState is not defined at Component in javascript"

Analyzes JavaScript error to find relevant solutions

advanced_search

"Find highly rated answers about memory leaks in C++ with at least 10 upvotes"

Uses advanced filtering to find high-quality answers

Related MCP server: mcp-stackexchange

Prerequisites

Before using this MCP server, you need to:

  1. Get a Stack Exchange API key (see below)

  2. Have Python 3.10+ installed

  3. Install uv (recommended)

Getting a Stack Exchange API Key

To use this server effectively, you'll need a Stack Exchange API key:

  1. Go to Stack Apps OAuth Registration

  2. Fill out the form with your application details:

    • Name: "Stack Overflow MCP" (or your preferred name)

    • Description: "MCP server for accessing Stack Overflow"

    • OAuth Domain: "localhost" (for local usage)

    • Application Website: Your website or leave blank

  3. Submit the form

  4. Copy your API Key (shown as "Key" on the next page)

This API key is not considered a secret and may be safely embedded in client-side code or distributed binaries. It simply allows you to receive a higher request quota when making requests to the Stack Exchange API.

Installation

Installing from PyPI

Stackoverflow PyPI page

# Using pip
pip install stackoverflow-mcp

# OR Using uv
uv venv
uv pip install stackoverflow-mcp

# OR using uv wihtout an venv
uv pip install stackoverflow-mcp --system

Installing from Source

# Clone the repository
git clone https://github.com/yourusername/stackoverflow-mcp-server.git
cd stackoverflow-mcp-server

# Install with uv
uv venv
uv pip install -e .

Adding to Claude Desktop

To run the Stack Overflow MCP server with Claude Desktop:

  1. Download Claude Desktop.

  2. Launch Claude and navigate to: Settings > Developer > Edit Config.

  3. Update your claude_desktop_config.json file with the following configuration:

{
  "mcpServers": {
    "stack-overflow": {
      "command": "uv",
      "args": ["run", "-m", "stackoverflow_mcp"],
      "env": {
        "STACK_EXCHANGE_API_KEY": "your_API_key"
      }
    }
  }
}

You can also specify a custom directory:

{
  "mcpServers": {
    "stack-overflow": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/stackoverflow-mcp-server",
        "run",
        "main.py"
      ],
      "env": {
        "STACK_EXCHANGE_API_KEY": "your_api_key_here"
      }
    }
  }
}

Configuration

Environment Variables

The server can be configured using these environment variables:

# Required
STACK_EXCHANGE_API_KEY=your_api_key_here

# Optional
MAX_REQUEST_PER_WINDOW=30     # Maximum requests per rate limit window
RATE_LIMIT_WINDOW_MS=60000    # Rate limit window in milliseconds (1 minute)
RETRY_AFTER_MS=2000           # Delay after hitting rate limit

Using a .env File

You can create a .env file in the project root:

STACK_EXCHANGE_API_KEY=your_api_key_here
MAX_REQUEST_PER_WINDOW=30
RATE_LIMIT_WINDOW_MS=60000
RETRY_AFTER_MS=2000

Usage

Available Tools

The Stack Overflow MCP server provides the following tools:

1. search_by_query

Search Stack Overflow for questions matching a query.

Parameters:
- query: The search query
- tags: Optional list of tags to filter by (e.g., ["python", "pandas"])
- excluded_tags: Optional list of tags to exclude
- min_score: Minimum score threshold for questions
- has_accepted_answer: Whether questions must have an accepted answer
- include_comments: Whether to include comments in results
- response_format: Format of response ("json" or "markdown")
- limit: Maximum number of results to return

2. search_by_error

Search Stack Overflow for solutions to an error message.

Parameters:
- error_message: The error message to search for
- language: Programming language (e.g., "python", "javascript")
- technologies: Related technologies (e.g., ["react", "django"])
- min_score: Minimum score threshold for questions
- include_comments: Whether to include comments in results
- response_format: Format of response ("json" or "markdown")
- limit: Maximum number of results to return

3. get_question

Get a specific Stack Overflow question by ID.

Parameters:
- question_id: The Stack Overflow question ID
- include_comments: Whether to include comments in results
- response_format: Format of response ("json" or "markdown")

4. analyze_stack_trace

Analyze a stack trace and find relevant solutions on Stack Overflow.

Parameters:
- stack_trace: The stack trace to analyze
- language: Programming language of the stack trace
- include_comments: Whether to include comments in results
- response_format: Format of response ("json" or "markdown")
- limit: Maximum number of results to return

Advanced search for Stack Overflow questions with many filter options.

Parameters:
- query: Free-form search query
- tags: List of tags to filter by
- excluded_tags: List of tags to exclude
- min_score: Minimum score threshold
- title: Text that must appear in the title
- body: Text that must appear in the body
- answers: Minimum number of answers
- has_accepted_answer: Whether questions must have an accepted answer
- sort_by: Field to sort by (activity, creation, votes, relevance)
- include_comments: Whether to include comments in results
- response_format: Format of response ("json" or "markdown")
- limit: Maximum number of results to return

Development

This section is for contributors who want to develop or extend the Stack Overflow MCP server.

Setting Up Development Environment

# Clone the repository
git clone https://github.com/yourusername/stackoverflow-mcp-server.git
cd stackoverflow-mcp-server

# Install dev dependencies
uv pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# Run specific test modules
pytest tests/test_formatter.py
pytest tests/test_server.py

# Run tests with coverage report
pytest --cov=stackoverflow_mcp

Project Structure

stackoverflow-mcp-server/
ā”œā”€ā”€ stackoverflow_mcp/          # Main package
│   ā”œā”€ā”€ __init__.py
|   |── __main__.py             # Entry point
│   ā”œā”€ā”€ api.py                  # Stack Exchange API client
│   ā”œā”€ā”€ env.py                  # Environment configuration
│   ā”œā”€ā”€ formatter.py            # Response formatting utilities
│   ā”œā”€ā”€ server.py               # MCP server implementation
│   └── types.py                # Data classes
ā”œā”€ā”€ tests/                      # Test suite
│   ā”œā”€ā”€ api/
│   │   └── test_search.py      # API search tests
│   ā”œā”€ā”€ test_formatter.py       # Formatter tests
│   ā”œā”€ā”€ test_general_api_health.py  # API health tests
│   └── test_server.py          # Server tests
ā”œā”€ā”€ pyproject.toml              # Package configuration
ā”œā”€ā”€ api_query.py                # testing stackexchange outside of MCP context
ā”œā”€ā”€ LICENSE                     # License file
└── README.md                   # This file

Contributing

Contributions are welcome! Here's how you can contribute:

  1. Fork the repository

  2. Create a feature branch: git checkout -b feature/my-feature

  3. Commit your changes: git commit -am 'Add new feature'

  4. Push to the branch: git push origin feature/my-feature

  5. Submit a pull request

Please make sure to update tests as appropriate and follow the project's coding style.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Available Tools

5 tools
analyze_stack_traceA

Analyze a stack trace and find relevant solutions on Stack Overflow.

Args:
    stack_trace (str): The stack trace to analyze
    language (str): Programming language of the stack trace
    excluded_tags (Optional[List[str]]): Optional list of tags to exclude
    min_score (Optional[int]): Minimum score threshold for questions
    has_accepted_answer (Optional[bool]): Whether questions must have an accepted answer
    answers (Optional[int]): Minimum number of answers
    include_comments (Optional[bool]): Whether to include comments in results
    response_format (Optional[str]): Format of response ("json" or "markdown")
    limit (Optional[int]): Maximum number of results to return
    ctx (Context): The context is passed automatically by the MCP
    
Returns:
    str: Formatted search results

Inputs: stack_trace (required), language (required), excluded_tags, min_score, +5 more.

get_questionA

Get a specific Stack Overflow question by ID.

Args:
    question_id (int): The Stack Overflow question ID
    include_comments (Optional[bool]): Whether to include comments in results
    response_format (Optional[str]): Format of response ("json" or "markdown")
    ctx (Context): The context is passed automatically by the MCP

Returns:
    str: Formatted question details

Inputs: question_id (required), include_comments, response_format.

search_by_errorA

Search Stack Overflow for solutions to an error message

Args:
    error_message (str): The error message to search for
    language (Optional[str]): Programming language (e.g., "python", "javascript")
    technologies (Optional[List[str]]): Related technologies (e.g., ["react", "django"])
    excluded_tags (Optional[List[str]]): Optional list of tags to exclude
    min_score (Optional[int]): Minimum score threshold for questions
    has_accepted_answer (Optional[bool]): Whether questions must have an accepted answer
    answers (Optional[int]): Minimum number of answers
    include_comments (Optional[bool]): Whether to include comments in results
    response_format (Optional[str]): Format of response ("json" or "markdown")
    limit (Optional[int]): Maximum number of results to return
    ctx (Context): The context is passed automatically by the MCP

Returns:
    str: Formatted search results

Inputs: error_message (required), language, technologies, excluded_tags, +6 more.

search_by_queryB

Search Stack Overflow for questions matching a query.

Args:
    query (str): The search query
    tags (Optional[List[str]]): Optional list of tags to filter by (e.g., ["python", "pandas"])
    excluded_tags (Optional[List[str]]): Optional list of tags to exclude
    min_score (Optional[int]): Minimum score threshold for questions
    title (Optional[str]): Text that must appear in the title
    body (Optional[str]): Text that must appear in the body
    has_accepted_answer (Optional[bool]): Whether questions must have an accepted answer
    answers (Optional[int]): Minimum number of answers
    sort_by (Optional[str]): Field to sort by (activity, creation, votes, relevance)
    include_comments (Optional[bool]): Whether to include comments in results
    response_format (Optional[str]): Format of response ("json" or "markdown")
    limit (Optional[int]): Maximum number of results to return
    ctx (Context): The context is passed automatically by the MCP

Returns:
    str: Formatted search results

Inputs: query (required), tags, excluded_tags, min_score, +8 more.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 5 tools

    Disambiguation4/5

    Tools have distinct purposes: advanced_search for comprehensive filtering, search_by_query for simpler queries, search_by_error for errors, analyze_stack_trace for stack traces, and get_question for specific retrieval. There is some overlap between advanced_search and search_by_query, but descriptions clearly differentiate them.

    Naming Consistency5/5

    All tool names follow a consistent snake_case verb_noun pattern (e.g., advanced_search, get_question, search_by_error). No mixing of conventions, making it easy to predict naming for hypothetical additional tools.

    Tool Count4/5

    5 tools is slightly below average but appropriate for a focused search-only server. Each tool covers a key use case (general search, error search, stack trace analysis, specific question retrieval). Could benefit from one more tool (e.g., for answers) but current count is reasonable.

    Completeness3/5

    Covers main search scenarios well, including advanced filtering, error messages, and stack traces. However, lacks tools for retrieving answers separately or exploring tags/users. The presence of two very similar search tools (advanced_search vs search_by_query) suggests slight redundancy rather than full coverage.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides instant access to a searchable knowledge base of 16,000+ community-driven troubleshooting solutions for common coding problems. Includes community feedback and smart ranking to help AI assistants find the most effective solutions.
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Wraps the StackExchange API v2.3 to enable reading StackExchange data (questions, answers, etc.) without authentication. Allows AI agents to query StackExchange content through natural language or direct tool calls.
      286 npm
      1
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides LLMs with tools to search Stack Overflow for programming solutions, helping ground responses in real-world code examples.
      -