Skip to content

Commit 3a98ad6

Browse files
authored
Fix JavaSDK sampling snippets (modelcontextprotocol#199)
Signed-off-by: Christian Tzolov <[email protected]>
1 parent 6e1bbc4 commit 3a98ad6

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

sdk/java/mcp-server.mdx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,11 @@ var calculatorTool = new McpServerFeatures.AsyncToolSpecification(
490490

491491
// Create a sampling request
492492
McpSchema.CreateMessageRequest request = McpSchema.CreateMessageRequest.builder()
493-
.content(McpSchema.Content.builder()
494-
.type("text")
495-
.text("Calculate: " + arguments.get("expression"))
496-
.build())
493+
.content(new McpSchema.TextContent("Calculate: " + arguments.get("expression")))
497494
.modelPreferences(McpSchema.ModelPreferences.builder()
498495
.hints(List.of(
499-
McpSchema.ModelHint.builder().name("claude-3-sonnet").build(),
500-
McpSchema.ModelHint.builder().name("claude").build()
496+
McpSchema.ModelHint.of("claude-3-sonnet"),
497+
McpSchema.ModelHint.of("claude")
501498
))
502499
.intelligencePriority(0.8) // Prioritize intelligence
503500
.speedPriority(0.5) // Moderate speed importance
@@ -524,26 +521,9 @@ server.addTool(calculatorTool)
524521
</Tabs>
525522

526523
The `CreateMessageRequest` object allows you to specify: `Content` - the input text or image for the model,
527-
`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
524+
`Model Preferences` - hints and priorities for model selection, `System Prompt` - instructions for the model's behavior and
525+
`Max Tokens` - maximum length of the generated response.
528526

529-
```java
530-
McpSchema.CreateMessageRequest request = McpSchema.CreateMessageRequest.builder()
531-
.content(McpSchema.Content.builder()
532-
.type("text")
533-
.text("What is the capital of France?")
534-
.build())
535-
.modelPreferences(McpSchema.ModelPreferences.builder()
536-
.hints(List.of(
537-
McpSchema.ModelHint.builder().name("claude-3-sonnet").build(),
538-
McpSchema.ModelHint.builder().name("claude").build()
539-
))
540-
.intelligencePriority(0.8)
541-
.speedPriority(0.5)
542-
.build())
543-
.systemPrompt("You are a helpful assistant.")
544-
.maxTokens(100)
545-
.build();
546-
```
547527

548528
## Error Handling
549529

0 commit comments

Comments
 (0)