PydanticAI 에이전트를 ClickHouse MCP 서버로 빌드하기
PydanticAI 에이전트를 ClickHouse MCP 서버로 빌드하기
이 가이드에서는 PydanticAI 에이전트를 만들어 ClickHouse의 SQL 플레이그라운드와 ClickHouse의 MCP 서버로 상호작용하도록 하는 방법을 배워요.
출처: 문서
본문
이 예제는 examples 저장소에서 노트북으로 확인할 수 있어요.
준비 사항 (Prerequisites)
- 시스템에 Python이 설치되어 있어야 해요.
- 시스템에
pip이 설치되어 있어야 해요. - Anthropic API 키 또는 다른 LLM 제공자의 API 키가 필요해요.
다음 절차는 Python REPL이나 스크립트로 실행할 수 있어요.
1. 라이브러리 설치
다음 명령을 실행해 필요한 라이브러리를 설치해요.
pip install -q --upgrade pip
pip install -q "pydantic-ai-slim[mcp]"
pip install -q "pydantic-ai-slim[anthropic]" # replace with the appropriate package if using a different LLM provider
2. 자격 증명 설정
다음으로 Anthropic API 키를 제공해야 해요.
import os, getpass
os.environ["ANTHROPIC_API_KEY"] = getpass.getpass("Enter Anthropic API Key:")
출력 결과:
Enter Anthropic API Key: ········
다른 LLM 제공자 사용하기 Anthropic API 키가 없고 다른 LLM 제공자를 사용하고 싶다면, PydanticAI 문서에서 자격 증명 설정 방법을 확인할 수 있어요.
다음으로 ClickHouse SQL 플레이그라운드에 연결하는 데 필요한 자격 증명을 정의해요.
env = {
"CLICKHOUSE_HOST": "sql-clickhouse.clickhouse.com",
"CLICKHOUSE_PORT": "8443",
"CLICKHOUSE_USER": "demo",
"CLICKHOUSE_PASSWORD": "",
"CLICKHOUSE_SECURE": "true"
}
3. MCP 서버와 PydanticAI 에이전트 초기화
이제 ClickHouse MCP 서버를 ClickHouse SQL 플레이그라운드를 가리키도록 설정해요.
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStdio
from pydantic_ai.messages import ToolCallPart, ToolReturnPart
server = MCPServerStdio(
'uv',
args=[
'run',
'--with', 'mcp-clickhouse',
'--python', '3.13',
'mcp-clickhouse'
],
env=env
)
agent = Agent('anthropic:claude-sonnet-4-0', mcp_servers=[server])
4. 에이전트에게 질문하기
마지막으로 에이전트에게 질문할 수 있어요.
async with agent.run_mcp_servers():
result = await agent.run("Who's done the most PRs for ClickHouse?")
print(result.output)
다음과 같은 응답을 받을 거예요.
Based on the data from the ClickHouse GitHub repository, here are the top contributors by number of pull requests created:
**Top contributors to ClickHouse by PRs opened:**
1. **alexey-milovidov** - 3,370 PRs opened
2. **azat** - 1,905 PRs opened
3. **rschu1ze** - 979 PRs opened
4. **alesapin** - 947 PRs opened
5. **tavplubix** - 896 PRs opened
6. **kssenii** - 871 PRs opened
7. **Avogar** - 805 PRs opened
8. **KochetovNicolai** - 700 PRs opened
9. **Algunenano** - 658 PRs opened
10. **kitaisreal** - 630 PRs opened
**Alexey Milovidov** stands out as by far the most active contributor with over 3,370 pull requests opened, which is significantly more than any other contributor. This makes sense as Alexey Milovidov is one of the founders and lead developers of ClickHouse.
The data also shows that alexey-milovidov has been very active in managing PRs, with 12,818 "closed" events (likely reviewing and closing PRs from other contributors) in addition to creating his own PRs.
It's worth noting that I filtered out various robot/bot accounts that handle automated processes, focusing on human contributors to give you the most meaningful answer about who has contributed the most PRs to ClickHouse.