Fix JavaSDK sampling snippets (#199)

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
Christian Tzolov 2025-03-21 22:32:09 +01:00 • committed by GitHub
commit 3a98ad69cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -490,14 +490,11 @@ var calculatorTool = new McpServerFeatures.AsyncToolSpecification(
// Create a sampling request // Create a sampling request
McpSchema.CreateMessageRequest request = McpSchema.CreateMessageRequest.builder() McpSchema.CreateMessageRequest request = McpSchema.CreateMessageRequest.builder()
.content(McpSchema.Content.builder() .content(new McpSchema.TextContent("Calculate: " + arguments.get("expression")))
.type("text")
.text("Calculate: " + arguments.get("expression"))
.build())
.modelPreferences(McpSchema.ModelPreferences.builder() .modelPreferences(McpSchema.ModelPreferences.builder()
.hints(List.of( .hints(List.of(
McpSchema.ModelHint.builder().name("claude-3-sonnet").build(), McpSchema.ModelHint.of("claude-3-sonnet"),
McpSchema.ModelHint.builder().name("claude").build() McpSchema.ModelHint.of("claude")
)) ))
.intelligencePriority(0.8) // Prioritize intelligence .intelligencePriority(0.8) // Prioritize intelligence
.speedPriority(0.5) // Moderate speed importance .speedPriority(0.5) // Moderate speed importance
@ -524,26 +521,9 @@ server.addTool(calculatorTool)
</Tabs> </Tabs>
The `CreateMessageRequest` object allows you to specify: `Content` - the input text or image for the model, The `CreateMessageRequest` object allows you to specify: `Content` - the input text or image for the model,
`Model Preferences` - hints and priorities for model selection, `System Prompt` - instructions for the model's behavior and `Max Tokens` - maximum length of the generated response `Model Preferences` - hints and priorities for model selection, `System Prompt` - instructions for the model's behavior and
`Max Tokens` - maximum length of the generated response.
```java
McpSchema.CreateMessageRequest request = McpSchema.CreateMessageRequest.builder()
.content(McpSchema.Content.builder()
.type("text")
.text("What is the capital of France?")
.build())
.modelPreferences(McpSchema.ModelPreferences.builder()
.hints(List.of(
McpSchema.ModelHint.builder().name("claude-3-sonnet").build(),
McpSchema.ModelHint.builder().name("claude").build()
))
.intelligencePriority(0.8)
.speedPriority(0.5)
.build())
.systemPrompt("You are a helpful assistant.")
.maxTokens(100)
.build();
```
## Error Handling ## Error Handling