MCP
MCP
MCP는 provider-adaptive 캐퍼빌리티이며 Pydantic AI에서 MCP의 주요 진입점이에요. 기본적으로 MCP 서버를 로컬로 실행해서 자격 증명·훅·트레이싱을 여러분의 통제 하에 두고, URL 기반 서버와 직접 클라이언트/툴셋/트랜스포트 입력을 모두 지원합니다.
출처: 문서
본문
네이티브 측은 MCPServerTool로 뒷받침됩니다 (공급자 지원과 설정은 MCP Server Tool 참고) — 캐퍼빌리티가 유도하는 것과 다른 id, authorization_token, description이 필요하면 native=MCPServerTool(...)을 직접 전달하세요. 로컬 측의 local=은 MCPToolset 입력(URL, fastmcp.Client, 트랜스포트, 인프로세스 FastMCP 서버, 스크립트 경로 등)을 받으며, 툴셋이 아닌 입력은 자동으로 MCPToolset에 감싸입니다.
from pydantic_ai.capabilities import MCP
from pydantic_ai.native_tools import MCPServerTool
# URL-based MCP server, running locally (requires `pydantic-ai-slim[mcp]`)
MCP('https://mcp.example.com/api')
# Local client without a URL -- pass any `MCPToolset` input
# (URL, `fastmcp.Client`, transport, in-process `FastMCP` server, script path, etc.)
MCP(local=my_fastmcp_client)
# Native preferred; URL-based local fallback
MCP('https://mcp.example.com/api', native=True)
# Strict native-only (no local -- does not require the `mcp` extra)
MCP('https://mcp.example.com/api', native=True, local=False)
# Explicit native + explicit local -- independent configuration on each side
# (e.g. provider-relay URL for native, direct connection for local)
MCP(
native=MCPServerTool(
id='public-mcp',
url='https://relay.example.com/mcp',
authorization_token='relay-token',
),
local=my_fastmcp_client,
)
더 낮은 수준의 접근 — MCPToolset 라이프사이클 직접 관리, 고급 트랜스포트/클라이언트 설정, 캐퍼빌리티를 통하지 않고 MCP 서버 사용 —이 필요하다면 MCP 문서를 보세요.