Skip to content

Add support to add reactive hook when initializing MCP server #712

@raducoravu

Description

@raducoravu

I create and initialize a McpSyncClient.

McpSyncClient client = McpClient.sync(transport)
          .requestTimeout(timeout)
          .loggingConsumer(this)
          .capabilities(ClientCapabilities.builder()
              .roots(true)      // Enable filesystem roots support
              .sampling()       // Enable LLM sampling support
              .build())
          .build();
client.initialize();

I get this error logged in the console:

java.lang.RuntimeException: Failed to start process with command: [npx, -y, @modelcontextprotocol/server-brave-search]
	at io.modelcontextprotocol.client.transport.StdioClientTransport.lambda$connect$1(StdioClientTransport.java:124)
	at reactor.core.publisher.MonoRunnable.call(MonoRunnable.java:73)
	at reactor.core.publisher.MonoRunnable.call(MonoRunnable.java:32)
	at reactor.core.publisher.FluxSubscribeOnCallable$CallableSubscribeOnSubscription.run(FluxSubscribeOnCallable.java:228)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at

but I do not seem to have a way to add a hook to the reactor.core.publisher.Operators.onErrorDropped(Throwable, Context) context object from the MCP code so that I can for example present the error to the end user.
Now I have to use the static reactor.core.publisher.Hooks.onErrorDropped(Consumer<? super Throwable>) which is not very elevant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions