spring-projects/spring-ai · info

void warn(String message)

Error message

void warn(String message)

What it means

This is not an error but the interface method declaration warn(String) on McpSyncRequestContext: the imperative context API's method to send a WARN-level logging notification to the connected MCP client, returning void. It surfaces in listings as an API surface member, not as a thrown error.

Solutions

  1. Call ctx.warn("...") directly in sync tool code — no subscription needed
  2. In reactive tool code use the async context variant which returns Mono<Void>

Example fix

// before
logger.warn("disk nearly full"); // only server-side logs
// after
ctx.warn("disk nearly full"); // notifies the MCP client too
Defensive patterns

Strategy: try-catch

Try / catch

try {
  ctx.warn("disk nearly full");
} catch (RuntimeException e) {
  logger.warn("Failed to send warn log notification", e);
}

Prevention

When it happens

Trigger: Invoked when a sync @McpTool method calls ctx.warn("message") to forward a warning log to the MCP client via notifications/message.

Common situations: Sync tool implementations reporting warnings (e.g. degraded inputs, fallback behavior) so the LLM host can surface them in its log stream.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/260b896cc1f37140. Report an issue: GitHub.

Appendix: source

Thrown at mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/context/McpSyncRequestContext.java:93

	void progress(Consumer<ProgressSpec> progressSpec);

	void progress(ProgressNotification progressNotification);

	// --------------------------------------
	// Ping
	// --------------------------------------
	void ping();

	// --------------------------------------
	// Logging
	// --------------------------------------
	void log(Consumer<LoggingSpec> logSpec);

	void debug(String message);

	void info(String message);

	void warn(String message);

	void error(String message);

}

View on GitHub (pinned to 98a7beda4f)