Skip to main content
mcp-agent ships with a structured logger that captures context-rich events from apps, workflows, agents, and Temporal workers. Logs are automatically correlated with traces and forwarded to MCP clients using the Model Context Protocol logging utility.

Logger entry points

  • app.logger – application-scoped logger, ideal for tools and startup messages.
  • context.logger – request-specific logger with access to the active session, token counter, and upstream MCP connection.
  • agent.logger – automatically bound when you call async with agent:; perfect for per-agent instrumentation.
Each call emits an Event that can be routed to multiple transports. Span IDs and workflow IDs are injected automatically when tracing is enabled.

Configure transports and levels

The logger section in mcp_agent.config.yaml controls transports, batching, and formatting:

Structured events

Logs accept a message plus an optional data payload. The payload is serialised as JSON and preserved end-to-end:
Sample JSON from the file transport:
Because trace IDs are present, you can pivot between logs and OpenTelemetry spans in Jaeger/Tempo with a single click.

MCP logging to upstream clients

When your app runs as an MCP server, the logger automatically forwards events to connected clients using the MCP logging channel. MCP-compatible tools (Claude Desktop, Cursor, etc.) will display your messages in their native consoles.
For long-running Temporal workflows, the logger falls back to a special activity (mcp_forward_log) so events appear in the client even while the workflow is suspended.

Tips for production setups

  • Pair logging with tracing (otel.enabled: true) so every event carries span metadata.
  • Use progress_display: true when running CLI tools to get live status bars for long flows.
  • Tune batch_size/flush_interval for high-volume agents; the defaults (100 events / 2 seconds) work well for most workloads.
  • HTTP transports can carry filters—attach an EventFilter if you only want to forward warnings and errors.

Reference implementations