Fabric RTI MCP 扩展

一个扩展的Microsoft Fabric实时智能(RTI)和Lakehouse环境的模型上下文协议(MCP)服务器,提供自定义的架构发现和直接数据查询功能。

  • by melisaluis
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 melisaluis/fabric-mcp

使用说明

结构RTI MCP(扩展)

此存储库是用于Microsoft Fabric实时智能(RTI)和Lakehouse环境的扩展模型上下文协议(MCP)服务器。它基于官方的Microsoft Fabric RTI MCP,添加了用于模式发现和直接数据查询的自定义功能,这些功能在官方的Microsoft版本中不可用。

与微软官方Fabric RTI MCP的主要区别

  • 模式和数据查询支持:与官方的Microsoft RTI MCP不同,该项目使代理能够在Fabric Lakehouse环境中直接查询表模式和数据。
  • 自定义扩展:已实施其他工具和端点,以支持高级数据探索、文档和分析场景。
  • 保持兼容性:保留所有原始RTI MCP功能(Eventhouse、Eventstreams、Activator、Map等),并在其上添加新功能。

特性

  • 将Fabric RTI和Lakehouse功能作为代理的MCP工具公开
  • 支持自然语言到SQL/KQL的转换,用于数据探索
  • 使用Azure身份进行安全身份验证
  • 对Eventhouse和Eventstreams的实时数据访问
  • 用于高级分析的查询历史、语义模型和模式工具

快速入门

  1. 安装Python 3.10+
  2. 克隆存储库:
    git clone https://github.com/melisa-l/fabric-rti-mcp.git
    cd fabric-rti-mcp
    
  3. 安装依赖项:
    pip install -r requirements.txt
    
  4. 设置环境变量:
    • FABRIC_SQL_ENDPOINT:您的结构SQL端点
    • FABRIC_LAKEHOUSE_NAME:您的Lakehouse数据库名称
    • (可选) FABRIC_RTI_MCP_TOKEN:用于HTTP API身份验证的承载令牌
  5. 运行MCP服务器:
    python -m fabric_rti_mcp.server
    

用法

  • 使用提供的工具列出表、获取模式、运行查询和分析Fabric Lakehouse(自定义扩展)中的关系。
  • 通过MCP HTTP API与人工智能代理或协调器集成。
  • 看 examples/ 脚本和使用模式目录。

贡献

欢迎投稿!请参阅CONTRIBUTING.md了解指导方针。

许可证

该项目根据MIT许可证获得许可。有关详细信息,请参阅许可证。

  }

示例提示

Eventhouse分析:


- "Sample 10 rows from table 'StormEvents' in Eventhouse"

See [QUICKSTART_GUIDE.md](QUICKSTART_GUIDE.md) for detailed setup instructions and [mcp.json](mcp.json) for a template configuration.- "What can you tell me about StormEvents data?"

- "Analyze the StormEvents to come up with trend analysis across past 10 years of data"

## Features- "Analyze the commands in 'CommandExecution' table and categorize them as low/medium/high risks"



**SQL Lakehouse Tools:****SQL Lakehouse Analytics:**

- `sql_list_lakehouse_tables` - List all tables in your Lakehouse- "What tables are in my SQL lakehouse?"

- `sql_get_table_schema` - Get detailed schema for any table- "Show me the schema of table 'MyTable' in the lakehouse"

- "List all tables and their columns in my lakehouse"

**Query History Tools:**

- `query_history_list` - View recent SQL queries**Eventstream Management:**

- `query_history_get` - Get details about specific query execution- "List all Eventstreams in my workspace"

- "Show me the details of my IoT data Eventstream"

## Example Prompts



- "What tables are in my lakehouse?"### Available tools 

- "Show me the schema of the customers table"

- "List all tables and their column types"#### SQL Lakehouse - 2 Tools:

- "What queries have been run recently?"- **`sql_list_lakehouse_tables`** - List all tables in a Fabric SQL lakehouse

- **`sql_get_table_schema`** - Get detailed schema information for a specific table in the lakehouse

## Configuration

#### Eventhouse (Kusto) - 12 Tools:

### Required Environment Variables- **`kusto_known_services`** - List all available Kusto services configured in the MCP

- **`kusto_query`** - Execute KQL queries on the specified database

| Variable | Description | Example |- **`kusto_command`** - Execute Kusto management commands (destructive operations)

|----------|-------------|---------|- **`kusto_list_databases`** - List all databases in the Kusto cluster

| `FABRIC_SQL_ENDPOINT` | Your Fabric SQL endpoint (without https://) | `workspace.datawarehouse.fabric.microsoft.com` |- **`kusto_list_tables`** - List all tables in a specified database

| `FABRIC_LAKEHOUSE_NAME` | Name of your lakehouse (case-sensitive) | `MyLakehouse` |- **`kusto_get_entities_schema`** - Get schema information for all entities (tables, materialized views, functions) in a database

- **`kusto_get_table_schema`** - Get detailed schema information for a specific table

### Optional Environment Variables- **`kusto_get_function_schema`** - Get schema information for a specific function, including parameters and output schema

- **`kusto_sample_table_data`** - Retrieve random sample records from a specified table

| Variable | Description | Default |- **`kusto_sample_function_data`** - Retrieve random sample records from the result of a function call

|----------|-------------|---------|- **`kusto_ingest_inline_into_table`** - Ingest inline CSV data into a specified table

| `FABRIC_API_BASE` | Fabric API base URL | `https://api.fabric.microsoft.com/v1` |- **`kusto_get_shots`** - Retrieve semantically similar query examples from a shots table using AI embeddings

| `FABRIC_BASE_URL` | Fabric web base URL | `https://fabric.microsoft.com` |

| `UV_LINK_MODE` | Set to `copy` to avoid OneDrive hardlink issues | - |#### Eventstreams - 6 Tools:

- **`list_eventstreams`** - List all Eventstreams in your Fabric workspace

## Authentication- **`get_eventstream`** - Get detailed information about a specific Eventstream

- **`get_eventstream_definition`** - Retrieve complete JSON definition of an Eventstream

Uses Azure Identity [`DefaultAzureCredential`](https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication/credential-chains?tabs=dac) for secure authentication.

## Getting Started

**Recommended: Azure CLI**

### Prerequisites

```bash1. Install either the stable or Insiders release of VS Code:

# Windows   * [ Stable release](https://code.visualstudio.com/download)

winget install Microsoft.AzureCLI   * [ Insiders release](https://code.visualstudio.com/insiders)

2. Install the [GitHub Copilot](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot) and [GitHub Copilot Chat](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot-chat) extensions

# macOS3. Install `uv`  

brew install azure-cli```ps

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

# Linux```  

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bashor, check here for [other install options](https://docs.astral.sh/uv/getting-started/installation/#__tabbed_1_2)



# Authenticate4. Open VS Code in an empty folder

az login

```## Installation



The MCP server will automatically use your cached Azure CLI credentials.### 🔧 Install from GitHub (Recommended for Development)  



## DevelopmentIf you want to use the latest version or contribute to development, you can install directly from the GitHub repository:



### Install from Source#### Quick Setup Steps:



```bash1. **Prerequisites**

git clone https://github.com/melisa-l/fabric-rti-mcp.git   - Python 3.10+ installed and added to PATH

cd fabric-rti-mcp   - `uv` package manager installed (see installation steps above)

pip install -e ".[dev]"   - VS Code with GitHub Copilot extensions

  1. 克隆仓库

在VS代码``bash中调试

克隆https://github.com/melisa-l/fabric-rti-mcp.git

  1. 使用开发依赖项进行安装: pip install -e ".[dev]" cd织物rti-mcp

  2. 配置环境变量(请参阅配置部分)```

  3. 附加调试器:

    • 跑 MCP: List Servers 在命令面板3中。 安装依赖项

    • 选择 fabric-lakehouse → Show Output ```bash

    • 注意PID pip安装-e。

    • 使用VS代码 Python: Attach 使用该PID进行配置```

    或使用紫外线:

🧪 测试bash

紫外线管道安装-e。

  1. 在VS代码中打开GitHub Copilot(代理模式)```

  2. 验证服务器是否出现在工具列表中

  3. 尝试提示:4。 配置VS代码

    • “列出我湖畔小屋中的所有桌子”将以下内容添加到您的 settings.json 或 mcp.json 文件:

    • “显示客户表的模式”-按 Ctrl+Shift+P 并搜索“首选项:打开用户设置(JSON)”

    • 在下面添加MCP服务器配置

📚 文件- 重要:更新 --directory 与克隆存储库的位置匹配的路径

安全{

   "mcp": {

您的凭据通过官方安全处理 Azure身份SDK我们从不直接存储或管理代币。“服务器”:{

           "fabric-rti-mcp": {

贡献“命令”:“uv”,

               "args": [

该项目欢迎各方提供意见和建议。大多数贡献都需要您同意贡献者许可协议(CLA)。有关详细信息,请访问https://cla.opensource.microsoft.com.“--目录”,

                   "C:/Users/YourUsername/fabric-rti-mcp/",

行为准则“运行”,

                   "-m",

该项目采用了 微软开源行为准则。有关更多信息,请参阅 行为准则常见问题 或联系 opencode@microsoft.com.“fabric_rti_mcp.server”

               ],

商标“env”:{

                   "FABRIC_SQL_ENDPOINT": "your-workspace-name.datawarehouse.fabric.microsoft.com",

此项目可能包含项目、产品或服务的商标或徽标。授权使用Microsoft商标或徽标必须遵守 微软商标和品牌指南“FABRIC_LAKEHOUSE_NAME”:“您的湖屋名称”

               }
           }
       }
   }

}


5. **Configure Environment Variables**
- **FABRIC_SQL_ENDPOINT** (Required): SQL endpoint for your Fabric lakehouse
  - Find: Fabric Portal → Lakehouse → SQL endpoint → Copy Server value
  - Format: `your-workspace-name.datawarehouse.fabric.microsoft.com`
- **FABRIC_LAKEHOUSE_NAME** (Required): Name of your lakehouse database

6. **Restart VS Code**
- Close and reopen VS Code for the MCP server to be recognized
- The server will automatically start when you use Copilot in Agent mode

#### Verify Installation:
1. Open GitHub Copilot Chat and switch to Agent mode
2. Type "@workspace /tools" to see available MCP tools
3. You should see tools from fabric-rti-mcp (SQL Lakehouse tools primarily)
4. Try a test query: "What tables are in my lakehouse?"

---

### Alternative: Install from PyPI (Pip)
The Fabric RTI MCP Server is also available on [PyPI](https://pypi.org/project/microsoft-fabric-rti-mcp/):

#### From VS Code
1. Open command palette (`Ctrl+Shift+P`) and run `MCP: Add Server`
2. Select "Install from Pip"
3. Enter package name: `microsoft-fabric-rti-mcp`
4. Follow the prompts to configure

The process will add these settings to your `settings.json`:

## Debugging the MCP Server locally
Assuming you have python installed and the repo cloned:

### Install locally
```bash
pip install -e ".[dev]"

配置

跟随 手动安装 说明。

附加调试器

使用 Python: Attach 您的配置 launch.json 连接到正在运行的服务器。 一旦VS Code拿起服务器并启动它,导航到它的输出:

  1. 打开命令面板(Ctrl+Shift+P)并运行命令 MCP: List Servers
  2. 导航到 fabric-rti-mcp 并选择 Show Output
  3. 从输出中获取服务器的进程ID(PID)
  4. 跑吧 Python: Attach 您的配置 launch.json 文件,并在提示中粘贴服务器的PID
  5. 调试器将附加到服务器进程,您可以开始调试

测试MCP服务器

  1. 在VS Code中打开GitHub Copilot 切换到代理模式
  2. 您应该在工具列表中看到结构RTI MCP服务器
  3. 尝试告诉代理使用Eventhouse工具的提示,例如“列出我的Kusto表”
  4. 代理应该能够使用结构RTI MCP服务器工具来完成您的查询

配置

MCP服务器可以使用以下环境变量进行配置:

所需的环境变量

变量 描述 示例
FABRIC_SQL_ENDPOINT 您的结构SQL端点(不带https://) workspace.datawarehouse.fabric.microsoft.com
FABRIC_LAKEHOUSE_NAME 您的lakehouse数据库名称(区分大小写) MyLakehouse

可选环境变量

变量 服务 描述 默认值 示例
FABRIC_API_BASE 全局 Microsoft Fabric API的基本URL https://api.fabric.microsoft.com/v1 https://api.fabric.microsoft.com/v1
FABRIC_BASE_URL 全局 Microsoft Fabric web界面的基本URL https://fabric.microsoft.com https://fabric.microsoft.com

嵌入端点配置

这 AZ_OPENAI_EMBEDDING_ENDPOINT 由语义搜索功能使用(例如。, kusto_get_shots 函数)以查找类似的查询示例。

格式要求:

https://{your-openai-resource}.openai.azure.com/openai/deployments/{deployment-name}/embeddings?api-version={api-version};impersonate

组件:

  • {your-openai-resource}:您的Azure OpenAI资源名称
  • {deployment-name}:您的文本嵌入部署名称(例如。, text-embedding-ada-002)
  • {api-version}:API版本(例如。, 2024-10-21, 2023-05-15)
  • ;impersonate:身份验证方法(您可以使用托管身份)

身份验证要求:

  • 您的Azure身份必须能够访问OpenAI资源
  • 如果使用托管身份,则必须将OpenAI资源配置为接受托管身份验证
  • 部署必须存在并且可访问

射击台配置

这 kusto_get_shots 该工具从快照表中检索与提示最相似的快照。此功能需要配置:

  • 射击桌:应该有一个包含自然语言提示的“EmbeddingText”(字符串)列、包含相应KQL的“AugmentedText”(string)列和包含EmbeddedText嵌入向量的“EmbeddedVector”(动态)列。
  • Azure OpenAI嵌入端点:用于为提示创建嵌入向量。请注意,此端点必须使用与在快照表中创建“EmbeddedVector”列时使用的模型相同的模型。

认证

MCP服务器通过以下方式使用Azure身份 DefaultAzureCredential 通过以下方式实现安全、无缝的身份验证 自动令牌缓存 以避免重复的身份验证提示。

身份验证方法(按优先级顺序):

  1. 环境变量 (EnvironmentCredential)-非常适合CI/CD管道
  2. 管理身份 (ManagedIdentityCredential)-适用于Azure托管部署
  3. Visual Studio Code (VisualStudioCodeCredential)-使用您的VS代码凭据
  4. Azure命令行界面 (AzureCliCredential) - ⭐ 推荐 -使用您现有的Azure CLI登录
  5. Azure PowerShell (AzurePowerShellCredential)-使用您的Az PowerShell登录
  6. Azure开发者命令行界面 (AzureDeveloperCliCredential)-使用您的azd登录
  7. 交互式浏览器 (InteractiveBrowserCredential)-如果需要,可以恢复基于浏览器的登录

推荐安装程序:Azure CLI(无重复的身份验证提示!)

这 Azure CLI方法提供最佳用户体验 使用自动令牌缓存:

安装Azure命令行界面:

窗户:

winget install Microsoft.AzureCLI

或从以下网址下载:https://aka.ms/installazurecliwindows

雨衣:

brew install azure-cli

Linux:

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

身份验证一次:

az login

就是这样! MCP服务器将自动将这些缓存的凭据用于所有查询。您永远不会被提示再次进行身份验证(除非令牌过期,令牌会自动刷新)。

令牌缓存的工作原理

  • 第一个请求:使用首选方法进行身份验证(建议使用Azure CLI)
  • 后续请求:自动重用缓存的令牌
  • 令牌过期:在后台自动刷新
  • 零提示:一旦通过身份验证,就不再有浏览器弹出窗口或登录请求!

替代方案:基于浏览器的身份验证

如果不安装Azure CLI,服务器将回退到交互式浏览器身份验证:

  • 第一个查询打开浏览器进行登录
  • 令牌已缓存用于会话
  • 可能需要偶尔重新验证

为了获得最流畅的体验,我们强烈建议使用Azure CLI!

MCP服务器的HTTP模式配置

当MCP服务器以HTTP模式在代理本地运行或部署到Azure时,以下环境变量用于定义和启用HTTP模式。您可以在 tests/live/test_kusto_tools_live_http.py 文件:

变量 描述 默认值 示例
FABRIC_RTI_TRANSPORT 服务器的传输模式 stdio http
FABRIC_RTI_HTTP_HOST HTTP服务器的主机地址 127.0.0.1 0.0.0.0
FABRIC_RTI_HTTP_PORT HTTP服务器端口 3000 8080
FABRIC_RTI_HTTP_PATH MCP端点的HTTP路径 /mcp /mcp
FABRIC_RTI_STATELESS_HTTP 是否使用无状态HTTP模式 false true

连接到服务器的HTTP客户端需要在请求标头中包含适当的身份验证令牌:

# Example from test_kusto_tools_live_http.py
auth_header = f"Bearer {token.token}"

headers = {
    "Content-Type": "application/json",
    "Accept": "application/json, text/event-stream",
    "Authorization": auth_header,
}

OBO流认证

如果您的场景涉及具有非Kusto受众的用户令牌,并且您需要使用OBO流将其交换为Kusto受众令牌,则结构RTI MCP服务器可以通过设置以下环境变量自动处理此交换:

变量 描述 默认值 示例
USE_OBO_FLOW 启用OBO流进行令牌交换 false true
FABRIC_RTI_MCP_AZURE_TENANT_ID 72f988bf-86f1-41af-91ab-2d7cd011db47 (微软) 72f988bf-86f1-41af-91ab-2d7cd011db47
FABRIC_RTI_MCP_ENTRA_APP_CLIENT_ID Entra应用程序(AAD)客户ID 您的客户ID
FABRIC_RTI_MCP_USER_MANAGED_IDENTITY_CLIENT_ID 用户管理身份客户端ID 您的UMI客户端ID

此流通常用于OAuth场景,其中涉及像Azure API管理(APIM)这样的网关(例如:https://github.com/ai-microsoft/adsmcp-apim-dual-validation?tab=readme-ov文件)。用户通过Entra ID进行身份验证,APIM将令牌转发给MCP服务器。令牌受众不是Kusto,因此MCP服务器必须执行OBO令牌交换,才能与Kusto受众获得令牌。 为了支持此设置,您的Microsoft Entra应用程序必须按照官方指南配置为使用联合凭据:https://learn.microsoft.com/en-us/entra/workload-id/workload-identity-federation.这使应用程序能够交换令牌(OBO)。 此外,Entra应用程序必须被授予Azure Data Explorer API权限,才能成功获得Kusto受众的海外建筑运营管理局令牌。

远程部署

MCP服务器可以使用您选择的方法进行部署。例如,您可以按照以下指南进行操作:https://github.com/Azure-Samples/mcp-sdk-functions-hosting-python/blob/main/ExistingServer.md将MCP服务器部署到Azure功能应用程序。

安全说明

您的凭据始终通过官方安全处理 Azure身份SDK - 我们从不直接存储或管理代币.

MCP作为一种现象是非常新颖和前沿的。与所有新技术标准一样,考虑进行安全审查,以确保与MCP服务器集成的任何系统都符合您的系统应遵守的所有法规和标准。这不仅包括Azure MCP服务器,还包括您选择实施到模型提供商的任何MCP客户端/代理。

贡献

该项目欢迎各方提供意见和建议。大多数捐款要求您同意 贡献者许可协议(CLA)声明您有权并实际授予我们 使用您贡献的权利。有关详细信息,请访问https://cla.opensource.microsoft.com.

当您提交拉取请求时,CLA机器人将自动确定您是否需要提供 CLA并适当地装饰PR(例如,状态检查、评论)。只需按照说明进行操作 由机器人提供。您只需使用我们的CLA在所有存储库中执行一次此操作。

行为准则

该项目采用了 微软开源行为准则. 有关更多信息,请参阅 行为准则常见问题 或 联系 opencode@microsoft.com 如有任何其他问题或意见。

数据收集

该软件可能会收集有关您和您使用该软件的信息,并将其发送给Microsoft。Microsoft可能会使用此信息提供服务并改进我们的产品和服务。您可以按照存储库中的说明关闭遥测。软件中还有一些功能,可以让您和Microsoft从应用程序的用户那里收集数据。如果您使用这些功能,则必须遵守适用法律,包括向您的应用程序用户提供适当的通知以及Microsoft隐私声明的副本。我们的隐私声明位于https://go.microsoft.com/fwlink/?LinkID=824704.您可以在帮助文档和我们的隐私声明中了解有关数据收集和使用的更多信息。您使用该软件即表示您同意这些做法。

商标

此项目可能包含项目、产品或服务的商标或徽标。授权使用Microsoft 商标或徽标必须遵守 微软商标和品牌指南. 在本项目的修改版本中使用Microsoft商标或徽标不得造成混淆或暗示Microsoft赞助。 任何使用第三方商标或徽标的行为均受这些第三方政策的约束。