Skip to main content
mcp-use provides comprehensive logging for MCP servers, making it easy to understand server activity, debug issues, and monitor production deployments.

Log Levels

The server provides different logging levels through environment variables:

Production Mode (Default)

Clean, informative logs showing MCP operations:
node server.js
Output:
[MCP] Server mounted at /mcp (Streamable HTTP Transport)
[MCP] Session initialized: abc123
[MCP] tools/call:analyze-sentiment completed in 234ms
[MCP] Session closed: abc123

Debug Mode

Enable debug mode for development and troubleshooting:
DEBUG=1 node server.js
Output:
[MCP] Server initialized: my-server v1.0.0
[MCP] Registered tool: analyze-sentiment
[MCP] Registered resource: config://app-settings
[MCP] Session initialized: abc123
[MCP] tools/call:analyze-sentiment started
[MCP] tools/call:analyze-sentiment completed in 234ms

Verbose Debug Mode

Full request/response logging with JSON-RPC details:
DEBUG=2 node server.js
Output:
[MCP] Session initialized: abc123
[MCP] → Request: {
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "analyze-sentiment",
    "arguments": { "text": "I love this!" }
  }
}
[MCP] tools/call:analyze-sentiment completed in 234ms
[MCP] ← Response: {
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [{ "type": "text", "text": "Sentiment: positive" }]
  }
}

Tool Logging with ctx.log

Tools can send log messages directly to clients during execution using ctx.log(). This allows real-time visibility into what your tool is doing, which is especially useful for long-running operations or debugging tool behavior.
server.tool({
  name: 'process_data',
  description: 'Process data with progress logging',
  schema: z.object({
    items: z.array(z.string())
  })
}, async ({ items }, ctx) => {
  // Log the start of processing
  await ctx.log('info', 'Starting data processing');
  
  // Debug-level logging for detailed information
  await ctx.log('debug', `Processing ${items.length} items`, 'my-tool');
  
  for (const item of items) {
    // Log warnings when needed
    if (!item.trim()) {
      await ctx.log('warning', 'Empty item found, skipping');
      continue;
    }
    
    try {
      await processItem(item);
    } catch (err) {
      // Log errors without throwing
      await ctx.log('error', `Failed to process item: ${err.message}`);
    }
  }
  
  await ctx.log('info', 'Processing completed');
  return text('All items processed');
})

Log Levels

The ctx.log() function supports eight log levels, from least to most severe:
LevelUse Case
debugDetailed debugging information, verbose output
infoGeneral informational messages about progress
noticeNormal but significant events
warningWarning messages for recoverable issues
errorError messages for failures that don’t stop execution
criticalCritical conditions requiring immediate attention
alertAction must be taken immediately
emergencySystem is unusable

Parameters

ctx.log(level, message, logger?)
  • level (required): One of the eight log levels listed above
  • message (required): The log message content as a string
  • logger (optional): Logger name for categorization (defaults to 'tool')