spring-projects / spring-projects/spring-ai

AsyncMcpToolCallbackProvider block()/blockFirst()/blockLast() are blocking, which is not supported

Open
#4,898 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

spring-ai version: 1.1.2
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-4
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:87) ~[reactor-core-3.7.11.jar:3.7.11]
at reactor.core.publisher.Mono.block(Mono.java:1779) ~[reactor-core-3.7.11.jar:3.7.11]
at org.springframework.ai.mcp.AsyncMcpToolCallbackProvider.getToolCallbacks(AsyncMcpToolCallbackProvider.java:155) ~[spring-ai-mcp-1.1.0.jar:1.1.0]
at org.springframework.ai.chat.client.DefaultChatClientUtils.toChatClientRequest(DefaultChatClientUtils.java:134) ~[spring-ai-client-chat-1.1.0.jar:1.1.0]
at org.springframework.ai.chat.client.DefaultChatClient$DefaultChatClientRequestSpec.stream(DefaultChatClient.java:1022) ~[spring-ai-client-chat-1.1.0.jar:1.1.0]

spring-ai version: 1.1.0-M3
Everything is ok.

    <dependency>
      <groupId>org.springframework.ai</groupId>
      <artifactId>spring-ai-starter-model-azure-openai</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.ai</groupId>
      <artifactId>spring-ai-starter-mcp-client-webflux</artifactId>
    </dependency>
spring:
  ai: 
    mcp:
      client:
      type: ASYNC
      streamable-http:
        connections:
          toolbox:
            url: http://127.0.0.1:5000
  @Bean
  ChatClient chatClient(
      ChatClient.Builder chatClientBuilder,
      ToolCallbackProvider[] toolCallbackProviders,
      ChatMemory chatMemory,
      ChatProperties chatProperties
  ) {
    return chatClientBuilder
        .defaultToolCallbacks(toolCallbackProviders)
        .defaultSystem(chatProperties.getSystemPrompt())
        .defaultAdvisors(
            MessageChatMemoryAdvisor.builder(chatMemory).build(),
            new SystemPromptFirstSortingAdvisor()
        )
        .build();
  }
  public Flux<ChatResponse> chat(ChatRequest request, String conversationId) {
    return chatClient.prompt()
        .user(request.prompt())
        .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, conversationId))
        .stream()
        .chatResponse();
  }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at AsyncMcpToolCallbackProvider.getToolCallbacks(), especially line 155, and trace how DefaultChatClientUtils.toChatClientRequest() reaches it from the streaming ChatClient path. Reproduce the issue with the provided WebFlux async MCP configuration and verify the completed change no longer calls blocking operations on reactor-http-nio threads.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.