WithRequestConfig is a middleware that extracts MCP-related headers and sets them in the request context. This includes readonly mode, toolsets, tools, lockdown mode, insiders mode, and feature flags.
(next http.Handler)
| 12 | // WithRequestConfig is a middleware that extracts MCP-related headers and sets them in the request context. |
| 13 | // This includes readonly mode, toolsets, tools, lockdown mode, insiders mode, and feature flags. |
| 14 | func WithRequestConfig(next http.Handler) http.Handler { |
| 15 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 16 | ctx := r.Context() |
| 17 | |
| 18 | // Readonly mode |
| 19 | if relaxedParseBool(r.Header.Get(headers.MCPReadOnlyHeader)) { |
| 20 | ctx = ghcontext.WithReadonly(ctx, true) |
| 21 | } |
| 22 | |
| 23 | // Toolsets |
| 24 | if toolsets := headers.ParseCommaSeparated(r.Header.Get(headers.MCPToolsetsHeader)); len(toolsets) > 0 { |
| 25 | ctx = ghcontext.WithToolsets(ctx, toolsets) |
| 26 | } |
| 27 | |
| 28 | // Tools |
| 29 | if tools := headers.ParseCommaSeparated(r.Header.Get(headers.MCPToolsHeader)); len(tools) > 0 { |
| 30 | ctx = ghcontext.WithTools(ctx, tools) |
| 31 | } |
| 32 | |
| 33 | // Lockdown mode |
| 34 | if relaxedParseBool(r.Header.Get(headers.MCPLockdownHeader)) { |
| 35 | ctx = ghcontext.WithLockdownMode(ctx, true) |
| 36 | } |
| 37 | |
| 38 | // Excluded tools |
| 39 | if excludeTools := headers.ParseCommaSeparated(r.Header.Get(headers.MCPExcludeToolsHeader)); len(excludeTools) > 0 { |
| 40 | ctx = ghcontext.WithExcludeTools(ctx, excludeTools) |
| 41 | } |
| 42 | |
| 43 | // Insiders mode |
| 44 | if relaxedParseBool(r.Header.Get(headers.MCPInsidersHeader)) { |
| 45 | ctx = ghcontext.WithInsidersMode(ctx, true) |
| 46 | } |
| 47 | |
| 48 | // Feature flags |
| 49 | if features := headers.ParseCommaSeparated(r.Header.Get(headers.MCPFeaturesHeader)); len(features) > 0 { |
| 50 | ctx = ghcontext.WithHeaderFeatures(ctx, features) |
| 51 | } |
| 52 | |
| 53 | next.ServeHTTP(w, r.WithContext(ctx)) |
| 54 | }) |
| 55 | } |
| 56 | |
| 57 | // relaxedParseBool parses a string into a boolean value, treating various |
| 58 | // common false values or empty strings as false, and everything else as true. |
nothing calls this directly
no test coverage detected