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

chore: use add all to make code simpler #96

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions mcp/src/main/java/io/modelcontextprotocol/server/McpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

package io.modelcontextprotocol.server;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wildcard imports are discouraged as they can lead to namespace pollution and make it harder to track dependencies.

import java.util.function.BiConsumer;
import java.util.function.BiFunction;

Expand Down Expand Up @@ -315,9 +311,7 @@ public AsyncSpecification tools(List<McpServerFeatures.AsyncToolSpecification> t
*/
public AsyncSpecification tools(McpServerFeatures.AsyncToolSpecification... toolSpecifications) {
Assert.notNull(toolSpecifications, "Tool handlers list must not be null");
for (McpServerFeatures.AsyncToolSpecification tool : toolSpecifications) {
this.tools.add(tool);
}
Collections.addAll(this.tools, toolSpecifications);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this.tools.addAll(List.of(toolSpecifications)) would do the job without needing additional/external libraries?

return this;
}

Expand Down Expand Up @@ -413,9 +407,7 @@ public AsyncSpecification resourceTemplates(List<ResourceTemplate> resourceTempl
*/
public AsyncSpecification resourceTemplates(ResourceTemplate... resourceTemplates) {
Assert.notNull(resourceTemplates, "Resource templates must not be null");
for (ResourceTemplate resourceTemplate : resourceTemplates) {
this.resourceTemplates.add(resourceTemplate);
}
Collections.addAll(this.resourceTemplates, resourceTemplates);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same like above

return this;
}

Expand Down Expand Up @@ -726,9 +718,7 @@ public SyncSpecification tools(List<McpServerFeatures.SyncToolSpecification> too
*/
public SyncSpecification tools(McpServerFeatures.SyncToolSpecification... toolSpecifications) {
Assert.notNull(toolSpecifications, "Tool handlers list must not be null");
for (McpServerFeatures.SyncToolSpecification tool : toolSpecifications) {
this.tools.add(tool);
}
Collections.addAll(this.tools, toolSpecifications);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

return this;
}

Expand Down Expand Up @@ -824,9 +814,7 @@ public SyncSpecification resourceTemplates(List<ResourceTemplate> resourceTempla
*/
public SyncSpecification resourceTemplates(ResourceTemplate... resourceTemplates) {
Assert.notNull(resourceTemplates, "Resource templates must not be null");
for (ResourceTemplate resourceTemplate : resourceTemplates) {
this.resourceTemplates.add(resourceTemplate);
}
Collections.addAll(this.resourceTemplates, resourceTemplates);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

return this;
}

Expand Down