article
README
🚀 Semgrep MCP 服务器
Semgrep MCP 服务器是一个强大的工具,它基于 Semgrep 实现了 MCP 协议相关功能。通过它,用户可以更高效地进行代码扫描等操作,无论是使用 Docker 快速部署,还是手动基于 Python 安装,都能轻松上手。
🚀 快速开始
运行服务器
semgrep-mcp-serve
示例 Python SSE 客户端
from mcp.client.session import ClientSession
from mcp.client.sse import sse_client
async def main():
async with sse_client("http://localhost:8000/sse") as (read_stream, write_stream):
async with ClientSession(read_stream, write_stream) as session:
await session.initialize()
results = await session.call_tool(
"semgrep_scan",
{
"code_files": [
{
"filename": "hello_world.py",
"content": "def hello(): print('Hello, World!')",
}
]
},
)
print(results)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
📦 安装指南
使用 Docker 安装并运行
docker run -it --rm semgrep/mcp:latest
手动安装(基于 Python)
- 安装 Python:
- Windows:
# 安装 Python 3.x choco install python3 - macOS:
# 使用 Homebrew 安装 Python 3 brew install python
- Windows:
- 安装 Semgrep 和 MCP 服务器:
pip install semgrep mcp-server
📚 文档与资源
官方链接
社区与支持
- Slack 频道: #mcp
- Discussions: 在 GitHub Discussions 中提问或分享想法
🔧 贡献与开发
提交代码
- Fork 仓库并克隆到本地:
git clone https://github.com/semgrep/mcp-server.git cd mcp-server git checkout main - 创建功能分支并提交代码:
git checkout -b feature/your-feature-name # 进行代码修改 git add . git commit -m "添加新功能" git push origin feature/your-feature-name
提交 Pull Request
- 在 GitHub Issues 中创建问题或提出功能请求。
- 为每个功能或修复创建独立的 Pull Request。
🛠️ 其他工具
- Semgrep VS Code 插件: 官方扩展
- Semgrep IntelliJ 插件: IntelliJ 插件
👥 社区项目
- Semgrep 规则集: 官方规则仓库
- MCP 服务器实现: mcp-server-semgrep
微信扫一扫