MCP structured logging: declare the capability, set a level, receive notifications
Declare logging, send logging/setLevel and handle notifications/message and errors, following the 2025-11-25 logging page.
Prepare the input and environment · Mechanism and data flow · Workflow map
At a glance
This article relies only on the Logging page of the MCP 2025-11-25 specification. It covers how a server sends structured log messages to a client, how the client sets a minimum level, and how it consumes the notifications. A log level describes how severe one message is. It is not a task success status, so a client should not use it in place of the result of a tool call or another request.
Runtime and applicability
- Article type
- Engineering practice
- Verified
- Applies to
- MCP Documented mcp task and conditions
Execution locations and responsibilities
- MCP client and server Define the configuration or request shown here and check its inputs, outputs and failure branches.
When to use
- An MCP client and server that follow the 2025-11-25 specification and have already connected and initialized. This article does not show how to connect, and the source page gives no initialization details.
When not to use
- The source page defines no default log level, no content for a successful
logging/setLevelresponse, no specific message that carries the capability declaration, and no extra rules for messages below the minimum level. This article does not infer them.
Prepare the input and environment
- An MCP client and server that follow the 2025-11-25 specification and have already connected and initialized. This article does not show how to connect, and the source page gives no initialization details.
- A server that actually emits log message notifications. The source page requires a server that emits them to declare the
loggingcapability. - A client that can receive JSON-RPC notifications and tell a request with an
idfrom a notification without one. - A review rule for log content, used to decide which fields must not appear in
data.
Mechanism and data flow
Capability declaration:The source page says a server that emits log message notifications must declare the logging capability. The example is an empty logging object inside capabilities. This layer answers whether the server will send logs at all. The page shows only this capability object. It does not say which message carries it and defines no subfields, so this article adds none. A client can treat the declaration as the precondition for setting a level and receiving notifications.
Levels and setting:The protocol uses the RFC 5424 syslog severities, and the page lists eight: debug, info, notice, warning, error, critical, alert, emergency. A client may send a logging/setLevel request to configure the minimum level. The example request has id 1 and params.level of info. The page states no default level and describes no success response, so a client cannot assume what happens before a level is set.
Notifications and data:The server sends logs with notifications/message notifications. In the example, params.level is error, logger is database, and data is a nested JSON object. The page says a notification carries a severity level, an optional logger name, and arbitrary JSON-serializable data. So logger may be absent, and the server decides the shape of data. The notification has no id, so the client does not reply to it.
Errors and security:The page says servers should return standard JSON-RPC errors for common failures: -32602 (Invalid params) for an invalid log level and -32603 (Internal error) for configuration errors. The security section says log messages must not contain credentials or secrets, personal identifying information, or internal system details that could aid attacks. It also recommends rate limiting, validating all data fields, controlling log access, and monitoring for sensitive content.
Workflow map
| Stage | What happens |
|---|---|
| Capability declaration | Capability declaration:The source page says a server that emits log message notifications must declare the logging capability. |
| Levels and setting | Levels and setting:The protocol uses the RFC 5424 syslog severities, and the page lists eight: debug, info, notice, warning, error, critical, alert, emergency. |
| Notifications and data | Notifications and data:The server sends logs with notifications/message notifications. |
| Errors and security | Errors and security:The page says servers should return standard JSON-RPC errors for common failures: -32602 (Invalid params) for an invalid log level and -32603 (Internal error) for configuration errors. |
Complete the task
Check logging in the actual server capability declaration. Its message location comes from the host initialization contract you have verified; the logging page does not define it. A server sending log notifications must declare that capability. Record a contract issue if it is missing rather than relying on notifications.
Choose a minimum level:Compare the eight syslog levels and decide the lowest severity the client wants to see. The page's example uses help here: debug for function entry and exit points, info for operation progress, warning for deprecated feature usage, error for operation failures, and emergency for an unusable system. Record the choice in client configuration and use only these eight lowercase names, since other values may trigger an invalid-level error.
Send logging/setLevel:The client sends a JSON-RPC request with method set to logging/setLevel, params.level set to the value chosen in the previous step, and an id so the response can be matched. The official example uses info. The page says only that a client may send this request, so it is optional. After sending, wait for the response with the same id before treating the configuration as accepted.
Consume notifications/message:The client should listen for notifications whose method is notifications/message and read params.level, the optional params.logger, and params.data. Do not assume fixed fields in data, since the page calls it arbitrary JSON-serializable data. The error and details keys in the example are only an example. The page lets a client show messages in a UI, filter or search them, display severity visually, and persist them.
Handle error responses:If logging/setLevel returns an error, branch on the code. -32602 signals invalid params, such as a level outside the eight values. -32603 signals a server configuration error. The page says servers should return these, not must, so the client should also be ready for errors in a different form. After an error, keep the original request and the error for diagnosis, and stop assuming the level has changed.
Review content and handle cleanup:Review logs against the security section: no credentials, personal identifying information, or internal details that could aid attacks. The official example has host and port fields. It illustrates the data format only, and whether such fields count as internal system details is the implementer's call under their own rules. Servers should rate limit and keep logger names consistent. The page defines no cleanup procedure, so if a client persists logs, retention and deletion need your own policy.
Worked example
Take the official example as a guide. The server declares logging in its capabilities. The client sends a logging/setLevel request with id 1 and level set to info. Later the server sends one notifications/message with level error, logger database, and data holding error as Connection failed plus details with host and port. The client reads the level, can display it as an error, and can group it by logger name. This log only reports a database connection failure. It says nothing about whether the whole task succeeded, which should come from the result of the matching request. This is the source page's official example, not an observation from this batch.
{
"capabilities": {
"logging": {}
}
}
{
"jsonrpc": "2.0",
"id": 1,
"method": "logging/setLevel",
"params": {
"level": "info"
}
}
{
"jsonrpc": "2.0",
"method": "notifications/message",
"params": {
"level": "error",
"logger": "database",
"data": {
"error": "Connection failed",
"details": {
"host": "localhost",
"port": 5432
}
}
}
}
Check the result and failure paths
- Configuration check: logging is declared, the level is valid and a matching successful response contains no error. Handle its exact structure under the verified host contract. A matching error response is a failure. Whether notifications follow the selected level still requires actual validation; this batch did not execute it.
- Notification check: every notification has
methodnotifications/messageand aparams.level, the client copes whenloggeris missing, anddataparses as JSON without depending on fixed fields. - Failure check: an invalid level is expected to return -32602, and a server configuration failure is expected to return -32603. If a different form comes back, record the actual response instead of rewriting it into these codes.
- Privacy check: sample
dataand confirm it holds no credentials, secrets, personal identifying information, or internal details that could aid attacks, and that rate limiting and access control exist.
Scope and limits
- A log level shows how severe a message is. It is not a task success status and cannot replace the result of a tool call, resource read, or other request.
- The page prescribes no user interface, so implementers choose how to display logs. Displayed or persisted logs still fall under the security section's limits on sensitive information.
No product, client, server, or API was run in this batch, and the request and notification behavior described here was not verified. The JSON comes from the official 2025-11-25 page, and the checks are expected points to verify, not execution results.
Connect the verified host sending and notification-dispatch interfaces. Define a bounded wait and stopping strategy for no response or user cancellation, and handle persisted logs under your own retention rules. These are implementation suggestions; the logging page defines no timeout, cancellation or cleanup interface.
Sources
All links are official pages; verification dates are listed per source, and links point to the version checked.