Skip to content

Expand InitializeRequestHandler #390

@TheEterna

Description

@TheEterna

I've noticed that the current InitializeRequestHandler doesn't have any access points, which means it's difficult for the server to perform exclusive initialization operations for different clients. My modification suggestions are as follows:

io.modelcontextprotocol.spec.McpServerSession#handleIncomingNotification

private Mono<Void> handleIncomingNotification(McpSchema.JSONRPCNotification notification) {
		return Mono.defer(() -> {
			if (McpSchema.METHOD_NOTIFICATION_INITIALIZED.equals(notification.method())) {
				this.state.lazySet(STATE_INITIALIZED);
				exchangeSink.tryEmitValue(new McpAsyncServerExchange(this, clientCapabilities.get(), clientInfo.get()));
// modify method signature ,and expose the initNotify Handler for user settings
				return this.exchangeSink.asMono().flatMap(exchange -> this.initNotificationHandler.handle(exchange, notification.params()));

			}

			var handler = notificationHandlers.get(notification.method());
			if (handler == null) {
				logger.error("No handler registered for notification method: {}", notification.method());
				return Mono.empty();
			}
			return this.exchangeSink.asMono().flatMap(exchange -> handler.handle(exchange, notification.params()));
		});
	}

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