Berghain 活动 API 和 MCP 实施
项目结构
要求
Python 3.10+
uv(用于依赖管理和虚拟环境)
AWS 账户(用于 DynamoDB 和 App Runner)
Firecrawl API 密钥
设施
克隆此存储库:
git clone <repository-url> cd berghain-api使用
uv
创建并激活虚拟环境:uv venv source .venv/bin/activate # En Linux/macOS # .venv\\Scripts\\activate # En Windows使用
uv
安装依赖项:uv pip install -r requirements.txt
详细流程
1. 使用 Firecrawl 提取数据
**将 Firecrawl MCP 设置为 Cursor:**确保您拥有 Firecrawl API 密钥。在 Cursor MCPs 配置中,添加:
"firecrawl-mcp": { "command": "npx", "args": [ "-y", "firecrawl-mcp" ], "env": { "FIRECRAWL_API_KEY": "fc-YOUR_FIRECRAWL_API_KEY" } }**运行提取:**使用 Cursor 中的代理(或类似工具)调用 Firecrawl MCP 并要求它从
https://www.berghain.berlin/en/program/
中提取事件。**保存数据:**提取的数据应保存为
events/
目录中的 JSON 文件。例如,events/berghain_events_YYYY-MM-DD.json
。
2.将数据加载到 DynamoDB
在 DynamoDB 中创建表:
scripts/create_table.py
脚本负责处理此事。运行它(如有必要,调整参数):uv run python scripts/create_table.py --table berghain_events --region tu-region-aws # Para desarrollo local con DynamoDB Local (ej. docker run -p 8000:8000 amazon/dynamodb-local): # uv run python scripts/create_table.py --table berghain_events --region localhost --endpoint-url http://localhost:8000将数据加载到表中:
scripts/load_data.py
脚本从 JSON 文件加载事件。uv run python scripts/load_data.py --table berghain_events --region tu-region-aws --path events # Para desarrollo local: # uv run python scripts/load_data.py --table berghain_events --region localhost --endpoint-url http://localhost:8000 --path events如果您不将配置作为参数传递,请确保
app/core/config.py
(由load_data.py
导入)具有必要的配置。
3. 使用 FastAPI 和 MCP 服务器的 API
API 逻辑位于
app/
目录中,并定义了端点(例如,在app/api/endpoints/events.py
中)。app/main.py
文件配置为启动 FastAPI 应用程序和 FastMCP 服务器,将 API 端点公开为 AI 模型的工具。检查app/main.py
中的custom_maps
以查看 GET 路由如何映射到RouteType.TOOL
。
在 AWS 上部署
到。 Dockerfile
确保您的Dockerfile
已正确配置以使用uv
并运行app/main.py
:
b.构建并上传图像至 Amazon ECR(弹性容器注册表)
使用 ECR 对 Docker 进行身份验证:
aws ecr get-login-password --region tu-region-aws | docker login --username AWS --password-stdin tu-aws-account-id.dkr.ecr.tu-region-aws.amazonaws.com在 ECR 中创建一个存储库(如果不存在):
aws ecr create-repository --repository-name berghain-mcp-api --region tu-region-aws构建你的 Docker 镜像:
docker build -t berghain-mcp-api .标记您的图像:
docker tag berghain-mcp-api:latest tu-aws-account-id.dkr.ecr.tu-region-aws.amazonaws.com/berghain-mcp-api:latest将图像上传到 ECR:
docker push tu-aws-account-id.dkr.ecr.tu-region-aws.amazonaws.com/berghain-mcp-api:latest将
tu-region-aws
和tu-aws-account-id
替换为您的值。
c.使用 Terraform 部署基础设施
**准备您的 Terraform 文件:**确保您的 Terraform 配置文件(例如
main.tf
、variables.tf
、outputs.tf
)位于目录(例如terraform/
)中。这些文件应该定义必要的 AWS 资源,例如 ECR 映像将使用的 AWS App Runner 服务,以及 DynamoDB 表(如果 Terraform 也管理它)。 Terraform 中的 App Runner 配置将需要引用上传到 ECR 的图像。导航到 Terraform 目录:
cd terraform初始化 Terraform:
terraform init应用 Terraform 配置:
terraform apply审查计划并确认申请。 Terraform 将提供资源。
**获取服务 URL:**一旦应用,Terraform 应该显示定义的输出,包括 App Runner 服务 URL。记下此 URL(例如
https://<id-servicio>.<region>.awsapprunner.com
)。
测试已部署的解决方案
到。调整本地测试脚本( mcp_local.py
)
将mcp_local.py
文件设置为项目的根目录
**重要提示:**使用您从 Terraform 输出中获得的 URL 更新mcp_local.py
中的mcp_server_url
变量。
b.运行测试
从项目的根目录(或保存mcp_local.py
任何位置):
这将运行 PydanticAI 代理,它将尝试连接到您部署的 MCP 并执行查询。
执照
麻省理工学院
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
该服务器允许 AI 代理通过 DynamoDB 支持的 FastAPI 服务查询和检索有关 Berghain 夜总会即将举行的活动的信息。
Related MCP Servers
- AsecurityFlicenseAqualityThis server integrates with the Ticketmaster API to provide AI agents with real-time concert and event data, enabling dynamic fetching and formatting for ease of interpretation.Last updated -12
- AsecurityAlicenseAqualityThis server provides tools for AI assistants to interact with the Eventbrite API, allowing users to search for events, get event details, retrieve venue information, and list event categories.
- -securityAlicense-qualityIntegrates with the Eventbrite API to provide AI-assisted event management capabilities for viewing events, tracking attendees, and generating analytics reports.Last updated -01MIT License
- -securityAlicense-qualityA powerful server that enables AI agents to interact with MySQL databases, execute SQL queries, and manage database content through a simple interface.Last updated -4396MIT License