MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / _update_security_for_mcp

Method _update_security_for_mcp

api/api/openapi.py:127–155  ·  view source on GitHub ↗

Update security schemes for MCP (OAuth + API Key fallback).

(
        self, schema: dict[str, Any], oauth: OAuthConfig
    )

Source from the content-addressed store, hash-verified

125 return operation
126
127 def _update_security_for_mcp(
128 self, schema: dict[str, Any], oauth: OAuthConfig
129 ) -> dict[str, Any]:
130 """Update security schemes for MCP (OAuth + API Key fallback)."""
131 schema = schema.copy()
132 schema["components"] = schema.get("components", {}).copy()
133 schema["components"]["securitySchemes"] = {
134 "oauth2": {
135 "type": "oauth2",
136 "flows": {
137 "authorizationCode": {
138 "authorizationUrl": f"{oauth.frontend_url}/oauth/authorize/",
139 "tokenUrl": f"{oauth.api_url}/o/token/",
140 "scopes": oauth.scopes,
141 },
142 },
143 },
144 "TOKEN_AUTH": {
145 "type": "apiKey",
146 "in": "header",
147 "name": "Authorization",
148 "description": "Organisation API Key. Format: Api-Key <key>",
149 },
150 }
151 schema["security"] = [
152 {"oauth2": list(oauth.scopes.keys())},
153 {"TOKEN_AUTH": []},
154 ]
155 return schema
156
157
158class TypedDictSchemaExtension(OpenApiSerializerExtension):

Calls 1

getMethod · 0.45