返回市场
堆溢出-MCP

堆溢出-MCP

作者:gscalzo43 星标更新:2025-03-10

项目介绍

Stackoverflow MCP Server

这是一个用于查询Stack Overflow的Model Context Protocol服务器。此服务器帮助AI模型通过搜索Stack Overflow的问题和答案来找到编程问题的解决方案。

特性

  • 根据错误消息搜索
  • 根据编程语言和技术标签搜索
  • 堆栈跟踪分析
  • 按分数/投票过滤结果
  • 包含问题和答案的评论
  • 输出为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": []
    }
  }
}

可选:Stack Overflow API认证

该服务器无需认证即可工作,但有速率限制。要增加速率限制:

  1. Stack Apps获取API密钥
  2. 将API密钥添加到您的MCP设置配置中

使用方法

该服务器提供三种主要工具:

1. search_by_error

根据错误相关的问题搜索Stack Overflow:

interface SearchByErrorInput {
  errorMessage: string;          // 必填:要搜索的错误消息
  language?: string;            // 可选:编程语言
  technologies?: string[];      // 可选:相关技术
  minScore?: number;           // 可选:最低分数阈值
  includeComments?: boolean;    // 可选:在结果中包含评论
  responseFormat?: "json" | "markdown"; // 可选:响应格式
  limit?: number;              // 可选:最大结果数量
}

2. search_by_tags

根据标签搜索Stack Overflow的问题:

interface SearchByTagsInput {
  tags: string[];              // 必填:要搜索的标签
  minScore?: number;          // 可选:最低分数阈值
  includeComments?: boolean;   // 可选:在结果中包含评论
  responseFormat?: "json" | "markdown"; // 可选:响应格式
  limit?: number;             // 可选:最大结果数量
}

3. analyze_stack_trace

分析堆栈跟踪以查找相关解决方案:

interface StackTraceInput {
  stackTrace: string;          // 必填:要分析的堆栈跟踪
  language: string;           // 必填:编程语言
  includeComments?: boolean;   // 可选:在结果中包含评论
  responseFormat?: "json" | "markdown"; // 可选:响应格式
  limit?: number;             // 可选:最大结果数量
}

示例

根据错误消息搜索

{
  "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. 创建拉取请求

许可证

MIT