-
-
Notifications
You must be signed in to change notification settings - Fork 451
fix: normalize MCP elicitation requests with empty message
#895
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@voltagent/core": patch | ||
| --- | ||
|
|
||
| fix: normalize MCP elicitation requests with empty `message` by falling back to the schema description so handlers receive a usable prompt. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| module voltagent-example-mcp-elicitation-go | ||
|
|
||
| go 1.23.0 | ||
|
|
||
| require ( | ||
| github.com/google/jsonschema-go v0.3.0 | ||
| github.com/modelcontextprotocol/go-sdk v1.2.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/yosida95/uritemplate/v3 v3.0.2 // indirect | ||
| golang.org/x/oauth2 v0.30.0 // indirect | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= | ||
| github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= | ||
| github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= | ||
| github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= | ||
| github.com/google/jsonschema-go v0.3.0 h1:6AH2TxVNtk3IlvkkhjrtbUc4S8AvO0Xii0DxIygDg+Q= | ||
| github.com/google/jsonschema-go v0.3.0/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE= | ||
| github.com/modelcontextprotocol/go-sdk v1.2.0 h1:Y23co09300CEk8iZ/tMxIX1dVmKZkzoSBZOpJwUnc/s= | ||
| github.com/modelcontextprotocol/go-sdk v1.2.0/go.mod h1:6fM3LCm3yV7pAs8isnKLn07oKtB0MP9LHd3DfAcKw10= | ||
| github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4= | ||
| github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4= | ||
| golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI= | ||
| golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU= | ||
| golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo= | ||
| golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "fmt" | ||
| "log" | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| "github.com/google/jsonschema-go/jsonschema" | ||
| "github.com/modelcontextprotocol/go-sdk/mcp" | ||
| ) | ||
|
|
||
| type DeleteCustomerParams struct { | ||
| CustomerID string `json:"customerId" jsonschema:"Customer ID to delete"` | ||
| } | ||
|
|
||
| func deleteCustomer( | ||
| ctx context.Context, | ||
| req *mcp.CallToolRequest, | ||
| params DeleteCustomerParams, | ||
| ) (*mcp.CallToolResult, any, error) { | ||
| schema := &jsonschema.Schema{ | ||
| Type: "object", | ||
| Description: "Confirm the deletion of the data.", | ||
| Properties: map[string]*jsonschema.Schema{ | ||
| "confirm": {Type: "boolean", Description: "Confirm the deletion of the data."}, | ||
| }, | ||
| Required: []string{"confirm"}, | ||
| } | ||
|
|
||
| result, err := req.Session.Elicit(ctx, &mcp.ElicitParams{ | ||
| // Intentionally blank to exercise client-side fallback to schema description. | ||
| Message: "", | ||
| RequestedSchema: schema, | ||
| }) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("eliciting failed: %w", err) | ||
| } | ||
|
|
||
| confirmed := false | ||
| if result != nil && result.Action == "accept" { | ||
| if value, ok := result.Content["confirm"]; ok { | ||
| switch typed := value.(type) { | ||
| case bool: | ||
| confirmed = typed | ||
| case string: | ||
| confirmed = strings.EqualFold(strings.TrimSpace(typed), "yes") | ||
| default: | ||
| confirmed = strings.EqualFold(strings.TrimSpace(fmt.Sprint(value)), "yes") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| message := fmt.Sprintf("Deletion cancelled for %s.", params.CustomerID) | ||
| if confirmed { | ||
| message = fmt.Sprintf("Customer %s deleted.", params.CustomerID) | ||
| } | ||
|
|
||
| return &mcp.CallToolResult{ | ||
| Content: []mcp.Content{ | ||
| &mcp.TextContent{Text: message}, | ||
| }, | ||
| }, nil, nil | ||
| } | ||
|
|
||
| func main() { | ||
| host := flag.String("host", "127.0.0.1", "host to listen on") | ||
| port := flag.Int("port", 3142, "port to listen on") | ||
| flag.Parse() | ||
|
|
||
| addr := fmt.Sprintf("%s:%d", *host, *port) | ||
|
|
||
| server := mcp.NewServer(&mcp.Implementation{ | ||
| Name: "go-elicitation-server", | ||
| Version: "0.1.0", | ||
| }, nil) | ||
|
|
||
| mcp.AddTool(server, &mcp.Tool{ | ||
| Name: "customer_delete", | ||
| Description: "Delete a customer after user confirmation.", | ||
| }, deleteCustomer) | ||
|
|
||
| handler := mcp.NewStreamableHTTPHandler(func(_ *http.Request) *mcp.Server { | ||
| return server | ||
| }, nil) | ||
|
|
||
| mux := http.NewServeMux() | ||
| mux.Handle("/mcp", handler) | ||
|
|
||
| log.Printf("MCP server listening on http://%s/mcp", addr) | ||
| if err := http.ListenAndServe(addr, mux); err != nil { | ||
| log.Fatalf("server failed: %v", err) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Dead code:
startMcpServer(port, logger)will never be called becauseserverUrlis hardcoded to a truthy string. The||fallback is unreachable. Either remove the fallback or use a conditional that can actually be falsy (e.g., uncomment the env var access).Prompt for AI agents