Skip to content

TestServerWithHosting should not output logging to stdio #37

Open
@eiriktsarpalis

Description

@eiriktsarpalis

Originally posted by @artl93 in PederHP/mcpdotnet#66.

Repro

Start TestServerWithHosting (which demoonstrates use of stdio)

Result

[13:15:44 INF] Starting server...
[13:15:44 DBG] Hosting starting
[13:15:44 INF] Application started. Press Ctrl+C to shut down.
[13:15:44 INF] Hosting environment: Production
[13:15:44 INF] Content root path: /Users/artleonard/src/mcpdotnet
[13:15:44 DBG] Hosting started
[13:15:44 INF] Transport entering read messages loop for Server (stdio) (TestServerWithHosting)
[13:15:44 INF] Transport waiting for message for Server (stdio) (TestServerWithHosting)

##Expected
Nothing other than stdin ready to receive initialization input.

##Issue:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.host.createapplicationbuilder?view=net-9.0-pp states that Host.CreateApplicationBuilder will automatically create a Console logger, which will interfere with https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/transports/

The server MAY write UTF-8 strings to its standard error (stderr) for logging purposes. Clients MAY capture, forward, or ignore this logging.
The server MUST NOT write anything to its stdout that is not a valid MCP message.

An alternative might look something like this, but mabe this needs a new host builder?

    var builder = Host.CreateApplicationBuilder(args);

    // Not sure this is really the best pattern
    builder.Logging.ClearProviders();
    builder.Logging.AddDebug();
    builder.Logging.AddEventSourceLogger();

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