Skip to content

Describe where logging info should be observed #171

Closed
@sheffler

Description

@sheffler

I am examining the Context .info(), .debug() and report_progress() methods. I would like a simple example of how to use them and where I should look for output.

I have written the following tiny example. The Error output from the Inspector is shown ad the end of this message. Where should I be able to find the messages or progress? An example of the correct way to use these facilities would be appreciated.

Could there be an error where the send_log_message() method is not awaited?

from mcp.server.fastmcp import FastMCP, Context
import time

mcp = FastMCP("Tom2 Server 2024-01-23", debug=True, log_level="DEBUG")

@mcp.tool()
async def my_tool(x: float, y:float, ctx:Context) -> str:
    """Perform a long running calculation"""

    ctx.info(f"Processing Message 1")
    await ctx.report_progress(1, 2)
    time.sleep(2)
    ctx.debug(f"Processing Message 2")
    await ctx.report_progress(2, 2)
    time.sleep(2)
    return x*y

Error Output from the inspector.

[01/24/25 15:32:26] DEBUG Using selector: selector_events.py:59 KqueueSelector
DEBUG Received message: server.py:428 root=InitializedNotification(method=' notifications/initialized', params=None, jsonrpc='2.0')
[01/24/25 15:32:31] DEBUG Received message: server.py:428 <mcp.shared.session.RequestResponder object at 0x106d86080>
INFO Processing request of type server.py:432 ListToolsRequest
DEBUG Dispatching request of type server.py:437 ListToolsRequest
DEBUG Response sent server.py:475
[01/24/25 15:32:35] DEBUG Received message: server.py:428 <mcp.shared.session.RequestResponder object at 0x106d87f40>
INFO Processing request of type server.py:432 CallToolRequest
DEBUG Dispatching request of type server.py:437 CallToolRequest
[01/24/25 15:32:39] DEBUG Response sent server.py:475
INFO Warning: RuntimeWarning: coroutine server.py:495 'ServerSession.send_log_message' was never awaited

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions