mcpField
P
pydantic-mcp

pydantic-mcp

github.com/rectalogicフレームワーク・SDK983 週間前に更新

pydantic-mcp について

pydantic-mcpは、MCPサーバーのツールをPydantic AIのツールインスタンスに変換するライブラリです。READMEでは、MCPサーバー対応が組み込まれたPydanticAIの利用を推奨しています。

主な機能

  1. 01MCPツールをPydantic AIに読み込む
  2. 02MCP ClientSession経由でツールを利用

活用シーン

  1. 01Pydantic AIからMCPサーバーのツールを利用
  2. 02付属のファイル読み取りデモを実行

MCP 対応

MCP ClientSessionで接続し、対応ツールを取得してpydantic_ai.Toolインスタンスとして提供します。

詳細

pydantic-mcp

PydanticAI は現在 MCP サーバー のサポートを含んでいます。代わりにそちらを使用してください

PyPI - Version

Model Context Protocol の Pydantic AI ツール呼び出しサポート。

mcp.ClientSession を作成して tools = await mcptools(session) を呼び出すだけで、サポートされているツールの pydantic_ai.Tool インスタンスのリストを取得できます。

例:

https://github.com/rectalogic/pydantic-mcp/blob/98c4e9abf31837cb48ebeb3eae6cb55b16c841e8/tests/demo.py#L15-L25

デモ

Groq の llama-3.1-8b-instant に対してデモを実行できます:

$ export GROQ_API_KEY=xxx
$ uv run tests/demo.py "Read and summarize the file ./LICENSE"
Secure MCP Filesystem Server running on stdio
Allowed directories: [ '/users/aw/projects/rectalogic/pydantic-mcp' ]
The file ./LICENSE is a MIT License agreement. It states that the software is provided "as is" without warranty and that the authors and copyright holders are not liable for any claims, damages, or other liability arising from the software or its use.

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。