Also validate that requests observe the lifecycle rules defined in the spec. Change-Id: I302282f81e053e76926e0bb295f7dbf8d526f02d Reviewed-on: https://go-review.googlesource.com/c/tools/+/667575 Reviewed-by: Jonathan Amsterdam <jba@google.com> Commit-Queue: Robert Findley <rfindley@google.com> Auto-Submit: Robert Findley <rfindley@google.com> TryBot-Bypass: Robert Findley <rfindley@google.com>
34 lines
666 B
Go
34 lines
666 B
Go
// Copyright 2025 The Go MCP SDK Authors. All rights reserved.
|
|
// Use of this source code is governed by an MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package mcp
|
|
|
|
import (
|
|
"crypto/rand"
|
|
)
|
|
|
|
func assert(cond bool, msg string) {
|
|
if !cond {
|
|
panic(msg)
|
|
}
|
|
}
|
|
|
|
func is[T any](v any) bool {
|
|
_, ok := v.(T)
|
|
return ok
|
|
}
|
|
|
|
// 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)
|
|
}
|