Skip to main content

A server that exposes a set of tools for interacting with Stack Overflow API. It provides functionality for searching questions, answers, tags, and retrieving detailed information from Stack Overflow.

Project description

Stack Overflow MCP Server

A Model Context Protocol (MCP) server that provides comprehensive tools for interacting with Stack Overflow through the Stack Exchange API. This server enables AI assistants to search questions, get detailed answers, and explore Stack Overflow content through a standardized interface.

License: MIT Python 3.11+ FastMCP

๐Ÿš€ Features

  • Question Search - Advanced search with multiple filters and sorting options
  • Question Details - Get comprehensive information including answers and comments
  • Answer Search - Find and retrieve detailed answer information
  • Tag Support - Search questions by specific tags
  • Type Safety - Full Pydantic validation for all inputs
  • Error Handling - Comprehensive error reporting and logging

๐Ÿ“ฆ Installation

Using uvx (Recommended)

uvx stack-overflow-mcp-light

Using uv

uv add stack-overflow-mcp-light
uv run stack-overflow-mcp-light

Using pip

pip install stack-overflow-mcp-light
stack-overflow-mcp-light

โš™๏ธ Configuration

Environment Variables

Configure the following environment variables:

# Optional: Stack Exchange API key for higher rate limits
export STACK_EXCHANGE_API_KEY="your_api_key_here"

# Optional: Show detailed logs for debugging (default: false)
export STACK_OVERFLOW_MCP_SHOW_LOGS="false"

๐Ÿ’ก API Key: While optional, an API key significantly increases your rate limits from 300 to 10,000 requests per day.

Environment Variable Details

  • STACK_EXCHANGE_API_KEY (Optional): Your Stack Exchange API key for increased rate limits. Get one at Stack Apps
  • STACK_OVERFLOW_MCP_SHOW_LOGS (Optional): Set to "true" to enable detailed logging for debugging and development

Claude Desktop Configuration

Add to your Claude Desktop claude_desktop_config.json:

{
  "mcpServers": {
    "stack-overflow": {
      "command": "uvx",
      "args": ["--no-progress", "stack-overflow-mcp-light"],
      "env": {
        "STACK_EXCHANGE_API_KEY": "your_api_key_here",
        "STACK_OVERFLOW_MCP_SHOW_LOGS": "false"
      },
      "transport": "stdio"
    }
  }
}

Alternative Configurations

Using uv directly:

{
  "mcpServers": {
    "stack-overflow": {
      "command": "uv",
      "args": ["run", "--with", "stack-overflow-mcp-light", "stack-overflow-mcp-light"],
      "env": {
        "STACK_EXCHANGE_API_KEY": "your_api_key_here",
        "STACK_OVERFLOW_MCP_SHOW_LOGS": "false"
      },
      "transport": "stdio"
    }
  }
}

Local development:

{
  "mcpServers": {
    "stack-overflow": {
      "command": "uv",
      "args": ["run", "stack-overflow-mcp-light"],
      "cwd": "/path/to/stack-overflow-mcp",
      "env": {
        "STACK_EXCHANGE_API_KEY": "your_api_key_here",
        "STACK_OVERFLOW_MCP_SHOW_LOGS": "true"
      },
      "transport": "stdio"
    }
  }
}

๐Ÿ› ๏ธ Available Tools

โ“ Question Tools (4 tools)

search_questions

Search Stack Overflow questions with advanced filters.

  • Input: Search parameters including:
    • q - Free-form text search
    • tagged - Semi-colon delimited list of tags
    • intitle - Search in question titles
    • nottagged - Exclude these tags
    • body - Text in question body
    • accepted - Has accepted answer (boolean)
    • closed - Question is closed (boolean)
    • answers - Minimum number of answers
    • views - Minimum view count
    • sort - Sort criteria ("activity", "votes", "creation", "hot", "week", "month", "relevance")
    • order - Sort order ("asc" or "desc")
    • page - Page number (1-25)
    • page_size - Items per page (1-100)
  • Output: Search results with questions matching criteria

get_question_details

Get detailed information about a specific question.

  • Input: question_id, include_body (boolean), include_comments (boolean), include_answers (boolean)
  • Output: Comprehensive question information including body, answers, and optionally comments

get_questions_by_tag

Get questions that have a specific tag.

  • Input: tag (tag name), sort, order, page, page_size
  • Output: Questions with the specified tag

get_question_answers

Get answers for a specific question.

  • Input: question_id
  • Output: All answers for the specified question

๐Ÿ’ฌ Answer Tools (3 tools)

search_answers

Search Stack Overflow answers using text search.

  • Input: q (optional search query), sort, order, page, page_size
  • Output: Search results with answers matching the query

get_answer_details

Get detailed information about a specific answer.

  • Input: answer_id, include_body (boolean), include_comments (boolean)
  • Output: Detailed answer information including body and optionally comments

get_top_answers

Get top-voted answers from Stack Overflow.

  • Input: None (uses default sorting by votes)
  • Output: Top answers sorted by vote count

๐Ÿงช Testing

The project includes comprehensive tests covering all tools:

# Run all tests
make test

# Run with coverage
make test-cov

# Run specific test categories
uv run pytest tests/test_server.py::TestQuestionTools -v

๐Ÿ”ง Development

Setup Development Environment

# Clone the repository
git clone https://github.com/midodimori/stack-overflow-mcp.git
cd stack-overflow-mcp

# Install with development dependencies
make install-dev

# Run tests
make test

# Format and lint code
make format

# Check code style and types
make lint

# Run the server locally
make run

# See all available commands
make help

Project Structure

stack-overflow-mcp/
โ”œโ”€โ”€ src/stack_overflow_mcp_light/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ server.py          # MCP server implementation
โ”‚   โ”œโ”€โ”€ models.py          # Pydantic models
โ”‚   โ”œโ”€โ”€ logging_config.py  # Logging configuration
โ”‚   โ””โ”€โ”€ tools/             # Tool implementations
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ base_client.py # Base client for Stack Exchange API
โ”‚       โ”œโ”€โ”€ questions.py   # Question search and retrieval tools
โ”‚       โ””โ”€โ”€ answers.py     # Answer search and retrieval tools
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_server.py     # Tool function tests
โ”‚   โ””โ”€โ”€ test_mcp_integration.py  # MCP integration tests
โ”œโ”€โ”€ pyproject.toml         # Project configuration
โ””โ”€โ”€ README.md

๐Ÿ“š API Reference

Question Sort Options

  • activity: Sort by last activity date (default)
  • votes: Sort by question score
  • creation: Sort by creation date
  • hot: Sort by current hotness
  • week: Sort by weekly activity
  • month: Sort by monthly activity
  • relevance: Sort by search relevance

Answer Sort Options

  • activity: Sort by last activity date (default)
  • votes: Sort by answer score
  • creation: Sort by creation date

Sort Order

  • desc: Descending order (default)
  • asc: Ascending order

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

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

โš ๏ธ Disclaimer

This software is provided for educational and informational purposes only. This tool interacts with Stack Overflow's public API and respects their rate limits and terms of service. The authors are not responsible for any misuse of the Stack Exchange API or violation of their terms of service.

๐Ÿ”— Links

๐Ÿ“ž Support

For questions, issues, or contributions:

  • Open an issue on GitHub
  • Check the Stack Overflow Meta for API-related questions
  • Review the comprehensive test suite for usage examples

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stack_overflow_mcp_light-1.0.3.tar.gz (92.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stack_overflow_mcp_light-1.0.3-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file stack_overflow_mcp_light-1.0.3.tar.gz.

File metadata

  • Download URL: stack_overflow_mcp_light-1.0.3.tar.gz
  • Upload date:
  • Size: 92.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stack_overflow_mcp_light-1.0.3.tar.gz
Algorithm Hash digest
SHA256 6bbb7b2bd10d415198eaad9e45ba69d4a84eea1f654a07161cf600a6a0701db2
MD5 9905f57fbd93f9267bf10855cd19ea5d
BLAKE2b-256 8ae7ade375d501f9048aac37c35141976915c65016157b4df93f3332e7c52018

See more details on using hashes here.

Provenance

The following attestation bundles were made for stack_overflow_mcp_light-1.0.3.tar.gz:

Publisher: publish.yml on midodimori/stack-overflow-mcp-light

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stack_overflow_mcp_light-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for stack_overflow_mcp_light-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aaf64a9ccba1e74d8a59b7d5d102fb579610da72ee94cd88c89c54f2dc9c3eb6
MD5 dd84b4b62194c0b688fd426b88674cec
BLAKE2b-256 c69033884b42b01e286ef91d6bba4b46597300380726763c8e810027f076de91

See more details on using hashes here.

Provenance

The following attestation bundles were made for stack_overflow_mcp_light-1.0.3-py3-none-any.whl:

Publisher: publish.yml on midodimori/stack-overflow-mcp-light

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page