@@ -158,3 +158,72 @@ public async Task EmptyPromptCollection_CanGetPromptAfterAddingDynamically()
158158 Assert . Equal ( "dynamic prompt content" , ( ( TextContent ) result . Messages [ 0 ] . Content [ 0 ] ) . Text ) ;
159159 }
160160}
161+
162+ /// <summary>
163+ /// Tests to verify that handlers are NOT synthesized when collections are null.
164+ /// This ensures we don't unnecessarily create capabilities when nothing is configured.
165+ /// </summary>
166+ public class NullCollectionTests : ClientServerTestBase
167+ {
168+ public NullCollectionTests ( ITestOutputHelper testOutputHelper )
169+ : base ( testOutputHelper )
170+ {
171+ }
172+
173+ protected override void ConfigureServices ( ServiceCollection services , IMcpServerBuilder mcpServerBuilder )
174+ {
175+ mcpServerBuilder . Services . Configure < McpServerOptions > ( options =>
176+ {
177+ options . ServerInfo = new Implementation
178+ {
179+ Name = "null-collection-test" ,
180+ Version = "1.0.0"
181+ } ;
182+
183+ // Explicitly leave collections as null - no handlers should be synthesized
184+ options . ResourceCollection = null ;
185+ options . ToolCollection = null ;
186+ options . PromptCollection = null ;
187+ } ) ;
188+ }
189+
190+ [ Fact ]
191+ public void NullCollections_DoNotCreateCapabilities ( )
192+ {
193+ // Verify that when collections are null (and no handlers are provided),
194+ // the specific capability properties remain null
195+ Assert . Null ( Server . ServerCapabilities . Resources ) ;
196+ Assert . Null ( Server . ServerCapabilities . Tools ) ;
197+ Assert . Null ( Server . ServerCapabilities . Prompts ) ;
198+ }
199+
200+ [ Fact ]
201+ public async Task NullResourceCollection_ListReturnsEmpty ( )
202+ {
203+ using var client = await CreateMcpClientForServer ( ) ;
204+
205+ // When no resource capability is configured, list should return empty
206+ var resources = await client . ListResourcesAsync ( ) ;
207+ Assert . Empty ( resources ) ;
208+ }
209+
210+ [ Fact ]
211+ public async Task NullToolCollection_ListReturnsEmpty ( )
212+ {
213+ using var client = await CreateMcpClientForServer ( ) ;
214+
215+ // When no tool capability is configured, list should return empty
216+ var tools = await client . ListToolsAsync ( ) ;
217+ Assert . Empty ( tools ) ;
218+ }
219+
220+ [ Fact ]
221+ public async Task NullPromptCollection_ListReturnsEmpty ( )
222+ {
223+ using var client = await CreateMcpClientForServer ( ) ;
224+
225+ // When no prompt capability is configured, list should return empty
226+ var prompts = await client . ListPromptsAsync ( ) ;
227+ Assert . Empty ( prompts ) ;
228+ }
229+ }
0 commit comments