ClickHouse MCP Server를 사용해 SlackBot 에이전트를 구축하는 방법
이 가이드에서는 SlackBot 에이전트를 구축하는 방법을 안내합니다. 이 봇을 사용하면 자연어로 Slack에서 ClickHouse 데이터에 대해 직접 질문할 수 있습니다. 이 봇은 ClickHouse MCP Server와 PydanticAI를 사용합니다.
이 예시의 코드는 examples 저장소에서 확인할 수 있습니다.
사전 요구 사항
uv가 설치되어 있어야 합니다- Slack 워크스페이스 접근 권한이 필요합니다
- Anthropic API 키 또는 다른 LLM 제공업체의 API 키가 필요합니다
Slack 앱 만들기
- slack.com/apps로 이동한 뒤
Create New App을 클릭합니다. From scratch옵션을 선택하고 앱 이름을 지정합니다.- Slack 워크스페이스를 선택합니다.
워크스페이스에 앱 설치하기
다음으로, 이전 단계에서 생성한 앱을 워크스페이스에 추가해야 합니다. 자세한 내용은 Slack 문서의 "Slack 워크스페이스에 앱 추가하기" 지침을 참고하십시오.
Slack 앱 설정 구성
App Home으로 이동합니다.Show Tabs→Messages Tab에서Allow users to send Slash commands and messages from the messages tab을 활성화합니다.Socket Mode로 이동합니다.Socket Mode를 활성화합니다.- 환경 변수
SLACK_APP_TOKEN에 사용할Socket Mode Handler값을 기록해 둡니다.
OAuth & Permissions로 이동합니다.- 다음
Bot Token Scopes를 추가합니다.app_mentions:readassistant:writechat:writeim:historyim:readim:writechannels:history
- 앱을 워크스페이스에 설치한 후, 환경 변수
SLACK_BOT_TOKEN에 사용할Bot User OAuth Token값을 기록해 둡니다.
- 다음
Event Subscriptions로 이동합니다.Events를 활성화합니다.Subscribe to bot events에서 다음 이벤트를 추가합니다.app_mentionassistant_thread_startedmessage:im
- 변경 사항을 저장합니다.
환경 변수 추가 (.env)
프로젝트 루트 디렉터리에 다음 환경 변수를 포함한 .env 파일을 생성합니다.
이 변수들은 애플리케이션이 ClickHouse SQL playground에 연결하도록 합니다.
원하는 경우 ClickHouse 관련 변수를 수정하여 자체 ClickHouse 서버나 Cloud 인스턴스를 사용하도록 설정할 수 있습니다.
Using the bot
-
Start the bot:
-
Slack에서:
- 채널에서 봇을 멘션하세요:
@yourbot Who are the top contributors to the ClickHouse git repo? - 스레드에서 멘션과 함께 답장하세요:
@yourbot how many contributions did these users make last week? - 봇에게 DM을 보내세요:
Show me all tables in the demo database.
- 채널에서 봇을 멘션하세요:
The bot will reply in the thread, using all previous thread messages as context if applicable.
Thread Context: When replying in a thread, the bot loads all previous messages (except the current one) and includes them as context for the AI.
Tool Usage: The bot uses only the tools available via MCP (e.g., schema discovery, SQL execution) and will always show the SQL used and a summary of how the answer was found.