pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/modelcontextprotocol/python-sdk/pull/2367

78641c0a1f3e0.css" /> fix: allow Any type for logging message parameter by mac-agent · Pull Request #2367 · modelcontextprotocol/python-sdk · GitHub
Skip to content

fix: allow Any type for logging message parameter#2367

Open
mac-agent wants to merge 1 commit intomodelcontextprotocol:mainfrom
mac-agent:fix/logging-data-type
Open

fix: allow Any type for logging message parameter#2367
mac-agent wants to merge 1 commit intomodelcontextprotocol:mainfrom
mac-agent:fix/logging-data-type

Conversation

@mac-agent
Copy link
Copy Markdown

Summary

Change the type annotation of the message parameter in Context.log(), Context.debug(), Context.info(), Context.warning(), and Context.error() from str to Any.

Problem

The MCP spec defines the log data field as:

data: unknown — "Any JSON serializable type is allowed here"

But the Python SDK types the message as str, preventing rich structured logging like:

ctx.info({"event": "progress", "percent": 50})

Solution

  • Change message: str to message: Any in all 5 logging methods
  • Update docstring to document the expanded type
  • Keep parameter name as message for backward compatibility
  • No behavioral changes — existing string calls continue to work identically

Changes

  • src/mcp/server/mcpserver/context.py: Type annotation changes only

Fixes #397

Change the type annotation of the message parameter in Context.log(),
Context.debug(), Context.info(), Context.warning(), and Context.error()
from str to Any.

The MCP spec defines the log data field as:
  data: unknown - "Any JSON serializable type is allowed here"

This allows MCP servers to send rich structured notifications:
  ctx.info({"event": "progress", "percent": 50})

The parameter name is kept as message for backward compatibility.

Fixes modelcontextprotocol#397
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context logging function types are not spec compliant

2 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy