Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context logging function types are not spec compliant #397

Open
alejandro5042 opened this issue Mar 31, 2025 · 4 comments
Open

Context logging function types are not spec compliant #397

alejandro5042 opened this issue Mar 31, 2025 · 4 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@alejandro5042
Copy link

Describe the bug

According to the MCP spec, the data that may be logged can be of any type.

    /**
     * The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
     */
    data: unknown;

MCP Schema

You can even see an example here.

However, ctx.info and friends have message typed as str:

async def info(self, message: str, **extra: Any) -> None:

Even so, the underlying ServerSession.send_log_message does indicate that data is Any type:

    async def send_log_message(
        self, level: types.LoggingLevel, data: Any, logger: str | None = None
    ) -> None:

And so does LoggingMessageNotificationParams:

    data: Any
    """
    The data to be logged, such as a string message or an object. Any JSON serializable
    type is allowed here.
    """

Also, it is unclear what the extra parameters should be for.

To Reproduce
Just look at the source file:

https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/server/fastmcp/server.py#L703

Expected behavior
This library should follow the spec and allow any JSON serializable type to be logged.

For example, this should work without giving a type error:

ctx.info({"test": "Hello World!"})

MCP servers can use logging to send rich notifications back to the client.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context

mcp 1.4.1

@dsp-ant
Copy link
Member

dsp-ant commented Mar 31, 2025

Do you mind taking a stab at it and sending a PR

@dsp-ant dsp-ant added good first issue Good for newcomers help wanted Extra attention is needed labels Mar 31, 2025
@AshwanthramKL
Copy link

AshwanthramKL commented Mar 31, 2025

Hey @dsp-ant,
can I contribute to this issue?

Plan on contributing to mcp in the future as well.
This good first issue will help me start capture a good understanding of the repo

@alejandro5042
Copy link
Author

@AshwanthramKL Just signed on to do it but saw your PR. Awesome - thank you for contributing! 👍

@Rakib-hosen
Copy link

Rakib-hosen commented Apr 1, 2025

I have added a pr to solve this.
#400
@dsp-ant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants