Features: - Direct conversations (1-to-1) auto-created and permanent - Group conversations with leave/archive support - Real-time messaging via long-polling - Offline notifications via CLAUDE.md - Auto-registration on MCP startup Architecture: - Broker: Express HTTP server + SQLite - MCP Partner: Modular tools (one file per tool) - Full documentation and API reference
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
// Shared utilities and state for MCP partner
|
|
|
|
const BROKER_URL = process.env.BROKER_URL || "http://localhost:3210";
|
|
const PARTNER_NAME = process.env.PARTNER_NAME || "Claude";
|
|
|
|
// ID basé sur le dossier de travail (unique par projet)
|
|
const cwd = process.cwd();
|
|
const projectName = cwd.split(/[/\\]/).pop().toLowerCase().replace(/[^a-z0-9]/g, "_");
|
|
const myId = projectName || "partner";
|
|
|
|
let isRegistered = false;
|
|
|
|
/**
|
|
* Appel HTTP au broker
|
|
*/
|
|
async function brokerFetch(path, options = {}) {
|
|
const url = `${BROKER_URL}${path}`;
|
|
|
|
const fetchOptions = {
|
|
...options,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
...options.headers,
|
|
},
|
|
};
|
|
|
|
const response = await fetch(url, fetchOptions);
|
|
return response.json();
|
|
}
|
|
|
|
/**
|
|
* S'enregistrer auprès du broker
|
|
*/
|
|
async function ensureRegistered() {
|
|
if (!isRegistered) {
|
|
await brokerFetch("/register", {
|
|
method: "POST",
|
|
body: JSON.stringify({ partnerId: myId, name: PARTNER_NAME, projectPath: cwd }),
|
|
});
|
|
isRegistered = true;
|
|
console.error(`[MCP-PARTNER] Registered as ${PARTNER_NAME} (${myId}) at ${cwd}`);
|
|
}
|
|
}
|
|
|
|
function setRegistered(value) {
|
|
isRegistered = value;
|
|
}
|
|
|
|
export {
|
|
BROKER_URL,
|
|
PARTNER_NAME,
|
|
cwd,
|
|
myId,
|
|
isRegistered,
|
|
brokerFetch,
|
|
ensureRegistered,
|
|
setRegistered,
|
|
};
|