{"record":{"id":"8b2b9e58186cdd7a","repo":"spring-projects/spring-ai","slug":"no-sampling-methods-found-8b2b9e","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/SyncMcpSamplingProvider.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, CreateMessageResult> methodCallback = SyncMcpSamplingMethodCallback\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 SyncSamplingSpecification(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/SyncMcpSamplingProvider.java#L94-L130","documentation":"SyncMcpSamplingProvider.getSamplingSpecifications logs 'No sampling methods found' when annotation scanning of the configured objects produces zero sampling handlers. The provider returns an empty list so the server registers no sampling capability; the warning signals a likely wiring or annotation mistake.","triggerScenarios":"Objects passed to SyncMcpSamplingProvider contain no public @McpSampling methods, methods are non-public or have unsupported signatures, or the objects list is empty — empty samplingHandlers triggers the warn at SyncMcpSamplingProvider.java:112.","commonSituations":"Sampling handler defined but never handed to the provider; annotation removed or renamed during an upgrade; handler method private; async-style handler supplied to the sync provider.","solutions":["Ensure a public @McpSampling-annotated method exists in the objects registered with SyncMcpSamplingProvider.","Verify the constructor receives the correct handler instances (non-empty list).","Confirm visibility and the synchronous signature expected by the scanner.","Remove the sampling provider if sampling is intentionally unsupported."],"exampleFix":"// before\nnew SyncMcpSamplingProvider(List.of());\n// after\nnew SyncMcpSamplingProvider(List.of(new MySampler())); // with @McpSampling String handle(McpSamplingRequest r) {...}","handlingStrategy":"validation","validationCode":"// Validate the sync sampling object before wiring:\nboolean hasHandler = Arrays.stream(samplingObject.getClass().getDeclaredMethods())\n    .anyMatch(m -> m.isAnnotationPresent(McpSampling.class) && Modifier.isPublic(m.getModifiers()));\nif (!hasHandler) throw new IllegalStateException(\"Missing public @McpSampling method in \" + samplingObject);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match provider type to handler style: sync provider for blocking methods, async provider for futures.","Keep sampling handler methods public with signatures the scanner supports.","Register the handler instance, not just declare it as a bean.","Assert non-empty sampling specs in a startup/integration test."],"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"}