Skip to content
Merged
Show file tree
Hide file tree
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
59 changes: 35 additions & 24 deletions pkg/mcp/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,30 +184,31 @@ type methodHandler func(map[string]interface{}) (string, map[string]interface{})

// methodHandlers maps MCP methods to their respective handlers
var methodHandlers = map[string]methodHandler{
"initialize": handleInitializeMethod,
"tools/call": handleNamedResourceMethod,
"prompts/get": handleNamedResourceMethod,
"resources/read": handleResourceReadMethod,
"resources/list": handleListMethod,
"tools/list": handleListMethod,
"prompts/list": handleListMethod,
"progress/update": handleProgressMethod,
"notifications/message": handleNotificationMethod,
"logging/setLevel": handleLoggingMethod,
"completion/complete": handleCompletionMethod,
"elicitation/create": handleElicitationMethod,
"sampling/createMessage": handleSamplingMethod,
"resources/subscribe": handleResourceSubscribeMethod,
"resources/unsubscribe": handleResourceUnsubscribeMethod,
"resources/templates/list": handleListMethod,
"roots/list": handleListMethod,
"notifications/progress": handleProgressNotificationMethod,
"notifications/cancelled": handleCancelledNotificationMethod,
"tasks/list": handleListMethod,
"tasks/get": handleTaskIDMethod,
"tasks/cancel": handleTaskIDMethod,
"tasks/result": handleTaskIDMethod,
"notifications/tasks/status": handleTaskStatusNotificationMethod,
"initialize": handleInitializeMethod,
"tools/call": handleNamedResourceMethod,
"prompts/get": handleNamedResourceMethod,
"resources/read": handleResourceReadMethod,
"resources/list": handleListMethod,
"tools/list": handleListMethod,
"prompts/list": handleListMethod,
"progress/update": handleProgressMethod,
"notifications/message": handleNotificationMethod,
"logging/setLevel": handleLoggingMethod,
"completion/complete": handleCompletionMethod,
"elicitation/create": handleElicitationMethod,
"sampling/createMessage": handleSamplingMethod,
"resources/subscribe": handleResourceSubscribeMethod,
"resources/unsubscribe": handleResourceUnsubscribeMethod,
"resources/templates/list": handleListMethod,
"roots/list": handleListMethod,
"notifications/progress": handleProgressNotificationMethod,
"notifications/cancelled": handleCancelledNotificationMethod,
"tasks/list": handleListMethod,
"tasks/get": handleTaskIDMethod,
"tasks/cancel": handleTaskIDMethod,
"tasks/result": handleTaskIDMethod,
"notifications/tasks/status": handleTaskStatusNotificationMethod,
"notifications/elicitation/complete": handleElicitationCompleteNotificationMethod,
}

// staticResourceIDs maps methods to their static resource IDs
Expand Down Expand Up @@ -359,6 +360,16 @@ func handleElicitationMethod(paramsMap map[string]interface{}) (string, map[stri
return "", paramsMap
}

// handleElicitationCompleteNotificationMethod extracts resource ID for elicitation complete notifications.
// This notification is sent by the server when an out-of-band URL-mode elicitation is completed.
// Returns the elicitationId as the resource identifier.
func handleElicitationCompleteNotificationMethod(paramsMap map[string]interface{}) (string, map[string]interface{}) {
if elicitationId, ok := paramsMap["elicitationId"].(string); ok {
return elicitationId, paramsMap
}
return "", paramsMap
}

// handleSamplingMethod extracts resource ID for sampling/createMessage requests.
// Returns the model name from modelPreferences if available, otherwise returns a
// truncated version of the systemPrompt. The 50-character truncation provides a
Expand Down
27 changes: 27 additions & 0 deletions pkg/mcp/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ func TestParsingMiddleware(t *testing.T) {
expectedID: int64(6),
expectedResID: "debug",
},
{
name: "notifications/elicitation/complete notification",
method: "POST",
path: "/messages",
contentType: "application/json",
body: `{"jsonrpc":"2.0","method":"notifications/elicitation/complete","params":{"elicitationId":"550e8400-e29b-41d4-a716-446655440000"}}`,
expectParsed: true,
expectedMethod: "notifications/elicitation/complete",
expectedID: nil,
expectedResID: "550e8400-e29b-41d4-a716-446655440000",
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -770,6 +781,22 @@ func TestExtractResourceAndArguments(t *testing.T) {
expectedResourceID: "page-2",
expectedArguments: nil,
},
{
name: "notifications/elicitation/complete with elicitationId",
method: "notifications/elicitation/complete",
params: `{"elicitationId":"550e8400-e29b-41d4-a716-446655440000"}`,
expectedResourceID: "550e8400-e29b-41d4-a716-446655440000",
expectedArguments: map[string]interface{}{
"elicitationId": "550e8400-e29b-41d4-a716-446655440000",
},
},
{
name: "notifications/elicitation/complete with missing elicitationId",
method: "notifications/elicitation/complete",
params: `{}`,
expectedResourceID: "",
expectedArguments: map[string]interface{}{},
},
}

for _, tt := range tests {
Expand Down
Loading