Skip to content

Fix for #56 - missing method attribute from client RPC message #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ plugins {
}

group = "io.modelcontextprotocol"
version = "0.3.0"
version = "0.3.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please revert the version change? We will do this manually before the release.


val mainSourcesJar = tasks.register<Jar>("mainSourcesJar") {
archiveClassifier = "sources"
Original file line number Diff line number Diff line change
@@ -186,18 +186,28 @@ public abstract class Protocol(

private suspend fun onNotification(notification: JSONRPCNotification) {
LOGGER.trace { "Received notification: ${notification.method}" }
val function = notificationHandlers[notification.method]

// Ensure method is in params if it's a JsonObject
val processedNotification = if (notification.params is JsonObject && !notification.params.containsKey("method")) {
notification.copy(
params = JsonObject(notification.params as JsonObject + ("method" to JsonPrimitive(notification.method)))
)
} else {
notification
}

val function = notificationHandlers[processedNotification.method]
val property = fallbackNotificationHandler
val handler = function ?: property

if (handler == null) {
LOGGER.trace { "No handler found for notification: ${notification.method}" }
LOGGER.trace { "No handler found for notification: ${processedNotification.method}" }
return
}
try {
handler(notification)
handler(processedNotification)
} catch (cause: Throwable) {
LOGGER.error(cause) { "Error handling notification: ${notification.method}" }
LOGGER.error(cause) { "Error handling notification: ${processedNotification.method}" }
onError(cause)
}
}