mcp: use rand.Text and slog.DiscardHandler over internal implementation (#773)
Address TODOs in code requiring go 1.24 as minimum version mcp/logging.go: use slog.DiscardHandler, over local implementation mcp/util.go: use rand.Text, over local implementation Fixes #772
This commit is contained in:
parent
cf88bda0c5
commit
df4f0d56a4
1 changed files with 10 additions and 44 deletions
|
|
@ -234,7 +234,7 @@ func deepCopyThoughts(thoughts []*Thought) []*Thought {
|
|||
func StartThinking(ctx context.Context, _ *mcp.CallToolRequest, args StartThinkingArgs) (*mcp.CallToolResult, any, error) {
|
||||
sessionID := args.SessionID
|
||||
if sessionID == "" {
|
||||
sessionID = randText()
|
||||
sessionID = rand.Text()
|
||||
}
|
||||
|
||||
estimatedSteps := args.EstimatedSteps
|
||||
|
|
@ -480,20 +480,6 @@ func ThinkingHistory(ctx context.Context, req *mcp.ReadResourceRequest) (*mcp.Re
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Copied from crypto/rand.
|
||||
// TODO: once 1.24 is assured, just use crypto/rand.
|
||||
const base32alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
|
||||
|
||||
func randText() string {
|
||||
// ⌈log₃₂ 2¹²⁸⌉ = 26 chars
|
||||
src := make([]byte, 26)
|
||||
rand.Read(src)
|
||||
for i := range src {
|
||||
src[i] = base32alphabet[src[i]%32]
|
||||
}
|
||||
return string(src)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue