(ctx context.Context, req *mcp.CallToolRequest, input samplingInput)
| 304 | } |
| 305 | |
| 306 | func testSamplingHandler(ctx context.Context, req *mcp.CallToolRequest, input samplingInput) (*mcp.CallToolResult, any, error) { |
| 307 | // Request LLM completion from the client |
| 308 | result, err := req.Session.CreateMessage(ctx, &mcp.CreateMessageParams{ |
| 309 | Messages: []*mcp.SamplingMessage{ |
| 310 | { |
| 311 | Role: "user", |
| 312 | Content: &mcp.TextContent{ |
| 313 | Text: input.Prompt, |
| 314 | }, |
| 315 | }, |
| 316 | }, |
| 317 | MaxTokens: 100, |
| 318 | }) |
| 319 | if err != nil { |
| 320 | return nil, nil, fmt.Errorf("sampling failed: %w", err) |
| 321 | } |
| 322 | |
| 323 | // Extract the text response from the result |
| 324 | var responseText string |
| 325 | if tc, ok := result.Content.(*mcp.TextContent); ok { |
| 326 | responseText = tc.Text |
| 327 | } else { |
| 328 | responseText = "(non-text response)" |
| 329 | } |
| 330 | |
| 331 | return &mcp.CallToolResult{ |
| 332 | Content: []mcp.Content{ |
| 333 | &mcp.TextContent{Text: fmt.Sprintf("LLM response: %s", responseText)}, |
| 334 | }, |
| 335 | }, nil, nil |
| 336 | } |
| 337 | |
| 338 | type elicitationInput struct { |
| 339 | Message string `json:"message" jsonschema:"The message to show the user"` |
nothing calls this directly
no test coverage detected
searching dependent graphs…