stackoverflow-mcp-server
Enables AI assistants to search and access Stack Overflow content, including questions, answers, and error solutions.
README
<div align="center">Stack Overflow MCP Server</div>
<div align="center">
</div>
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 |
Prerequisites
Before using this MCP server, you need to:
- Get a Stack Exchange API key (see below)
- Have Python 3.10+ installed
- Install uv (recommended)
Getting a Stack Exchange API Key
To use this server effectively, you'll need a Stack Exchange API key:
- Go to Stack Apps OAuth Registration
- 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
- Submit the form
- 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
# 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:
-
Download Claude Desktop.
-
Launch Claude and navigate to: Settings > Developer > Edit Config.
-
Update your
claude_desktop_config.jsonfile 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
5. advanced_search
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:
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -am 'Add new feature' - Push to the branch:
git push origin feature/my-feature - 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.
<p align="center"> Stack Overflow MCP Server: AI-accessible programming knowledge </p>
<!-- Badges -->
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。