-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathrequest.go
More file actions
131 lines (106 loc) · 4.04 KB
/
request.go
File metadata and controls
131 lines (106 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package context
import "context"
// readonlyCtxKey is a context key for read-only mode
type readonlyCtxKey struct{}
// WithReadonly adds read-only mode state to the context
func WithReadonly(ctx context.Context, enabled bool) context.Context {
return context.WithValue(ctx, readonlyCtxKey{}, enabled)
}
// IsReadonly retrieves the read-only mode state from the context
func IsReadonly(ctx context.Context) bool {
if enabled, ok := ctx.Value(readonlyCtxKey{}).(bool); ok {
return enabled
}
return false
}
// toolsetsCtxKey is a context key for the active toolsets
type toolsetsCtxKey struct{}
// WithToolsets adds the active toolsets to the context
func WithToolsets(ctx context.Context, toolsets []string) context.Context {
return context.WithValue(ctx, toolsetsCtxKey{}, toolsets)
}
// GetToolsets retrieves the active toolsets from the context
func GetToolsets(ctx context.Context) []string {
if toolsets, ok := ctx.Value(toolsetsCtxKey{}).([]string); ok {
return toolsets
}
return nil
}
// toolsCtxKey is a context key for tools
type toolsCtxKey struct{}
// WithTools adds the tools to the context
func WithTools(ctx context.Context, tools []string) context.Context {
return context.WithValue(ctx, toolsCtxKey{}, tools)
}
// GetTools retrieves the tools from the context
func GetTools(ctx context.Context) []string {
if tools, ok := ctx.Value(toolsCtxKey{}).([]string); ok {
return tools
}
return nil
}
// lockdownCtxKey is a context key for lockdown mode
type lockdownCtxKey struct{}
// WithLockdownMode adds lockdown mode state to the context
func WithLockdownMode(ctx context.Context, enabled bool) context.Context {
return context.WithValue(ctx, lockdownCtxKey{}, enabled)
}
// IsLockdownMode retrieves the lockdown mode state from the context
func IsLockdownMode(ctx context.Context) bool {
if enabled, ok := ctx.Value(lockdownCtxKey{}).(bool); ok {
return enabled
}
return false
}
// insidersCtxKey is a context key for insiders mode
type insidersCtxKey struct{}
// WithInsidersMode adds insiders mode state to the context
func WithInsidersMode(ctx context.Context, enabled bool) context.Context {
return context.WithValue(ctx, insidersCtxKey{}, enabled)
}
// IsInsidersMode retrieves the insiders mode state from the context
func IsInsidersMode(ctx context.Context) bool {
if enabled, ok := ctx.Value(insidersCtxKey{}).(bool); ok {
return enabled
}
return false
}
// excludeToolsCtxKey is a context key for excluded tools
type excludeToolsCtxKey struct{}
// WithExcludeTools adds the excluded tools to the context
func WithExcludeTools(ctx context.Context, tools []string) context.Context {
return context.WithValue(ctx, excludeToolsCtxKey{}, tools)
}
// GetExcludeTools retrieves the excluded tools from the context
func GetExcludeTools(ctx context.Context) []string {
if tools, ok := ctx.Value(excludeToolsCtxKey{}).([]string); ok {
return tools
}
return nil
}
// headerFeaturesCtxKey is a context key for raw header feature flags
type headerFeaturesCtxKey struct{}
// WithHeaderFeatures stores the raw feature flags from the X-MCP-Features header into context
func WithHeaderFeatures(ctx context.Context, features []string) context.Context {
return context.WithValue(ctx, headerFeaturesCtxKey{}, features)
}
// GetHeaderFeatures retrieves the raw feature flags from context
func GetHeaderFeatures(ctx context.Context) []string {
if features, ok := ctx.Value(headerFeaturesCtxKey{}).([]string); ok {
return features
}
return nil
}
// uiSupportCtxKey is a context key for MCP Apps UI support
type uiSupportCtxKey struct{}
// WithUISupport stores whether the client supports MCP Apps UI in the context.
// This is used by HTTP/stateless servers where the go-sdk session may not
// persist client capabilities across requests.
func WithUISupport(ctx context.Context, supported bool) context.Context {
return context.WithValue(ctx, uiSupportCtxKey{}, supported)
}
// HasUISupport retrieves the MCP Apps UI support flag from context.
func HasUISupport(ctx context.Context) (supported bool, ok bool) {
v, ok := ctx.Value(uiSupportCtxKey{}).(bool)
return v, ok
}