jira-server-mcp
Version:
MCP (Model Context Protocol) para integração com Jira Server auto-hospedado. Uso principal via configuração MCP (mcp.json) para automações e integrações.
67 lines (58 loc) • 1.59 kB
JavaScript
import http from 'http';
import { URL } from 'url';
import { JiraAPI } from './index.js';
const PORT = process.env.PORT || 8080;
const server = http.createServer(async (req, res) => {
const url = new URL(req.url, `http://${req.headers.host}`);
// Configurar cabeçalhos SSE
if (url.pathname === '/sse') {
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Access-Control-Allow-Origin': '*'
});
// Manter conexão viva
const keepAlive = setInterval(() => {
res.write(':\n\n');
}, 30000);
// Limpar intervalo quando a conexão for fechada
req.on('close', () => {
clearInterval(keepAlive);
});
try {
const config = {
baseUrl: process.env.JIRA_BASE_URL,
authentication: {
basic: {
apiToken: process.env.JIRA_API_TOKEN
}
}
};
const jira = new JiraAPI(config);
const user = await jira.getMyself();
// Enviar mensagem de sucesso
res.write(`data: ${JSON.stringify({
type: 'success',
data: {
message: 'Conexão estabelecida com sucesso!',
user
}
})}\n\n`);
} catch (error) {
// Enviar mensagem de erro
res.write(`data: ${JSON.stringify({
type: 'error',
data: {
message: error.message
}
})}\n\n`);
}
} else {
res.writeHead(404);
res.end();
}
});
server.listen(PORT, () => {
console.log(`Servidor SSE rodando na porta ${PORT}`);
});