0Pricing
MCP Academy · Lesson

Structured Logging to the Client

Emit leveled log messages over the protocol.

Structured Logging to the Client is a free MCP Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MCP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Logs the Client Can See

Printing to your terminal only helps you. MCP lets the server send log messages over the protocol so the host app can show them too.

The message Notification

Logs travel as a notifications/message notification. It carries a level, optional logger name, and the data you want recorded.

{"method": "notifications/message",
 "params": {"level": "info", "data": "Indexing started"}}

Use the Context

From inside a tool you reach logging through the Context object, the same handle you used for progress. No extra setup is needed.

from mcp.server.fastmcp import Context

ctx.info for Updates

The most common helper is ctx.info. Use it for normal, expected status notes that help a user follow what the tool is doing.

await ctx.info("Loaded 120 records from disk")

ctx.debug for Detail

Reach for ctx.debug when you want fine-grained traces, like a parsed value or a chosen branch, that are noisy in everyday use.

await ctx.debug(f"chosen strategy = {strategy}")

ctx.warning for Surprises

Use ctx.warning when something is off but recoverable, like a missing optional field that you filled with a default value.

await ctx.warning("timeout missing, using 30s default")

ctx.error for Failures

Call ctx.error for genuine problems. It tells the client a step failed, separate from raising an exception that ends the call.

await ctx.error("upstream API returned 503")

Standard Severity Levels

MCP follows the familiar syslog scale: debug, info, notice, warning, error, critical, and higher. Clients can sort and color by level.

Name Your Logger

Many helpers accept a logger name so messages can be grouped by component, much like Python's standard logging module does.

await ctx.info("cache miss", logger="db")

Never Log Secrets

Log messages leave your process and reach the client, so treat them as visible. Never write secrets like tokens or passwords into a log.

Logs Are Notifications

Like progress, each log is a notification, so it never blocks your tool or expects a reply. You can log freely as the work unfolds.

await ctx.info("step 1 done")
await ctx.info("step 2 done")

Quick Check

Pick the right helper for routine status updates.

Recap: Logging

You can now emit leveled logs with ctx.info, debug, warning, and error, name your loggers, and keep secrets out. Great progress!

Frequently asked questions

Is the “Structured Logging to the Client” lesson free?

Yes — the full text of “Structured Logging to the Client” is free to read here on the web, and the MCP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MCP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Structured Logging to the Client”?

Emit leveled log messages over the protocol. You practise MCP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start MCP Academy?

No prior experience is required. MCP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Structured Logging to the Client” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this MCP Academy lesson?

Yes. Every MCP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Send Progress for Long Tasks
  2. Handle Cancellation Requests
  3. Structured Logging to the Client
  4. Set Log Levels at Runtime
← Back to MCP Academy