Skip to content

Commit 780f5dd

Browse files
committed
feat(server): add bulk registration methods for async completions
Add convenience methods to AsyncSpecification for registering multiple completions at once: - completions(List) for bulk registration from collections - completions(AsyncCompletionSpecification...) for inline varargs registration Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
1 parent f9d154e commit 780f5dd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

mcp/src/main/java/io/modelcontextprotocol/server/McpServer.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,36 @@ public AsyncSpecification prompts(McpServerFeatures.AsyncPromptSpecification...
517517
return this;
518518
}
519519

520+
/**
521+
* Registers multiple completions with their handlers using a List. This method is
522+
* useful when completions need to be added in bulk from a collection.
523+
* @param completions List of completion specifications. Must not be null.
524+
* @return This builder instance for method chaining
525+
* @throws IllegalArgumentException if completions is null
526+
*/
527+
public AsyncSpecification completions(List<McpServerFeatures.AsyncCompletionSpecification> completions) {
528+
Assert.notNull(completions, "Completions list must not be null");
529+
for (McpServerFeatures.AsyncCompletionSpecification completion : completions) {
530+
this.completions.put(completion.referenceKey(), completion);
531+
}
532+
return this;
533+
}
534+
535+
/**
536+
* Registers multiple completions with their handlers using varargs. This method
537+
* is useful when completions are defined inline and added directly.
538+
* @param completions Array of completion specifications. Must not be null.
539+
* @return This builder instance for method chaining
540+
* @throws IllegalArgumentException if completions is null
541+
*/
542+
public AsyncSpecification completions(McpServerFeatures.AsyncCompletionSpecification... completions) {
543+
Assert.notNull(completions, "Completions list must not be null");
544+
for (McpServerFeatures.AsyncCompletionSpecification completion : completions) {
545+
this.completions.put(completion.referenceKey(), completion);
546+
}
547+
return this;
548+
}
549+
520550
/**
521551
* Registers a consumer that will be notified when the list of roots changes. This
522552
* is useful for updating resource availability dynamically, such as when new

0 commit comments

Comments
 (0)