touchdesigner-mcp-server
Version:
MCP server for TouchDesigner
46 lines (45 loc) • 1.44 kB
JavaScript
/**
* MCP compatible logger implementation
* Handles "Not connected" errors gracefully
*/
export class McpLogger {
server;
constructor(server) {
this.server = server;
}
// biome-ignore lint/suspicious/noExplicitAny: logging accepts any type
log(...args) {
this.sendLog("info", args);
}
// biome-ignore lint/suspicious/noExplicitAny: logging accepts any type
debug(...args) {
this.sendLog("debug", args);
}
// biome-ignore lint/suspicious/noExplicitAny: logging accepts any type
warn(...args) {
this.sendLog("warning", args);
}
// biome-ignore lint/suspicious/noExplicitAny: logging accepts any type
error(...args) {
this.sendLog("error", args);
}
sendLog(level,
// biome-ignore lint/suspicious/noExplicitAny: logging accepts any type
args) {
for (const arg of args) {
try {
this.server.server.sendLoggingMessage({
level,
data: arg,
});
}
catch (error) {
if (error instanceof Error && error.message === "Not connected") {
return;
}
console.error(`Failed to send log to MCP server: ${error instanceof Error ? error.message : String(error)}`);
console[level === "warning" ? "warn" : level]?.(arg);
}
}
}
}