aminghadersohi commented on code in PR #33976: URL: https://github.com/apache/superset/pull/33976#discussion_r2230076183
########## superset/mcp_service/mcp_app.py: ########## @@ -0,0 +1,90 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +""" +FastMCP app instance and initialization for Superset MCP service. +This file provides the global FastMCP instance (mcp) and a function to initialize +middleware. All tool modules should import mcp from here and use @mcp.tool and +@mcp_auth_hook decorators. +""" + +import logging + +from fastmcp import FastMCP + +from superset.mcp_service.middleware import LoggingMiddleware, PrivateToolMiddleware + +mcp = FastMCP( + "Superset MCP Server", + instructions=""" Review Comment: @dpgaspar Thanks for the excellent suggestion! I've implemented the configurable factory pattern as you outlined. The MCP service now uses `app.config["MCP_AUTH_FACTORY"](app)` to create the auth provider, following the same pattern as MACHINE_AUTH_PROVIDER_CLASS. Implementation details: 1. Default factory in superset/mcp_service/config.py: ``` def create_default_mcp_auth_factory(app: Flask) -> Optional[Any]: """Default MCP auth factory that uses app.config values.""" if not app.config.get("MCP_AUTH_ENABLED", False): return None jwks_uri = app.config.get("MCP_JWKS_URI") # ... create and return BearerAuthProvider ``` 2. Usage in the MCP service initialization: ``` auth_factory = app.config.get("MCP_AUTH_FACTORY") if auth_factory and callable(auth_factory): return auth_factory(app) ``` 3. User configuration in superset_config.py: ``` # Simple approach - just set values MCP_AUTH_ENABLED = True MCP_JWKS_URI = "https://your-provider.com/.well-known/jwks.json" # Or provide custom factory def create_auth(app): jwks_uri = app.config["MCP_JWKS_URI"] return BearerAuthProvider(jwks_uri=jwks_uri, ...) MCP_AUTH_FACTORY = create_auth ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
