Skip to content

Commit faf3954

Browse files
YassinNouh21franciscojavierarceoSrihari1192Fiona-Waters
authored andcommitted
feat: Add MCP (Model Context Protocol) support for Feast feature server (feast-dev#5406)
* Revert "fix: Update milvus connect function to work with remote instance" (feast-dev#5398) Revert "fix: Update milvus connect function to work with remote instance (feast-dev#5382)" This reverts commit 7e5e7d5. Signed-off-by: yassinnouh21 <[email protected]> * test: Add Operator E2E tests for Feast Apply and Materialize functionality (feast-dev#5389) Signed-off-by: Srihari <[email protected]> Signed-off-by: yassinnouh21 <[email protected]> * fix: Updating milvus connect function to work with remote instance (feast-dev#5401) * Updating milvus connect function to work with remote instance Signed-off-by: Fiona Waters <[email protected]> * Update test configuration to use path for db Signed-off-by: Fiona Waters <[email protected]> --------- Signed-off-by: Fiona Waters <[email protected]> Signed-off-by: yassinnouh21 <[email protected]> * feat: Add MCP support to feature server configuration Signed-off-by: yassinnouh21 <[email protected]> * fix linter Signed-off-by: yassinnouh21 <[email protected]> * add example Signed-off-by: yassinnouh21 <[email protected]> * test: add test cases for the mcp server Signed-off-by: yassinnouh21 <[email protected]> * fix linter Signed-off-by: yassinnouh21 <[email protected]> * formatting Signed-off-by: yassinnouh21 <[email protected]> * docs: update README for MCP setup instructions Signed-off-by: yassinnouh21 <[email protected]> * fix: update transformation service endpoint and refactor MCP integration Signed-off-by: yassinnouh21 <[email protected]> * feat: add Model Context Protocol (MCP) support and update documentation Signed-off-by: yassinnouh21 <[email protected]> * fix: update entity key serialization version and improve README clarity Signed-off-by: yassinnouh21 <[email protected]> * fix: refactor MCP imports to use the correct module path Signed-off-by: yassinnouh21 <[email protected]> * feat: Add MCP server implementation files Signed-off-by: yassinnouh21 <[email protected]> * test: MCP server unit tests and integration tests Signed-off-by: yassinnouh21 <[email protected]> * fix formatting Signed-off-by: yassinnouh21 <[email protected]> * fix formatting Signed-off-by: yassinnouh21 <[email protected]> * adding compiled requirements Signed-off-by: Francisco Javier Arceo <[email protected]> * fix linter Signed-off-by: Francisco Javier Arceo <[email protected]> * reverting duckdb change Signed-off-by: Francisco Javier Arceo <[email protected]> * needed to do file source and duckdb Signed-off-by: Francisco Javier Arceo <[email protected]> --------- Signed-off-by: yassinnouh21 <[email protected]> Signed-off-by: Srihari <[email protected]> Signed-off-by: Fiona Waters <[email protected]> Signed-off-by: Francisco Javier Arceo <[email protected]> Co-authored-by: Francisco Arceo <[email protected]> Co-authored-by: Srihari Venkataramaiah <[email protected]> Co-authored-by: Fiona Waters <[email protected]> Co-authored-by: Francisco Javier Arceo <[email protected]> Signed-off-by: Jacob Weinhold <[email protected]>
1 parent e74fc07 commit faf3954

30 files changed

+8223
-5913
lines changed

docs/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
* [Validating historical features with Great Expectations](tutorials/validating-historical-features.md)
5454
* [Building streaming features](tutorials/building-streaming-features.md)
5555
* [Retrieval Augmented Generation (RAG) with Feast](tutorials/rag-with-docling.md)
56+
* [MCP - AI Agent Example](../examples/mcp_feature_store/README.md)
5657

5758
## How-to Guides
5859

@@ -147,6 +148,7 @@
147148
* [Feature servers](reference/feature-servers/README.md)
148149
* [Python feature server](reference/feature-servers/python-feature-server.md)
149150
* [\[Alpha\] Go feature server](reference/feature-servers/go-feature-server.md)
151+
* [MCP Feature Server](reference/feature-servers/mcp-feature-server.md)
150152
* [Offline Feature Server](reference/feature-servers/offline-feature-server.md)
151153
* [Registry server](reference/feature-servers/registry-server.md)
152154
* [\[Beta\] Web UI](reference/alpha-web-ui.md)

docs/getting-started/genai.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,62 @@ This integration enables:
103103
- Generating embeddings for millions of text chunks
104104
- Efficiently materializing features to vector databases
105105
- Scaling RAG applications to enterprise-level document repositories
106+
107+
## Model Context Protocol (MCP) Support
108+
109+
Feast supports the Model Context Protocol (MCP), which enables AI agents and applications to interact with your feature store through standardized MCP interfaces. This allows seamless integration with LLMs and AI agents for GenAI applications.
110+
111+
### Key Benefits of MCP Support
112+
113+
* **Standardized AI Integration**: Enable AI agents to discover and use features dynamically without hardcoded definitions
114+
* **Easy Setup**: Add MCP support with a simple configuration change and `pip install feast[mcp]`
115+
* **Agent-Friendly APIs**: Expose feature store capabilities through MCP tools that AI agents can understand and use
116+
* **Production Ready**: Built on top of Feast's proven feature serving infrastructure
117+
118+
### Getting Started with MCP
119+
120+
1. **Install MCP support**:
121+
```bash
122+
pip install feast[mcp]
123+
```
124+
125+
2. **Configure your feature store** to use MCP:
126+
```yaml
127+
feature_server:
128+
type: mcp
129+
enabled: true
130+
mcp_enabled: true
131+
mcp_server_name: "feast-feature-store"
132+
mcp_server_version: "1.0.0"
133+
```
134+
135+
### How It Works
136+
137+
The MCP integration uses the `fastapi_mcp` library to automatically transform your Feast feature server's FastAPI endpoints into MCP-compatible tools. When you enable MCP support:
138+
139+
1. **Automatic Discovery**: The integration scans your FastAPI application and discovers all available endpoints
140+
2. **Tool Generation**: Each endpoint becomes an MCP tool with auto-generated schemas and descriptions
141+
3. **Dynamic Access**: AI agents can discover and call these tools dynamically without hardcoded definitions
142+
4. **Standard Protocol**: Uses the Model Context Protocol for standardized AI-to-API communication
143+
144+
### Available MCP Tools
145+
146+
The fastapi_mcp integration automatically exposes your Feast feature server's FastAPI endpoints as MCP tools. This means AI assistants can:
147+
148+
* **Call `/get-online-features`** to retrieve features from the feature store
149+
* **Use `/health`** to check server status
150+
151+
For a complete example, see the [MCP Feature Store Example](../../examples/mcp_feature_store/).
152+
106153
## Learn More
107154

108155
For more detailed information and examples:
109156

110157
* [Vector Database Reference](../reference/alpha-vector-database.md)
111158
* [RAG Tutorial with Docling](../tutorials/rag-with-docling.md)
112159
* [Milvus Quickstart Example](https://github.com/feast-dev/feast/tree/master/examples/rag/milvus-quickstart.ipynb)
160+
* [MCP Feature Store Example](../../examples/mcp_feature_store/)
161+
* [MCP Feature Server Reference](../reference/feature-servers/mcp-feature-server.md)
113162
* [Spark Data Source](../reference/data-sources/spark.md)
114163
* [Spark Offline Store](../reference/offline-stores/spark.md)
115164
* [Spark Batch Materialization](../reference/batch-materialization/spark.md)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Feast MCP Feature Server Example
2+
3+
This example demonstrates how to enable MCP (Model Context Protocol) support in Feast, allowing AI agents and applications to interact with your features through standardized MCP interfaces.
4+
5+
## Prerequisites
6+
7+
1. Python 3.8+
8+
2. Feast installed
9+
3. FastAPI MCP library
10+
11+
## Installation
12+
13+
1. Install Feast with MCP support:
14+
```bash
15+
pip install feast[mcp]
16+
```
17+
18+
Alternatively, you can install the dependencies separately:
19+
```bash
20+
pip install feast
21+
pip install fastapi_mcp
22+
```
23+
24+
## Setup
25+
26+
1. Navigate to this example directory within your cloned Feast repository:
27+
```bash
28+
cd examples/mcp_feature_store
29+
```
30+
31+
2. Initialize a Feast repository in this directory. We'll use the existing `feature_store.yaml` that's already configured for MCP:
32+
```bash
33+
feast init .
34+
```
35+
This will create a `data` subdirectory and a `feature_repo` subdirectory if they don't exist, and will use the `feature_store.yaml` present in the current directory (`examples/mcp_feature_store`).
36+
37+
3. Apply the feature store configuration:
38+
```bash
39+
cd feature_repo
40+
feast apply
41+
cd .. # Go back to examples/mcp_feature_store for the next steps
42+
```
43+
44+
## Starting the MCP-Enabled Feature Server
45+
46+
Start the Feast feature server with MCP support:
47+
48+
```bash
49+
feast serve --host 0.0.0.0 --port 6566
50+
```
51+
52+
If MCP is properly configured, you should see a log message indicating that MCP support has been enabled:
53+
54+
```
55+
INFO:feast.feature_server:MCP support has been enabled for the Feast feature server
56+
```
57+
58+
## Available MCP Tools
59+
60+
The fastapi_mcp integration automatically exposes your Feast feature server's FastAPI endpoints as MCP tools. This means AI assistants can:
61+
62+
- **Call `/get-online-features`** to retrieve features from the feature store
63+
- **Use `/health`** to check server status
64+
65+
66+
## Configuration Details
67+
68+
The key configuration that enables MCP support:
69+
70+
```yaml
71+
feature_server:
72+
type: mcp # Use MCP feature server type
73+
enabled: true # Enable feature server
74+
mcp_enabled: true # Enable MCP protocol support
75+
mcp_server_name: "feast-feature-store"
76+
mcp_server_version: "1.0.0"
77+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
project: feast_mcp_example
2+
registry: data/registry.db
3+
provider: local
4+
5+
online_store:
6+
type: sqlite
7+
path: data/online_store.db
8+
9+
offline_store:
10+
type: file
11+
12+
# MCP Feature Server Configuration
13+
feature_server:
14+
type: mcp
15+
enabled: true
16+
mcp_enabled: true # Enable MCP support - defaults to false
17+
mcp_server_name: "feast-feature-store"
18+
mcp_server_version: "1.0.0"
19+
feature_logging:
20+
enabled: false
21+
22+
entity_key_serialization_version: 3

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ snowflake = [
116116
"snowflake-connector-python[pandas]>=3.7,<4",
117117
]
118118
sqlite_vec = ["sqlite-vec==v0.1.6"]
119+
mcp = ["fastapi_mcp"]
119120

120121
ci = [
121122
"build",
@@ -162,13 +163,13 @@ ci = [
162163
"types-setuptools",
163164
"types-tabulate",
164165
"virtualenv<20.24.2",
165-
"feast[aws, azure, cassandra, clickhouse, couchbase, delta, docling, duckdb, elasticsearch, faiss, gcp, ge, go, grpcio, hazelcast, hbase, ibis, ikv, k8s, milvus, mssql, mysql, opentelemetry, spark, trino, postgres, pytorch, qdrant, redis, singlestore, snowflake, sqlite_vec]"
166+
"feast[aws, azure, cassandra, clickhouse, couchbase, delta, docling, duckdb, elasticsearch, faiss, gcp, ge, go, grpcio, hazelcast, hbase, ibis, ikv, k8s, mcp, milvus, mssql, mysql, opentelemetry, spark, trino, postgres, pytorch, qdrant, redis, singlestore, snowflake, sqlite_vec]"
166167
]
167168
nlp = ["feast[docling, milvus, pytorch]"]
168169
dev = ["feast[ci]"]
169170
docs = ["feast[ci]"]
170171
# used for the 'feature-server' container image build
171-
minimal = ["feast[aws, gcp, snowflake, redis, go, mysql, postgres-c, opentelemetry, grpcio, k8s, duckdb, milvus]"]
172+
minimal = ["feast[aws, gcp, snowflake, redis, go, mysql, postgres-c, opentelemetry, grpcio, k8s, duckdb, mcp, milvus]"]
172173
minimal-sdist-build = [
173174
"feast[minimal]",
174175
"feast[ibis]",

sdk/python/feast/feature_server.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def get_app(
173173
- `/materialize-incremental`: Materialize features incrementally
174174
- `/chat`: Chat UI
175175
- `/ws/chat`: WebSocket endpoint for chat
176+
MCP Support:
177+
- If MCP is enabled in feature server configuration, MCP endpoints will be added automatically
176178
"""
177179
proto_json.patch()
178180
# Asynchronously refresh registry, notifying shutdown and canceling the active timer if the app is shutting down
@@ -490,9 +492,37 @@ async def websocket_endpoint(websocket: WebSocket):
490492
with importlib_resources.as_file(static_dir_ref) as static_dir:
491493
app.mount("/static", StaticFiles(directory=static_dir), name="static")
492494

495+
# Add MCP support if enabled in feature server configuration
496+
_add_mcp_support_if_enabled(app, store)
497+
493498
return app
494499

495500

501+
def _add_mcp_support_if_enabled(app, store: "feast.FeatureStore"):
502+
"""Add MCP support to the FastAPI app if enabled in configuration."""
503+
try:
504+
# Check if MCP is enabled in feature server config
505+
if (
506+
store.config.feature_server
507+
and hasattr(store.config.feature_server, "type")
508+
and store.config.feature_server.type == "mcp"
509+
and getattr(store.config.feature_server, "mcp_enabled", False)
510+
):
511+
from feast.infra.mcp_servers.mcp_server import add_mcp_support_to_app
512+
513+
mcp_server = add_mcp_support_to_app(app, store, store.config.feature_server)
514+
515+
if mcp_server:
516+
logger.info("MCP support has been enabled for the Feast feature server")
517+
else:
518+
logger.warning("MCP support was requested but could not be enabled")
519+
else:
520+
logger.debug("MCP support is not enabled in feature server configuration")
521+
except Exception as e:
522+
logger.error(f"Error checking/adding MCP support: {e}")
523+
# Don't fail the entire server if MCP fails to initialize
524+
525+
496526
if sys.platform != "win32":
497527
import gunicorn.app.base
498528

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# MCP (Model Context Protocol) server implementations for Feast
2+
3+
from .mcp_config import McpFeatureServerConfig
4+
from .mcp_server import add_mcp_support_to_app
5+
6+
__all__ = [
7+
"McpFeatureServerConfig",
8+
"add_mcp_support_to_app",
9+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import Literal, Optional
2+
3+
from pydantic import StrictBool, StrictStr
4+
5+
from feast.infra.feature_servers.base_config import BaseFeatureServerConfig
6+
7+
8+
class McpFeatureServerConfig(BaseFeatureServerConfig):
9+
"""MCP (Model Context Protocol) Feature Server configuration."""
10+
11+
# Feature server type selector
12+
type: Literal["mcp"] = "mcp"
13+
14+
# Enable MCP server support - defaults to False as requested
15+
mcp_enabled: StrictBool = False
16+
17+
# MCP server name for identification
18+
mcp_server_name: StrictStr = "feast-mcp-server"
19+
20+
# MCP server version
21+
mcp_server_version: StrictStr = "1.0.0"
22+
23+
# Optional MCP transport configuration
24+
mcp_transport: Optional[StrictStr] = None
25+
26+
# The endpoint definition for transformation_service (inherited from base)
27+
transformation_service_endpoint: StrictStr = "localhost:6566"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
MCP (Model Context Protocol) integration for Feast Feature Server.
3+
4+
This module provides MCP support for Feast by integrating with fastapi_mcp
5+
to expose Feast functionality through the Model Context Protocol.
6+
"""
7+
8+
import logging
9+
from typing import Optional
10+
11+
from feast.feature_store import FeatureStore
12+
13+
logger = logging.getLogger(__name__)
14+
15+
try:
16+
from fastapi_mcp import FastApiMCP
17+
18+
MCP_AVAILABLE = True
19+
except ImportError:
20+
logger.warning(
21+
"fastapi_mcp is not installed. MCP support will be disabled. "
22+
"Install it with: pip install fastapi_mcp"
23+
)
24+
MCP_AVAILABLE = False
25+
# Create placeholder classes for testing
26+
FastApiMCP = None
27+
28+
29+
def add_mcp_support_to_app(app, store: FeatureStore, config) -> Optional["FastApiMCP"]:
30+
"""Add MCP support to the FastAPI app if enabled in configuration."""
31+
if not MCP_AVAILABLE:
32+
logger.warning("MCP support requested but fastapi_mcp is not available")
33+
return None
34+
35+
try:
36+
# Create MCP server from the FastAPI app
37+
mcp = FastApiMCP(
38+
app,
39+
name=getattr(config, "mcp_server_name", "feast-feature-store"),
40+
description="Feast Feature Store MCP Server - Access feature store data and operations through MCP",
41+
)
42+
43+
# Mount the MCP server to the FastAPI app
44+
mcp.mount()
45+
46+
logger.info(
47+
"MCP support has been enabled for the Feast feature server at /mcp endpoint"
48+
)
49+
logger.info(
50+
f"MCP integration initialized for {getattr(config, 'mcp_server_name', 'feast-feature-store')} "
51+
f"v{getattr(config, 'mcp_server_version', '1.0.0')}"
52+
)
53+
54+
return mcp
55+
56+
except Exception as e:
57+
logger.error(f"Failed to initialize MCP integration: {e}")
58+
return None

sdk/python/feast/infra/offline_stores/duckdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _write_data_source(
9696
prev_schema = (
9797
DeltaTable(file_options.uri, storage_options=storage_options)
9898
.schema()
99-
.to_pyarrow()
99+
.to_arrow()
100100
)
101101
table = table.cast(ibis.Schema.from_pyarrow(prev_schema))
102102
write_mode = "append"

0 commit comments

Comments
 (0)