数据存储MCP服务器
提供对Google Cloud数据存储访问的模型上下文协议(MCP)服务器。该服务器使Claude等AI助手能够与Datastore实体交互、执行查询和管理数据。
特性
- 实体运营:创建、读取、更新和删除数据存储实体
- 查询支持:使用筛选器、排序和分页执行查询
- 命名空间支持:使用不同的数据存储命名空间
- 仿真器支持:默认情况下连接到本地Datastore仿真器进行开发
- 生产就绪:轻松配置生产环境中的Google Cloud数据存储
安装
先决条件
选项1:Docker(推荐)
- Docker引擎20.10+
- Docker Compose v2.0+
选项2:本地Python
- Python 3.10或更高版本
- 谷歌云数据存储模拟器(用于本地开发)或谷歌云项目(用于生产)
从源代码安装
# Clone the repository
git clone
cd datastore-mcp
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -e .使用紫外线(推荐)
# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .使用Docker(推荐用于测试)
Docker提供了一个隔离的环境,预先配置了Datastore仿真器和MCP服务器。
# Run tests
make test
# Start all services (emulator + server)
make up
# View logs
make logs
# Stop services
make down有关Docker的详细文档,请参阅 医生.md.
配置
可以使用环境变量或命令行参数配置服务器。
环境变量
对于模拟器:
DATASTORE_DATASET-数据集名称(默认值:test)DATASTORE_EMULATOR_HOST-数据存储模拟器主机(默认值:localhost:8081)DATASTORE_EMULATOR_HOST_PATH-仿真器主机路径(默认值:localhost:8081/datastore)DATASTORE_HOST-数据存储HTTP主机(默认值:http://localhost:8081)DATASTORE_PROJECT_ID-Google Cloud项目ID(默认值:test)DATASTORE_NAMESPACE-默认命名空间(可选)
生产:
DATASTORE_PROJECT_ID-谷歌云项目ID(必填)GOOGLE_APPLICATION_CREDENTIALS-服务帐户密钥文件的路径(必需)DATASTORE_NAMESPACE-默认命名空间(可选)
使用数据存储仿真器运行(默认)
# Start the Datastore emulator (in a separate terminal)
gcloud beta emulators datastore start --host-port=localhost:8081
# Run the MCP server (uses emulator by default)
python src/datastore_mcp/server.py
# Or with custom emulator host
DATASTORE_EMULATOR_HOST=localhost:9090 python src/datastore_mcp/server.py使用生产数据存储运行
# Set credentials and project
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account-key.json
export DATASTORE_PROJECT_ID=your-gcp-project-id
# Unset emulator host to use production
unset DATASTORE_EMULATOR_HOST
# Run the server
python src/datastore_mcp/server.py使用Claude Desktop
将此配置添加到您的Claude Desktop配置文件中:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%/Claude/claude_desktop_config.json
用于仿真器(开发)
{
"mcpServers": {
"datastore": {
"command": "python",
"args": ["/path/to/datastore-mcp/src/datastore_mcp/server.py"],
"env": {
"DATASTORE_DATASET": "test",
"DATASTORE_EMULATOR_HOST": "localhost:8081",
"DATASTORE_EMULATOR_HOST_PATH": "localhost:8081/datastore",
"DATASTORE_HOST": "http://localhost:8081",
"DATASTORE_PROJECT_ID": "test"
}
}
}
}用于生产
{
"mcpServers": {
"datastore": {
"command": "python",
"args": ["/path/to/datastore-mcp/src/datastore_mcp/server.py"],
"env": {
"DATASTORE_PROJECT_ID": "your-gcp-project-id",
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service-account-key.json"
}
}
}
}在Claude Desktop上使用Docker(推荐)
选项1:全自动(仿真器+服务器)
使用提供的包装器脚本(包含在存储库中):
MacOS/Linux: start-datastore-mcp.sh 视窗: start-datastore-mcp.bat
然后配置Claude Desktop:
MacOS/Linux:
{
"mcpServers": {
"datastore": {
"command": "/path/to/datastore-mcp/start-datastore-mcp.sh"
}
}
}视窗:
{
"mcpServers": {
"datastore": {
"command": "C:\\path\\to\\datastore-mcp\\start-datastore-mcp.bat"
}
}
}如果模拟器未运行,此选项会自动启动模拟器,并在启动MCP服务器之前等待其正常运行。
选项2:手动启动模拟器
首先,启动Datastore模拟器一次:
cd /path/to/datastore-mcp
make emulator-only # Keeps running in background然后配置Claude Desktop:
{
"mcpServers": {
"datastore": {
"command": "docker",
"args": [
"compose",
"-f",
"/path/to/datastore-mcp/docker-compose.yml",
"run",
"--rm",
"mcp-server"
]
}
}
}选项3:外部仿真器(自定义IP)
如果您的模拟器在不同的机器或自定义IP上运行:
{
"mcpServers": {
"datastore": {
"command": "docker",
"args": [
"compose",
"-f",
"/path/to/datastore-mcp/docker-compose.yml",
"run",
"--rm",
"-e", "DATASTORE_EMULATOR_HOST=localhost:8081",
"-e", "DATASTORE_EMULATOR_HOST_PATH=localhost:8081/datastore",
"-e", "DATASTORE_HOST=http://localhost:8081",
"mcp-server"
]
}
}
}在Claude Desktop中使用uv
{
"mcpServers": {
"datastore": {
"command": "uv",
"args": [
"--directory",
"/path/to/datastore-mcp",
"run",
"datastore-mcp"
],
"env": {
"DATASTORE_DATASET": "test",
"DATASTORE_EMULATOR_HOST": "localhost:8081",
"DATASTORE_EMULATOR_HOST_PATH": "localhost:8081/datastore",
"DATASTORE_HOST": "http://localhost:8081",
"DATASTORE_PROJECT_ID": "test"
}
}
}
}可用工具
连接后,Claude可以使用以下工具:
datastore_get-按键检索实体datastore_put-创建或更新实体datastore_delete-删除实体datastore_query-使用筛选器和排序查询实体datastore_batch_get-按键检索多个实体datastore_list_kinds-列出命名空间中的所有实体类型
查询示例
请克劳德:
- “获取ID为12345的用户实体”
- “按名称查询价格>100的所有产品”
- “创建一个具有标题和内容的新BlogPost实体”
- “删除ID为abc123的注释实体”
- “列出我的数据存储中的所有实体类型”
发展
使用Docker(推荐)
# Run tests
make test
# Run tests with coverage
docker-compose run --rm test
# Start emulator only for local development
make emulator-only
# Interactive shell in container
make shell使用本地Python
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=src/datastore_mcp --cov-report=term-missing
# Run the server
python src/datastore_mcp/server.py项目结构
datastore-mcp/
├── src/
│ └── datastore_mcp/
│ ├── server.py # Main MCP server
│ ├── datastore.py # Datastore client wrapper
│ └── tools.py # Tool implementations
├── tests/
│ └── test_tools.py
├── pyproject.toml
└── README.md许可证
MIT许可证
贡献
欢迎投稿!请打开问题或提交拉取请求。
