Skip to main content
Glama

Node Code Sandbox MCP

by mozicim
logger.ts1.75 kB
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; // Will be set once the server is initialized let serverInstance: McpServer | null = null; /** * Set the server instance for logging * @param server MCP server instance */ export function setServerInstance(server: McpServer): void { serverInstance = server; } /** * Log levels supported by MCP */ export type LogLevel = 'debug' | 'info' | 'warning' | 'error'; /** * Send a logging message using the MCP protocol * Falls back to console.error if server is not initialized * @param level Log level * @param message Message to log * @param data Optional data to include */ export function log(level: LogLevel, message: string, data?: unknown): void { if (serverInstance) { // Access the server through the internal server property // @ts-expect-error - _server is not documented in the public API but is available const internalServer = serverInstance._server; if ( internalServer && typeof internalServer.sendLoggingMessage === 'function' ) { internalServer.sendLoggingMessage({ level, data: data ? `${message}: ${JSON.stringify(data)}` : message, }); return; } } // Fallback if server is not initialized yet or doesn't support logging console.error(`[${level.toUpperCase()}] ${message}`, data || ''); } /** * Convenience methods for different log levels */ export const logger = { debug: (message: string, data?: unknown) => log('debug', message, data), info: (message: string, data?: unknown) => log('info', message, data), warning: (message: string, data?: unknown) => log('warning', message, data), error: (message: string, data?: unknown) => log('error', message, data), };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mozicim/node-code-sandbox-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server