Debian Codegraph @

debian/go/src/github.com/modelcontextprotocol/go-sdk/internal/mcpgodebug/mcpgodebug.go

raw symbols SCIP
1 // Copyright 2025 The Go MCP SDK Authors. All rights reserved.
2 // Use of this source code is governed by the license
3 // that can be found in the LICENSE file.
4
5 // Package mcpgodebug provides a mechanism to configure compatibility parameters
6 // via the MCPGODEBUG environment variable.
7 //
8 // The value of MCPGODEBUG is a comma-separated list of key=value pairs.
9 // For example:
10 //
11 // MCPGODEBUG=someoption=1,otheroption=value
12 package mcpgodebug
13
14 import (
15 "fmt"
16 "os"
17 "strings"
18 )
19
20 const compatibilityEnvKey = "MCPGODEBUG"
21
22 var compatibilityParams map[string]string
23
24 func init() {
25 var err error
26 compatibilityParams, err = parseCompatibility(os.Getenv(compatibilityEnvKey))
27 if err != nil {
28 panic(err)
29 }
30 }
31
32 // Value returns the value of the compatibility parameter with the given key.
33 // It returns an empty string if the key is not set.
34 func Value(key string) string {
35 return compatibilityParams[key]
36 }
37
38 func parseCompatibility(envValue string) (map[string]string, error) {
39 if envValue == "" {
40 return nil, nil
41 }
42
43 params := make(map[string]string)
44 for part := range strings.SplitSeq(envValue, ",") {
45 k, v, ok := strings.Cut(part, "=")
46 if !ok {
47 return nil, fmt.Errorf("MCPGODEBUG: invalid format: %q", part)
48 }
49 params[strings.TrimSpace(k)] = strings.TrimSpace(v)
50 }
51 return params, nil
52 }