package server
import (
"context"
"errors"
"github.com/mark3labs/mcp-go/mcp"
)
var (
ErrNoActiveSession = errors .New ("no active session" )
ErrElicitationNotSupported = errors .New ("session does not support elicitation" )
)
func (s *MCPServer ) RequestElicitation (ctx context .Context , request mcp .ElicitationRequest ) (*mcp .ElicitationResult , error ) {
session := ClientSessionFromContext (ctx )
if session == nil {
return nil , ErrNoActiveSession
}
if elicitationSession , ok := session .(SessionWithElicitation ); ok {
if err := request .Params .Validate (); err != nil {
return nil , err
}
return elicitationSession .RequestElicitation (ctx , request )
}
return nil , ErrElicitationNotSupported
}
func (s *MCPServer ) RequestURLElicitation (
ctx context .Context ,
session ClientSession ,
elicitationID string ,
url string ,
message string ,
) (*mcp .ElicitationResult , error ) {
if session == nil {
return nil , ErrNoActiveSession
}
params := mcp .ElicitationParams {
Mode : mcp .ElicitationModeURL ,
Message : message ,
ElicitationID : elicitationID ,
URL : url ,
}
if err := params .Validate (); err != nil {
return nil , err
}
request := mcp .ElicitationRequest {
Request : mcp .Request {
Method : string (mcp .MethodElicitationCreate ),
},
Params : params ,
}
if elicitationSession , ok := session .(SessionWithElicitation ); ok {
return elicitationSession .RequestElicitation (ctx , request )
}
return nil , ErrElicitationNotSupported
}
func (s *MCPServer ) SendElicitationComplete (
ctx context .Context ,
session ClientSession ,
elicitationID string ,
) error {
if session == nil {
return ErrNoActiveSession
}
jsonRPCNotif := mcp .NewElicitationCompleteNotification (elicitationID )
return s .sendNotificationCore (ctx , session , jsonRPCNotif )
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .