Add support for SSE transport, as defined by version 2024-11-05 and 2025-03-26 of the MCP spec. In order to achieve this, the jsonrpc2 stream must be abstracted so that we can implement it across multiple HTTP requests. This required some refactoring of the jsonrpc2_v2 package, so that we can avoid the Dialer/Binder interfaces and construct the Connection directly from its constituent primitives. Change-Id: Id627b5b5a474d92f2c613cfad904d14611e7c768 Reviewed-on: https://go-review.googlesource.com/c/tools/+/667475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
32 lines
661 B
Go
32 lines
661 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)
|
|
}
|