Package org.mcpjava.server.completion
Interface CompletionContext
public interface CompletionContext
Provides access to values for other arguments that the user has already completed
Where a prompt or a resource template has multiple arguments, the valid completions for one argument can be affected by the values already selected for another argument.
This interface can be accepted as a parameter to a CompletePrompt or CompleteResourceTemplate-annotated method and used to access values for other arguments.
Example
The city-data resource template needs arguments for the city and country. When completing the city name, the country name should be taken into account if the user has already provided it.
@ResourceTemplate(name = "city-data", uriTemplate = "http://example.org/locationdata/{country}/{city}")
public String getCityData(@ResourceTemplateArg(name = "country") String country,
@ResourceTemplateArg(name = "city") String city) {
return cities.find(country, city);
}
@CompleteResourceTemplate("city-data")
public List<String> completeCity(@CompleteArg(name = "city") String partialCity,
CompletionContext context) {
return context.getArgument("country")
.map(country -> cities.startingWith(country, partialCity))
.orElseGet(() -> cities.startingWith(partialCity));
}
-
Method Summary
Modifier and TypeMethodDescriptiongetArgument(String name) Returns the value assigned to the named argument, if the user has provided it.
-
Method Details
-
getArgument
Returns the value assigned to the named argument, if the user has provided it.- Parameters:
name- the name of the argument- Returns:
- the value of the argument, if provided
-