Skip to main content

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.

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

👇 Use case examples with Claude — toggle

Find solutions to error messages

Finding solutions to error messages

Search for code examples

Searching for code examples

Analyze stack traces

Analyzing stack traces

Find specific questions

Finding specific questions

Prerequisites

Before using this MCP server, you need to:

  1. Get a Stack Exchange API key (see below)
  2. Have Python 3.8+ 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

# Using pip
pip install stackoverflow-mcp

# Using uv (recommended)
uv pip install stackoverflow-mcp

Installing from Source

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

# Install with uv
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", "main.py"],
      "env": {
        "STACK_EXCHANGE_API_KEY": "your_api_key_here"
      }
    }
  }
}

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
│   ├── 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
├── main.py                     # Entry point
├── setup.py                    # Package configuration
├── 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.


Stack Overflow MCP Server: AI-accessible programming knowledge

Metadata

Release files for stackoverflow-mcp-server 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stackoverflow-mcp-server 0.1.0
File Size Uploaded Provenance
stackoverflow_mcp_server-0.1.0.tar.gz 27.4 kB Without provenance Details

Release files / stackoverflow_mcp_server-0.1.0.tar.gz

Download URL stackoverflow_mcp_server-0.1.0.tar.gz
Size 27.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0557de538c908c49649360a39d9399772871f3fba47e157156897075a5e212c3
BLAKE2b-256 checksum
How to use checksums
b82cd171a14eef920343586adc9397f920b60632c91289b9b7054e35fc006454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Security for stackoverflow-mcp-server 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page