Add MCP support to the FastAPI app if enabled in configuration.
(app, store: "feast.FeatureStore")
| 800 | |
| 801 | |
| 802 | def _add_mcp_support_if_enabled(app, store: "feast.FeatureStore"): |
| 803 | """Add MCP support to the FastAPI app if enabled in configuration.""" |
| 804 | mcp_transport_not_supported_error = None |
| 805 | try: |
| 806 | # Check if MCP is enabled in feature server config |
| 807 | if ( |
| 808 | store.config.feature_server |
| 809 | and hasattr(store.config.feature_server, "type") |
| 810 | and store.config.feature_server.type == "mcp" |
| 811 | and getattr(store.config.feature_server, "mcp_enabled", False) |
| 812 | ): |
| 813 | try: |
| 814 | from feast.infra.mcp_servers.mcp_server import ( |
| 815 | McpTransportNotSupportedError, |
| 816 | add_mcp_support_to_app, |
| 817 | ) |
| 818 | |
| 819 | mcp_transport_not_supported_error = McpTransportNotSupportedError |
| 820 | except ImportError as e: |
| 821 | logger.error(f"Error checking/adding MCP support: {e}") |
| 822 | return |
| 823 | |
| 824 | mcp_server = add_mcp_support_to_app(app, store, store.config.feature_server) |
| 825 | |
| 826 | if mcp_server: |
| 827 | logger.info("MCP support has been enabled for the Feast feature server") |
| 828 | else: |
| 829 | logger.warning("MCP support was requested but could not be enabled") |
| 830 | else: |
| 831 | logger.debug("MCP support is not enabled in feature server configuration") |
| 832 | except Exception as e: |
| 833 | if mcp_transport_not_supported_error and isinstance( |
| 834 | e, mcp_transport_not_supported_error |
| 835 | ): |
| 836 | raise |
| 837 | logger.error(f"Error checking/adding MCP support: {e}") |
| 838 | # Don't fail the entire server if MCP fails to initialize |
| 839 | |
| 840 | |
| 841 | if sys.platform != "win32": |