@@ -20,30 +20,31 @@ func Example_elicitation() {
2020 // Create server
2121 server := mcp .NewServer (& mcp.Implementation {Name : "config-server" , Version : "v1.0.0" }, nil )
2222
23- serverSession , err := server .Connect (ctx , serverTransport )
23+ serverSession , err := server .Connect (ctx , serverTransport , nil )
2424 if err != nil {
2525 log .Fatal (err )
2626 }
2727
2828 // Create client with elicitation handler
29+ // Note: Never use elicitation for sensitive data like API keys or passwords
2930 client := mcp .NewClient (& mcp.Implementation {Name : "config-client" , Version : "v1.0.0" }, & mcp.ClientOptions {
30- ElicitationHandler : func (ctx context.Context , cs * mcp.ClientSession , params * mcp. ElicitParams ) (* mcp.ElicitResult , error ) {
31- fmt .Printf ("Server requests: %s\n " , params .Message )
32-
31+ ElicitationHandler : func (ctx context.Context , request * mcp.ElicitRequest ) (* mcp.ElicitResult , error ) {
32+ fmt .Printf ("Server requests: %s\n " , request . Params .Message )
33+
3334 // In a real application, this would prompt the user for input
3435 // Here we simulate user providing configuration data
3536 return & mcp.ElicitResult {
3637 Action : "accept" ,
3738 Content : map [string ]any {
38- "apiKey " : "sk-test123 " ,
39- "maxRetries" : float64 (3 ),
40- "enableLogs" : true ,
39+ "serverEndpoint " : "https://api.example.com " ,
40+ "maxRetries" : float64 (3 ),
41+ "enableLogs" : true ,
4142 },
4243 }, nil
4344 },
4445 })
4546
46- _ , err = client .Connect (ctx , clientTransport )
47+ _ , err = client .Connect (ctx , clientTransport , nil )
4748 if err != nil {
4849 log .Fatal (err )
4950 }
@@ -52,11 +53,11 @@ func Example_elicitation() {
5253 configSchema := & jsonschema.Schema {
5354 Type : "object" ,
5455 Properties : map [string ]* jsonschema.Schema {
55- "apiKey " : {Type : "string" , Description : "API key for authentication " },
56- "maxRetries" : {Type : "number" , Minimum : ptr (1.0 ), Maximum : ptr (10.0 )},
57- "enableLogs" : {Type : "boolean" , Description : "Enable debug logging" },
56+ "serverEndpoint " : {Type : "string" , Description : "Server endpoint URL " },
57+ "maxRetries" : {Type : "number" , Minimum : ptr (1.0 ), Maximum : ptr (10.0 )},
58+ "enableLogs" : {Type : "boolean" , Description : "Enable debug logging" },
5859 },
59- Required : []string {"apiKey " },
60+ Required : []string {"serverEndpoint " },
6061 }
6162
6263 result , err := serverSession .Elicit (ctx , & mcp.ElicitParams {
@@ -68,18 +69,18 @@ func Example_elicitation() {
6869 }
6970
7071 if result .Action == "accept" {
71- fmt .Printf ("Configuration received: API Key : %v, Max Retries: %.0f, Logs: %v\n " ,
72- result .Content ["apiKey " ],
72+ fmt .Printf ("Configuration received: Endpoint : %v, Max Retries: %.0f, Logs: %v\n " ,
73+ result .Content ["serverEndpoint " ],
7374 result .Content ["maxRetries" ],
7475 result .Content ["enableLogs" ])
7576 }
7677
7778 // Output:
7879 // Server requests: Please provide your configuration settings
79- // Configuration received: API Key: sk-test123 , Max Retries: 3, Logs: true
80+ // Configuration received: Endpoint: https://api.example.com , Max Retries: 3, Logs: true
8081}
8182
8283// ptr is a helper function to create pointers for schema constraints
8384func ptr [T any ](v T ) * T {
8485 return & v
85- }
86+ }
0 commit comments