Semgrep MCP 服务器是一个强大的工具,它基于 Semgrep 实现了 MCP 协议相关功能。通过它,用户可以更高效地进行代码扫描等操作,无论是使用 Docker 快速部署,还是手动基于 Python 安装,都能轻松上手。
semgrep-mcp-serve
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 run -it --rm semgrep/mcp:latest
# 安装 Python 3.x
choco install python3
# 使用 Homebrew 安装 Python 3
brew install python
pip install semgrep mcp-server
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