Stack Overflow查询服务

一个用于查询Stack Overflow问题和答案的服务器,帮助AI模型和开发者快速找到编程问题的解决方案。

  • by gscalzo
  • TypeScript
  • 本地部署
  • 73 星标
  • 更新于
在 GitHub 查看 gscalzo/stackoverflow-mcp

使用说明

堆栈溢出MCP服务器

用于查询堆栈溢出的模型上下文协议服务器。该服务器通过搜索Stack Overflow问题和答案来帮助AI模型找到编程问题的解决方案。

特性

  • 按错误消息搜索
  • 按编程语言和技术标签搜索
  • 堆栈跟踪分析
  • 按分数/投票筛选结果
  • 包括问答评论
  • 以JSON或Markdown格式输出

安装

您可以直接使用npx运行服务器:

npx -y @gscalzo/stackoverflow-mcp

或者全局安装:

npm install -g @gscalzo/stackoverflow-mcp

配置服务器

创建或修改MCP设置文件:

  • 对于Claude.app: ~/Library/Application Support/Cursor/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
  • 对于Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json

添加以下配置:

{
  "mcpServers": {
    "stackoverflow": {
      "command": "npx",
      "args": ["-y", "@gscalzo/stackoverflow-mcp"],
      "env": {
        "STACKOVERFLOW_API_KEY": "your-api-key-optional"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

可选:堆栈溢出API身份验证

服务器在没有身份验证的情况下工作,但有速率限制。要提高费率限制:

  1. 从获取API密钥 堆栈应用程序
  2. 将API密钥添加到MCP设置配置中

用法

服务器提供三个主要工具:

1.搜索_错误

在Stack Overflow中搜索与错误相关的问题:

interface SearchByErrorInput {
  errorMessage: string;          // Required: Error message to search for
  language?: string;            // Optional: Programming language
  technologies?: string[];      // Optional: Related technologies
  minScore?: number;           // Optional: Minimum score threshold
  includeComments?: boolean;    // Optional: Include comments in results
  responseFormat?: "json" | "markdown"; // Optional: Response format
  limit?: number;              // Optional: Maximum number of results
}

2.搜索_ _标签

按标签搜索Stack Overflow问题:

interface SearchByTagsInput {
  tags: string[];              // Required: Tags to search for
  minScore?: number;          // Optional: Minimum score threshold
  includeComments?: boolean;   // Optional: Include comments in results
  responseFormat?: "json" | "markdown"; // Optional: Response format
  limit?: number;             // Optional: Maximum number of results
}

3.分析_跟踪_跟踪

分析堆栈痕迹以找到相关解决方案:

interface StackTraceInput {
  stackTrace: string;          // Required: Stack trace to analyze
  language: string;           // Required: Programming language
  includeComments?: boolean;   // Optional: Include comments in results
  responseFormat?: "json" | "markdown"; // Optional: Response format
  limit?: number;             // Optional: Maximum number of results
}

例子

按错误消息搜索

{
  "name": "search_by_error",
  "arguments": {
    "errorMessage": "TypeError: Cannot read property 'length' of undefined",
    "language": "javascript",
    "technologies": ["react"],
    "minScore": 5,
    "includeComments": true,
    "responseFormat": "markdown",
    "limit": 3
  }
}

按标签搜索

{
  "name": "search_by_tags",
  "arguments": {
    "tags": ["python", "pandas", "dataframe"],
    "minScore": 10,
    "includeComments": true,
    "responseFormat": "json",
    "limit": 5
  }
}

分析堆栈跟踪

{
  "name": "analyze_stack_trace",
  "arguments": {
    "stackTrace": "Error: ENOENT: no such file or directory, open 'config.json'\n    at Object.openSync (fs.js:476:3)\n    at Object.readFileSync (fs.js:377:35)",
    "language": "javascript",
    "includeComments": true,
    "responseFormat": "markdown",
    "limit": 3
  }
}

响应格式

JSON输出

答复包括:

  • 问题详细信息(标题、正文、分数、标签等)
  • 答案(按投票排序)
  • 问题和答案的可选评论
  • Stack Overflow原始帖子的链接

Markdown输出

markdown格式提供了一个格式良好的视图,包括:

  • 问题标题和分数
  • 问题正文
  • 评论(如有要求)
  • 带有接受状态和分数的答案
  • 回答意见(如有要求)
  • 链接到原始帖子

发展

  1. 内置手表模式:
npm run watch
  1. 运行测试:
npm test

贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 提交您的更改
  4. 推到分支
  5. 创建拉取请求

许可证

麻省理工学院