{"record":{"id":"ee388c5db6717734","repo":"spring-projects/spring-ai","slug":"no-sampling-methods-found","errorCode":null,"errorMessage":"No sampling methods found","messagePattern":"No sampling methods found","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/provider/sampling/AsyncMcpSamplingProvider.java","lineNumber":112,"sourceCode":"\t\t\t\t.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))\n\t\t\t\t.map(mcpSamplingMethod -> {\n\t\t\t\t\tvar samplingAnnotation = mcpSamplingMethod.getAnnotation(McpSampling.class);\n\n\t\t\t\t\tFunction<CreateMessageRequest, Mono<CreateMessageResult>> methodCallback = AsyncMcpSamplingMethodCallback\n\t\t\t\t\t\t.builder()\n\t\t\t\t\t\t.method(mcpSamplingMethod)\n\t\t\t\t\t\t.bean(samplingObject)\n\t\t\t\t\t\t.sampling(samplingAnnotation)\n\t\t\t\t\t\t.build();\n\n\t\t\t\t\treturn new AsyncSamplingSpecification(samplingAnnotation.clients(), methodCallback);\n\t\t\t\t})\n\t\t\t\t.toList())\n\t\t\t.flatMap(List::stream)\n\t\t\t.toList();\n\n\t\tif (samplingHandlers.isEmpty()) {\n\t\t\tlogger.warn(\"No sampling methods found\");\n\t\t}\n\t\tif (samplingHandlers.size() > 1) {\n\t\t\tif (logger.isWarnEnabled()) {\n\t\t\t\tlogger.warn(\"Multiple sampling methods found: \" + samplingHandlers.size());\n\t\t\t}\n\t\t}\n\n\t\treturn samplingHandlers;\n\t}\n\n\t/**\n\t * Returns the methods of the given bean class.\n\t * @param bean the bean instance\n\t * @return the methods of the bean class\n\t */\n\tprotected Method[] doGetClassMethods(Object bean) {\n\t\treturn bean.getClass().getDeclaredMethods();\n\t}","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/provider/sampling/AsyncMcpSamplingProvider.java#L94-L130","documentation":"AsyncMcpSamplingProvider.getSamplingSpecifictions logs 'No sampling methods found' when scanning the configured objects for @McpSampling-annotated methods yields an empty handler list. The provider returns nothing, so the MCP server registers no sampling handlers. This warns that sampling support is effectively disabled despite the provider being wired.","triggerScenarios":"Constructing AsyncMcpSamplingProvider with objects lacking any public @McpSampling method, annotated methods filtered out (visibility/signature mismatch), or an empty objects list — empty samplingHandlers triggers the warn at AsyncMcpSamplingProvider.java:112.","commonSituations":"Sampling handler class never registered with the provider; @McpSampling annotation missing after refactor; method made private; wrong provider type (async provider given sync-style handlers).","solutions":["Add a public method annotated with @McpSampling in the object(s) passed to AsyncMcpSamplingProvider.","Verify the sampling handler instances are actually supplied to the provider constructor/builder.","Check method visibility and parameter/return types match what the scanner supports for async sampling.","If sampling is not needed, remove the sampling provider instead of registering an empty one."],"exampleFix":"// before\nclass Sampler { public String complete(String prompt) { ... } } // no @McpSampling\n// after\nclass Sampler { @McpSampling public CompletableFuture<String> complete(McpSamplingRequest req) { ... } }","handlingStrategy":"validation","validationCode":"// Confirm a sampling handler exists before wiring the async provider:\nlong sampling = Arrays.stream(samplingObject.getClass().getDeclaredMethods())\n    .filter(m -> m.isAnnotationPresent(McpSampling.class) && Modifier.isPublic(m.getModifiers()))\n    .count();\nif (sampling == 0) throw new IllegalStateException(samplingObject + \" has no public @McpSampling methods\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the async provider only with async-compatible (CompletableFuture-returning) @McpSampling methods.","Register the sampling handler bean explicitly with the provider.","Add a startup assertion that sampling specifications are non-empty when sampling is required.","Re-check annotations after upgrading spring-ai-mcp versions."],"tags":["mcp","annotation-scanning","sampling","empty-specifications"],"backgroundTag":"empty-result-set","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}