Skip to content

Instantly share code, notes, and snippets.

@ytyng
Created August 6, 2025 12:00
Show Gist options
  • Save ytyng/0a502946882530da0b149557eaf9fdf9 to your computer and use it in GitHub Desktop.
Save ytyng/0a502946882530da0b149557eaf9fdf9 to your computer and use it in GitHub Desktop.
MCP Agent の finder_agent.py を動かしてみた!設定ファイルの修正方法とつまづきポイントを解説
#!/usr/bin/env python3
import asyncio
import os
from mcp_agent.app import MCPApp
from mcp_agent.agents.agent import Agent
from mcp_agent.workflows.llm.augmented_llm_openai import OpenAIAugmentedLLM
app = MCPApp(name="hello_world_agent")
async def example_usage():
async with app.run() as mcp_agent_app:
logger = mcp_agent_app.logger
# This agent can read the filesystem or fetch URLs
finder_agent = Agent(
name="finder",
instruction="""You can read local files or fetch URLs.
Return the requested information when asked.""",
server_names=[
"fetch",
"filesystem",
], # MCP servers this Agent can use
)
async with finder_agent:
# Automatically initializes the MCP servers and adds their tools for LLM use
tools = await finder_agent.list_tools()
logger.info(f"Tools available:", data=tools)
# Attach an OpenAI LLM to the agent (defaults to GPT-4o)
llm = await finder_agent.attach_llm(OpenAIAugmentedLLM)
# This will perform a file lookup and read using the filesystem server
result = await llm.generate_str(
message="Show me what's in README.md verbatim"
)
logger.info(f"README.md contents: {result}")
# Uses the fetch server to fetch the content from URL
result = await llm.generate_str(
message="Print the first two paragraphs from https://www.anthropic.com/research/building-effective-agents"
)
logger.info(f"Blog intro: {result}")
# Multi-turn interactions by default
result = await llm.generate_str(
"Summarize that in a 128-char tweet"
)
logger.info(f"Tweet: {result}")
if __name__ == "__main__":
asyncio.run(example_usage())

MCP Agent の finder_agent.py を動かしてみた! 🤖✨

はじめに

lastmile-ai/mcp-agent の README に載ってる finder_agent.py を実際に動かしてみました! 最初は設定ファイルでつまづいたけど、無事に動作させることができたので、その手順をまとめてみるで 😊

MCP Agent のかわいいイラスト

環境

  • macOS 14.3.0
  • Python 3.13+
  • mcp-agent 0.1.8+
  • OpenAI API Key

つまづいたポイントと解決方法

1. filesystem サーバーのディレクトリ設定

問題: mcp_agent.config.yaml の filesystem サーバー設定で <add_your_directories> がプレースホルダーのまま残ってた

filesystem:
  command: "npx"
  args:
    [
      "-y",
      "@modelcontextprotocol/server-filesystem",
      "<add_your_directories>",  # ← これが問題!
    ]

解決: 実際のワークスペースディレクトリに変更

filesystem:
  command: "npx"
  args:
    [
      "-y",
      "@modelcontextprotocol/server-filesystem",
      "/Users/ytyng/workspace",  # ← 実際のパスに変更
    ]

2. OpenAI モデル名の修正

問題: gpt-4.1-mini という存在しないモデル名が設定されてた

openai:
  default_model: gpt-4.1-mini  # ← 存在しないモデル

解決: 正しいモデル名に変更

openai:
  default_model: gpt-4o-mini  # ← 正しいモデル名

実際の実行手順

1. プロジェクトのセットアップ

# リポジトリをクローン(既にある場合はスキップ)
git clone https://github.com/lastmile-ai/mcp-agent.git
cd mcp-agent/examples/basic/finder-agent

# 依存関係をインストール
pip install uv
uv sync
uv pip install -r requirements.txt

2. 設定ファイルの修正

# 設定ファイルを編集
vim mcp_agent.config.yaml

上記の修正内容を適用

3. API キーの設定

# secrets ファイルに OpenAI API キーを設定
vim mcp_agent.secrets.yaml
openai:
  api_key: "sk-proj-YOUR_API_KEY_HERE"

4. 実行!

# 仮想環境をアクティベート
. .venv/bin/activate

# finder_agent.py を実行
python3 finder_agent.py

動作結果

成功すると以下のような出力が表示される:

[INFO] MCPApp initialized
[INFO] filesystem: Up and running with a persistent connection!
[INFO] fetch: Up and running with a persistent connection!
[INFO] Tools available: (合計15個のツール)

利用可能なツール:

  • ファイルシステム操作: read_file, write_file, list_directory など 14個
  • Web取得: fetch など 1個

実際にファイルの読み込みやWeb上の記事の取得、要約機能なども動作確認できた!

まとめ

MCP Agent はとても強力なフレームワークやけど、設定ファイルの初期設定に注意が必要やな。 特に:

  1. プレースホルダー(<add_your_directories>)の置き換え忘れ
  2. モデル名のタイポ

この2点を気をつければ、簡単に動作させることができるで!

AI エージェントが実際にファイルを読んだり、Webから情報を取得したりする様子を見れるのは感動的やった 🎉

参考リンク


この記事が誰かの役に立てば嬉しいです! 何か質問があればコメントしてくださいね 😊

execution_engine: asyncio
logger:
transports: [console] # You can use [file, console] for both
level: debug
path: "logs/mcp-agent.jsonl" # Used for file transport
# For dynamic log filenames:
# path_settings:
# path_pattern: "logs/mcp-agent-{unique_id}.jsonl"
# unique_id: "timestamp" # Or "session_id"
# timestamp_format: "%Y%m%d_%H%M%S"
mcp:
servers:
fetch:
command: "uvx"
args: ["mcp-server-fetch"]
filesystem:
command: "npx"
args:
[
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/ytyng/workspace", # ← ここを実際のパスに変更
]
openai:
# Secrets (API keys, etc.) are stored in an mcp_agent.secrets.yaml file which can be gitignored
default_model: gpt-4o-mini # ← 正しいモデル名に修正
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment