使用说明
Tableau MCP服务器
一个模型上下文协议(MCP)服务器,使Claude Desktop能够与Tableau server交互。上传数据集、检查数据源以及将Excel文件转换为Tableau Hyper格式,所有这些都可以通过自然语言完成。
特性
- 上传数据集:将数据源发布到Tableau Server
- 检查数据集:验证您的Tableau项目中是否存在数据集
- Excel到Hyper转换:将Excel文件(.xlsx、.xls、.xlsm、.xlsb)转换为Tableau Hyper格式
先决条件
- Python 3.10或更高版本
- Claude桌面应用程序
- 带有个人访问令牌(PAT)的Tableau服务器
- Windows、macOS或Linux
安装
1.克隆存储库
git clone https://github.com/samiribrh/tableau-mcp.git
cd tableau-mcp
2.安装依赖项
此项目使用 诗歌 用于依赖性管理。
# Install Poetry if you haven't already
curl -sSL https://install.python-poetry.org | python3 -
# Install project dependencies
poetry install
或者使用pip手动安装:
pip install mcp tableauserverclient pantab pandas python-dotenv openpyxl
3.配置环境变量
创建一个 .env 项目根目录中的文件:
# Tableau Server Configuration
TABLEAU_SERVER=https://your-tableau-server.com
TABLEAU_SITE_ID=your-site-id
TABLEAU_PAT_NAME=your-pat-name
TABLEAU_PAT_SECRET=your-pat-secret
TABLEAU_PROJECT_NAME=Sales
# Optional: Default file directory
DEFAULT_FILE_DIRECTORY=C:\Users\YourUsername\Downloads
如何获取Tableau PAT:
- 登录Tableau服务器
- 单击您的个人资料图标→ 我的帐户设置
- 滚动到 个人访问令牌
- 点击 创建新令牌
- 输入令牌名称并单击 创建
- 复制令牌密钥(您将不会再看到它!)
4.配置克劳德桌面
视窗
打开或创建: %APPDATA%\Claude\claude_desktop_config.json
使用诗歌:
{
"mcpServers": {
"tableau-mcp": {
"command": "poetry",
"args": [
"run",
"python",
"main.py"
],
"cwd": "C:\\path\\to\\tableau-mcp"
}
}
}
直接使用Python:
{
"mcpServers": {
"tableau-mcp": {
"command": "C:\\Python313\\python.exe",
"args": [
"C:\\path\\to\\tableau-mcp\\main.py"
],
"cwd": "C:\\path\\to\\tableau-mcp"
}
}
}
macOS/Linux
打开或创建: ~/Library/Application Support/Claude/claude_desktop_config.json
使用诗歌:
{
"mcpServers": {
"tableau-mcp": {
"command": "poetry",
"args": [
"run",
"python",
"main.py"
],
"cwd": "/path/to/tableau-mcp"
}
}
}
直接使用Python:
{
"mcpServers": {
"tableau-mcp": {
"command": "/usr/local/bin/python3",
"args": [
"/path/to/tableau-mcp/main.py"
],
"cwd": "/path/to/tableau-mcp"
}
}
}
5.重新启动克劳德桌面
完全关闭并重新打开Claude Desktop以使更改生效。
用法
配置后,您可以在Claude Desktop中通过自然语言与Tableau交互:
将Excel转换为Hyper
"Convert sales_data to hyper format"
→ Finds sales_data.xlsx in Downloads and converts to sales_data.hyper
"Convert Q4_report.xlsx to hyper"
→ Converts the specific file to Hyper format
"Convert C:\Documents\data.xlsx to output.hyper"
→ Converts with custom output path
上传数据集
"Upload revenue.hyper to Tableau"
→ Uploads to default project (from .env)
"Upload customer_data.hyper to Marketing project"
→ Uploads to specific project
"Upload C:\Reports\sales.hyper to Sales project"
→ Upload from custom path
检查数据集
"Check if sales_data exists in Tableau"
→ Checks in default project
"Does customer_report exist in the Marketing project?"
→ Checks specific project
组合工作流
"Convert monthly_sales to hyper and upload it to the Finance project"
→ Converts Excel file and uploads in one go
项目结构
tableau-mcp/
├── main.py # MCP server entry point
├── mcp_server.py # Tool definitions and handlers
├── tableau_api.py # Tableau Server API interactions
├── config.py # Configuration management
├── utils.py # Helper utilities
├── .env # Environment variables (create this)
├── pyproject.toml # Poetry dependencies
├── poetry.lock # Locked dependencies
└── README.md # This file
可用工具
1. convert_excel_to_hyper
将Excel文件转换为Tableau Hyper格式。
参数:
excel_file_path(必填):Excel文件的路径(带或不带扩展名)hyper_file_path(可选):hyper文件的输出路径
支持的格式: .xlsx, .xls, .xlsm, .xlsb
2. upload_dataset
将数据集上传到Tableau Server。
参数:
file_path(必填):要上传的文件的路径tableau_project(可选):目标项目名称
3. check_dataset
检查Tableau Server上是否存在数据集。
参数:
dataset_name(必填):数据集的名称tableau_project(可选):要登记的项目
配置选项
环境变量
| 变量 | 描述 | 默认值 | 必填 |
|---|---|---|---|
TABLEAU_SERVER |
Tableau服务器URL | - | 是 |
TABLEAU_SITE_ID |
站点标识符 | '' |
没有 |
TABLEAU_PAT_NAME |
个人访问令牌名称 | - | 是 |
TABLEAU_PAT_SECRET |
个人访问令牌机密 | - | 是 |
TABLEAU_PROJECT_NAME |
默认项目名称 | Sales |
没有 |
DEFAULT_FILE_DIRECTORY |
默认文件位置 | 用户下载 | 否 |
故障排除
服务器未出现在Claude桌面中
- 检查配置文件位置:确保你编辑的是正确的
claude_desktop_config.json - 验证Python路径:确保Python可执行文件路径正确
- 检查文件路径:在配置中使用绝对路径
- 完全重新启动:从任务管理器/活动监视器关闭Claude桌面
- 检查日志:往里看
%APPDATA%\Claude\logs\(Windows)或~/Library/Logs/Claude/(macOS)
未找到模块错误
# Ensure all dependencies are installed with Poetry
poetry install
# Or add a specific package
poetry add package-name
# If using pip directly
pip install mcp tableauserverclient pantab pandas python-dotenv openpyxl
Tableau连接问题
- 验证PAT凭据:使用Tableau服务器客户端手动测试
- 检查服务器URL:必须包括
https:// - 验证站点ID:默认站点留空
- 网络接入:确保您可以访问Tableau Server
找不到文件错误
- 检查默认目录:验证
DEFAULT_FILE_DIRECTORY在.env - 使用绝对路径:如果相对路径不起作用,请提供完整路径
- 检查文件扩展名:确保Excel文件具有适当的扩展名
发展
添加新工具
- 添加功能
tableau_api.py - 将工具定义添加到
get_tool_definitions()在mcp_server.py - 添加处理函数
_handle_your_tool()在mcp_server.py - 路线进入
handle_tool_call()在mcp_server.py
例子:
# In tableau_api.py
def your_new_function(param1, param2):
# Implementation
pass
# In mcp_server.py - get_tool_definitions()
Tool(
name="your_tool",
description="Description of what it does",
inputSchema={
"type": "object",
"properties": {
"param1": {"type": "string", "description": "..."}
},
"required": ["param1"]
}
)
# In mcp_server.py - handle_tool_call()
elif name == "your_tool":
result = _handle_your_tool(arguments)
运行测试
# Test the server manually with Poetry
poetry run python main.py
# Then send a JSON-RPC request via stdin
# Test Tableau connection
poetry run python -c "from tableau_api import connect_tableau; connect_tableau()"
# Add development dependencies
poetry add --group dev pytest pytest-asyncio
# Run tests (if you create them)
poetry run pytest
贡献
欢迎投稿!拜托:
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
致谢
- 内置 模型上下文协议(MCP)
- 用途 Tableau服务器客户端
- 由...驱动 皮疹。 用于超转换
支持
更新日志
v1.0.0(2024-11-07)
- 初始版本
- Excel到Hyper的转换
- 数据集上传功能
- 数据集存在性检查