MCP错误上下文协议的错误记录器,可将错误信息高效记录到Sentry,为项目的错误追踪提供有力支持。
MCP错误记录器能帮助你将错误信息记录到Sentry,以下是快速搭建MCP服务器的步骤:
安装依赖:
npm install @modelcontextprotocol/server @sentry/node
创建MCP服务器:
const { createServer } = require('@modelcontextprotocol/server');
const Sentry = require('@sentry/node');
Sentry.init('your_sentry_dsn');
createServer()
.use('/mcp', async (req, res) => {
// 处理请求并记录错误
try {
// 你的业务逻辑
throw new Error('Something went wrong');
} catch (error) {
Sentry.captureException(error);
res.json({ status: 'success' });
}
})
.listen(3000, () => {
console.log('MCP服务器已启动,监听在端口 3000');
});
通过设置环境变量来配置Sentry的DSN:
SSENTRY_DSN=your_sentry_dsn
fetch('http://localhost:3000/mcp', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
context: {
error: new Error('示例错误').stack,
timestamp: new Date().toISOString(),
environment: process.env.NODE_ENV,
},
}),
});
// 服务器将返回类似以下内容:
{ status: 'success' }
欢迎为项目贡献力量!你可以提交问题和拉取请求到GitHub仓库。
此MCP服务器受MIT License保护。你可以在MIT许可下自由使用、修改和分发软件,具体条款见项目仓库中的LICENSE文件。