week7-mcp-server
第7週 — MCP(エージェントに専用ツールを持たせる、標準的な方法)
分野全体がAIへとシフトする中で、自動化スキルを磨いていく旅の一部です。今週のテーマは Model Context Protocol (MCP) です。プロンプトにデータを貼り付ける代わりに、LLMには小さなツール群が手渡され、質問に答えるためにどのツールをどの順番で呼び出すかを、モデル自身が決定します。
今週が重要な理由: プロンプトにデータをハードコードするやり方は、デモを超えてはスケールしません。MCPは「ここにあなたのツールとデータソースがあります。あとはどうぞ」というための新たな標準であり、エージェントをスナップショットではなくライブなシステムに接続することを可能にします。
アーキテクチャ
[client.py asks a question]
|
v
[Claude sees 3 tool definitions — no invoice data in the prompt]
| decides which tools to call, with what arguments
v
[MCP server (server.py): list_invoices / get_invoice / get_purchase_order]
| returns live data over stdio
v
[Claude reasons over the results and answers]連続性: 第2週では文書から請求書を抽出しました。第6週では、ボットがすでに手にしていたデータを基に、請求書の例外をどう処理するかを決定しました。今週では、データ自体がMCPサーバーの背後に存在し、エージェントはデータを与えられるのではなく、自分自身で事実を取得します。これを第6週のポリシーガード付き判定サービスと組み合わせると、ロードマップ上のPortfolio Project #4、つまり情報を調べると同時に、判定を監査可能なルール層に委ねるエージェントが実現します。
Related MCP server: Invoice MCP Server
このリポジトリの内容
ファイル | 役割 |
| MCPサーバー — |
| サーバーを起動し、Claudeから直接操作する — 個別のサーバープロセスの起動は不要 |
| ツール関数の単体テスト — APIキーは不要 |
1. 実行する
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
# copy .env.example to .env and paste your key
python src/client.pyclient.pyはstdio経由でserver.py自体を起動します(これはローカルツールのMCPの標準的な動作であり、第6週とは異なりHTTPポートを管理する必要はありません)。Claudeが何を調べる必要があるかを判断する際に、[MCP tool call: ...]という行が表示されるのを確認してください。
ツールロジックの単体テストを実行します(APIキーは不要):
pytest2. 核となる設計アイデア: 標準プロトコルによるツールとデータ
MCP以前は、モデルにツールを与えるというのは、プロジェクトごとにJSONスキーマとディスパッチ用のif/elifを手作りすることを意味していました。MCPはそれを標準化します。server.pyは@mcp.tool()でツールを一度宣言し、任意の MCP対応クライアント(このリポジトリのclient.py、Claude Desktop、別のチームのエージェント)が同じ方法でツールを発見し呼び出せます。これが「エージェントを実際のツールに接続する」という提案です。ツール提供者とエージェントは、同じ人が作る必要はありません。
3. 学んだこと / 本番運用に対応しているかどうか
MCPは、データを所有する者とデータについて推論する者を分離します。サーバーが呼び出しているのはどのLLMでもよく、知る必要も、気にする必要もありません。
モデルの選択もここでは重要です。これは難しい判断ではなくオーケストレーション(どのツールを呼ぶかの決定)なので、安くて速いモデル(
claude-haiku-4-5)が正しい選択です。Opus相当の推論は、第6週が行うような判断のために取っておきましょう。本番運用には対応していません: 「ERP」はインメモリのdictであり、サーバーには認証も、実際のMCPリソースもありません(ツールのみ)。本番バージョンでは、請求書レコードをMCPリソースとしても公開するでしょう(第8週以降)。
技術スタック
Python · MCP(公式Python SDK) · Claude(ツール駆動にclaude-haiku-4-5) · Anthropic SDK · pytest
This server cannot be deployed
Maintenance
Related MCP Connectors
Read incoming supplier invoices through a remote MCP server and get structured data for accounting.
41Free hosted MCP for invoices, estimates, clients, items and PDFs. OAuth authorization required.
1Create and manage invoices and customers on Jupiter Invoice (MCP, API-key auth).
MCP server for Codat — companies, connections, invoices, bills and financial statements.
Related MCP Servers
- FlicenseBqualityDmaintenanceBridges to a simple_invoicing FastAPI backend, exposing invoice, product, ledger, inventory, buyer, and payment management as MCP tools for use with MCP-compatible clients.15-
- AlicenseNot gradedqualityDmaintenanceEnables invoice management through MCP, including customer, invoice, and report operations with CLI and web interfaces.MIT
- AlicenseAqualityCmaintenanceEnables AI agents to stamp, cancel, and query Mexican CFDI 4.0 invoices through MCP tools, with support for local stdio and hosted HTTP transport.4609 npmMIT
- AlicenseAqualityBmaintenanceEnables MCP clients such as Claude and Cursor to manage customers, create and update draft invoices, list or download invoices as PDF and XML e-invoices, and record and list payments in a BillingEngine account. It runs locally with your API key and never deletes data.1063 npmMIT