-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathmcp_server.py
More file actions
58 lines (45 loc) · 1.76 KB
/
mcp_server.py
File metadata and controls
58 lines (45 loc) · 1.76 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
"""
MCP (Model Context Protocol) integration for Feast Feature Server.
This module provides MCP support for Feast by integrating with fastapi_mcp
to expose Feast functionality through the Model Context Protocol.
"""
import logging
from typing import Optional
from feast.feature_store import FeatureStore
logger = logging.getLogger(__name__)
try:
from fastapi_mcp import FastApiMCP
MCP_AVAILABLE = True
except ImportError:
logger.warning(
"fastapi_mcp is not installed. MCP support will be disabled. "
"Install it with: pip install fastapi_mcp"
)
MCP_AVAILABLE = False
# Create placeholder classes for testing
FastApiMCP = None
def add_mcp_support_to_app(app, store: FeatureStore, config) -> Optional["FastApiMCP"]:
"""Add MCP support to the FastAPI app if enabled in configuration."""
if not MCP_AVAILABLE:
logger.warning("MCP support requested but fastapi_mcp is not available")
return None
try:
# Create MCP server from the FastAPI app
mcp = FastApiMCP(
app,
name=getattr(config, "mcp_server_name", "feast-feature-store"),
description="Feast Feature Store MCP Server - Access feature store data and operations through MCP",
)
# Mount the MCP server to the FastAPI app
mcp.mount()
logger.info(
"MCP support has been enabled for the Feast feature server at /mcp endpoint"
)
logger.info(
f"MCP integration initialized for {getattr(config, 'mcp_server_name', 'feast-feature-store')} "
f"v{getattr(config, 'mcp_server_version', '1.0.0')}"
)
return mcp
except Exception as e:
logger.error(f"Failed to initialize MCP integration: {e}")
return None