modelcontextprotocol / modelcontextprotocol/java-sdk
Initialization errors in McpAsyncClient not emitted immediately
Personne n'a encore pris cette issue.
- Langage dominant
- Java
- Étoiles
- 3.7k
- Forks
- 1.1k
- Merge moyen
- 1 j 15 h
- PR mergées (30 j)
- 9
Description
Bug Description
When subscribing to exceptions from McpAsyncClient.initialize() using onErrorResumein order to catch initialization failures immediately, nothing is emitted. I suspect this is caused by McpAsyncClient not propagating errors downstream.
I’m new to Reactor and don’t know how to fix this. Any simple tips or pointers, like which class or method handles error propagation, would be really helpful so I can send a PR.
Also, I believe this issue may be related to:
- https://github.com/modelcontextprotocol/java-sdk/issues/275
- https://github.com/modelcontextprotocol/java-sdk/issues/377
- https://github.com/modelcontextprotocol/java-sdk/issues/151
Environment
JDK: zulu-21
gradle: 8.10.2
IntelliJ IDEA 2025.1.1.1 (Community Edition) (K2 mode)
io.modelcontextprotocol java-sdk commit: https://github.com/modelcontextprotocol/java-sdk/commit/8a2f97f1b1995880c492159dd1b4c50266d0b579
Steps to reproduce
- Clone and
installthe repo, checkout https://github.com/modelcontextprotocol/java-sdk/commit/8a2f97f1b1995880c492159dd1b4c50266d0b579 - Run the script provided below
- Observe that no immediate exception is thrown
Expected behavior
- When I initialize McpClient with an incorrect transport
- And internally, the
reactor.core.publisher.Operatorslogger reports:
java.lang.RuntimeException: Failed to start process with command: [a, a] - Then I expect the initialization to fail immediately - not after my configured timeout
Minimal Complete Reproducible example
Main.kt:
import io.modelcontextprotocol.client.transport.StdioClientTransport
import io.modelcontextprotocol.client.transport.ServerParameters
import kotlinx.coroutines.reactive.awaitSingle
import mu.KotlinLogging
import reactor.core.publisher.Mono
import java.time.Duration
private val logger = KotlinLogging.logger {}
suspend fun main() {
val params = ServerParameters.builder("a").args("b").build()
val transport = StdioClientTransport(params)
val client = io.modelcontextprotocol.client.McpClient
.async(transport)
.requestTimeout(Duration.ofSeconds(6))
.initializationTimeout(Duration.ofSeconds(5))
.build()
client.initialize()
.doOnError { t -> logger.error { t }; return@doOnError }
.onErrorResume { return@onErrorResume Mono.error(it) }
.awaitSingle()
}
build.gradle.kts:
plugins {
kotlin("jvm") version "2.1.20"
}
group = "com.anything.mcp"
version = "1.0-SNAPSHOT"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation("io.modelcontextprotocol.sdk:mcp:0.11.0-SNAPSHOT")
implementation("io.modelcontextprotocol.sdk:mcp-spring-webflux:0.11.0-SNAPSHOT")
implementation("io.github.microutils:kotlin-logging:3.0.5")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.8.0")
}
kotlin {
jvmToolchain(21)
}
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par suivre McpAsyncClient.initialize() et le chemin de démarrage de StdioClientTransport utilisé par Main.kt, en vérifiant comment l’échec du démarrage du processus atteint le publisher Reactor. Utilisez la reproduction fournie et la sortie du logger de Operators pour confirmer que l’échec est émis immédiatement, et non seulement après initializationTimeout ; c’est terminé lorsque l’erreur atteint doOnError/onErrorResume sans attendre le délai d’expiration.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java, kotlin
- Domaine
- api, backend
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 48/100