Skip to content

McpServerPrimitiveCollection ArgumentNullException #624

@kevklam

Description

@kevklam

Describe the bug
[ArgumentNullException]: Value cannot be null.
Parameter name: comparer
at System.Collections.Concurrent.ConcurrentDictionary2..ctor(Int32 concurrencyLevel, Int32 capacity, Boolean growLockArray, IEqualityComparer1 comparer)
at System.Collections.Concurrent.ConcurrentDictionary2..ctor(IEqualityComparer1 comparer)
at ModelContextProtocol.Server.McpServerPrimitiveCollection1..ctor(IEqualityComparer1 keyComparer)
at ModelContextProtocol.McpServerOptionsSetup.Configure(McpServerOptions options)

This is caused by introduction of default-null IEqualityComparer in McpServerPrimitiveCollection constructor, apparently null is not actually accepted by ConcurrentDictionary constructor despite it being a nullable value.

To Reproduce
Steps to reproduce the behavior:

  1. Setup an MCP server with no tools, then McpServerOptionsSetup.Configure() will do this:
    McpServerPrimitiveCollection toolCollection = options.Capabilities?.Tools?.ToolCollection ?? [];

the case where ToolCollection is null results in the above call stack

Expected behavior
Server runs with no tools

Logs
If applicable, add logs to help explain your problem.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions