AIエージェント Google Julesお試ししてみた(リファクタリング編)

1. Google Julesとは

Googleの発表したAIコーディングエージェント。現在はβ版で無料でお試しできる。 Google Jules公式サイト


2. 実際に使ってみる

Google JulesはGitHub上のレポジトリを対象にして動作する。初めてで何が起きるか分からないので、壊されても痛くない小さめなプロジェクトを題材にしてみる。

  • MCPで今週の日付を返すプログラム。
  • CursorのAIで週報を操作していたら、正しい日付に書き換えてくれなかったので、作ってみたもの。
  • mcp-thisweek GitHubリポジトリ

この短時間で適当に作ったプログラムを使いやすいようにリファクタリングして貰う。


2.1 Google Julesに目的を通知

mcp-thisweekレポジトリを指定して、Google Julesに次のように依頼。

# 目的
mcp-thisweekをリファクタリングして、より良いプロダクトにします。

# やりたいこと
- 英語のREADMEを作成する
- 日本語のREADMEをリネームする
- fastmcpを使用していますが、もっと導入しやすい形式に実装を変更する
- Dockerを利用した機能の導入方法も追加でサポートしたい
- その他、導入すべきことがあれば導入

2.2 Google Julesがプランを作成して最初のコードを生成

Google Julesが以下を自動で実施:
- GitHubのレポジトリを読み取り
- プランを作成
- コードをリファクタリング
- gitのbranchを作成して、GitHubにコードをpush
https://github.com/taku-o/mcp-thisweek/tree/refactor/improve-mcp-thisweek


3. 作成されたコードを確認(Docker編)

Google Julesが作成したコードを確認していく。まずはDocker経由でMCPを利用する機能から。

git clone https://github.com/taku-o/mcp-thisweek.git
cd mcp-thisweek
# 作業ブランチに切り替え
git switch refactor/improve-mcp-thisweek
pip install -r requirements.txt
# [notice] A new release of pip is available: 24.0 -> 25.1.1
# [notice] To update, run: pip install --upgrade pip
pip install --upgrade pip
docker build -t mcp-thisweek .

3.1 エラー発生

ERROR: failed to solve: process "/bin/sh -c pip install --no-cache-dir -r requirements.txt" did not complete successfully: exit code: 1

Google Julesにエラーを直させてみる。発生したエラーの文面を貼り付けて依頼。 ペタリ。

docker build -t mcp-thisweek .
で、次のエラーが出たけれど、原因は分かりますか?

 > [4/5] RUN pip install --no-cache-dir -r requirements.txt:
1.068 Collecting python-dateutil>=2.8.2
...
1.375 ERROR: Could not find a version that satisfies the requirement fastmcp>=0.4.1 (from versions: none)
1.376 ERROR: No matching distribution found for fastmcp>=0.4.1
...
ERROR: failed to solve: process "/bin/sh -c pip install --no-cache-dir -r requirements.txt" did not complete successfully: exit code: 1

Google Julesが修正を始めて新しいコードを作成してくれた。
内容を確認してpublish branch。


3.2 修正コードの確認(Docker編2回目)

git pull origin refactor/improve-mcp-thisweek
pip install -r requirements.txt

前回失敗したところが、今度は成功。

docker build -t mcp-thisweek .

しかし、Dockerで走らせた処理がすぐ止まってしまう。

docker run -d --name mcp-thisweek-container mcp-thisweek

ログを拾うためにforegroundで実行。

docker run --name mcp-thisweek-container mcp-thisweek
#> [06/02/25 06:12:32] INFO Starting MCP server 'mcp-thisweek' server.py:799
#> with transport 'stdio'

再びGoogle Julesに修正依頼。

docker run -d --name mcp-thisweek-container mcp-thisweek
がすぐ止まってしまう。

docker run --name mcp-thisweek-container mcp-thisweek
と実行したら
[06/02/25 06:12:32] INFO Starting MCP server 'mcp-thisweek' server.py:799
with transport 'stdio'
というログが帰ってきた。

直せますか?

Google JulesがDockerfileに問題があると断定。修正してくれた。
内容を確認して再度publish branch。


3.3 修正コードの確認(Docker編3回目)

git pull origin refactor/improve-mcp-thisweek
docker build -t mcp-thisweek .

今度はDockerの処理が動いているようだ。

docker run -d --name mcp-thisweek-container mcp-thisweek
docker ps

3.4 Cursor上でMCPを動作させてみる

Cursorのmcp.jsonを変更。

"mcp-thisweek": {
  "command": "docker",
  "args": [
    "exec",
    "-i",
    "mcp-thisweek-container",
    "python",
    "/app/server.py"
  ]
}

mcp.jsonを変更したらCursorを再起動。Cursor SettingsのMCP Toolsを確認。
mcp-thisweekが有効になった。

Cursorに聞いて、MCPが動作しているかチェックする。

今週の月曜日から金曜日の日付を教えてください

> Called MCP tool get_this_week_dates

> 今週の月曜日から金曜日の日付は以下の通りです。
> 月曜日:06/02
> 火曜日:06/03
> 水曜日:06/04
> 木曜日:06/05
> 金曜日:06/06
> 他に知りたいことがあれば教えてください。

うまく修正してくれたようだ。 Docker版の機能はOK。


4. 作成されたコードを確認(python編)

pythonコマンドで動作する方の機能の修正も動作確認していく。

mcp.jsonpythonを使う版に切り替える。

which python
#> /Users/taku.omi/.pyenv/shims/python

mcp.jsonを書き換えた後、Cursorを再起動する。

{
  "mcpServers": {
    "mcp-thisweek": {
      "command": "/Users/taku.omi/.pyenv/shims/python",
      "args": [
        "/Users/taku.omi/Documents/workspaces/mcp-thisweek/server.py"
      ]
    }
  }
}

残念ながらMCPが動かない。

MCPのエラーログは、Command-Shift-Pでコマンドパレット開いて、 Output: Focus on Output Viewを選択、開かれたビューでMCP Logsを選択すれば確認出来る。

2025-06-01 15:39:41.862 [error] week: No server info found

このログをGoogle Julesに投げて修正依頼する。

pipとPythonを使用する版は、
2025-06-01 15:39:41.862 [error] week: No server info found
と出て、MCP Toolとしての起動に失敗しました。
原因は分かりますか?

意訳だが、お前のエラーだろ、と言われた

The error 'No server info found' usually means the MCP client can't find or correctly read the configuration for 'mcp-thisweek' in its mcp.json file. This could be due to an incorrect path, a typo in the server name, or incorrect command/arguments for starting the server.

To help me understand the cause, could you please:

Confirm the exact location of the mcp.json file your MCP client is using?
Share the content of this mcp.json file?
Provide the full, correct absolute path to the mcp-thisweek/server.py script on your system?
Confirm that the python command in your mcp.json correctly points to a Python 3.10+ interpreter?

Google Julesと続けてやりとりする。

mcp.jsonでは、次のように指定しました。
{
  "mcpServers": {
    "mcp-thisweek": {
      "command": "/Users/taku.omi/.pyenv/shims/python",
      "args": [
        "/Users/taku.omi/Documents/workspaces/mcp-thisweek/server.py"
      ]
    }
  }
}

どちらもファイルはある。
ls /Users/taku.omi/.pyenv/shims/python
> /Users/taku.omi/.pyenv/shims/python*
ls /Users/taku.omi/Documents/workspaces/mcp-thisweek/server.py
> /Users/taku.omi/Documents/workspaces/mcp-thisweek/server.py

Google Jules回答。

Thanks for the details! The mcp.json entry looks correct, and the file paths are valid.

The 'No server info found' error strongly suggests that the MCP client application is either not loading this specific mcp.json file, or it's trying to call the server by a name that doesn't exactly match 'mcp-thisweek' as it appears in your mcp.json.

To narrow this down, could you please tell me:

How are you trying to use or call the 'mcp-thisweek' server? (e.g., from another Python script, a specific application, a command-line interface?)
Is there a chance the client application is configured to load its mcp.json from a different path than where this file is located?
What is the name of the specific tool or application that is reporting the 'No server info found' error?
Cursorのmcp.jsonを直接編集後、
Cursorを再起動。
Cursor SettingsでMCP Toolsとして、mcp-thisweekが有効になるか確認。
という手順を踏んでいます。
Thanks! This is very helpful. Since you're using Cursor, there are a couple of things to check:

Python Interpreter Path: GUI applications like Cursor sometimes don't inherit the full shell environment, so pyenv shims might not work as expected. Could you try changing the command in your mcp.json to the direct path of the Python interpreter within your pyenv version? For example, if your Python version is 3.10.7, the path might be /Users/taku.omi/.pyenv/versions/3.10.7/bin/python. Please update this path in your mcp.json, restart Cursor, and see if it resolves the issue.

Your mcp.json would look like:

{
  "mcpServers": {
    "mcp-thisweek": {
      "command": "/Users/taku.omi/.pyenv/versions/YOUR_PYTHON_VERSION_HERE/bin/python",
      "args": [
        "/Users/taku.omi/Documents/workspaces/mcp-thisweek/server.py"
      ]
    }
  }
}
(Replace YOUR_PYTHON_VERSION_HERE with the actual version like 3.10.7)

Cursor's mcp.json Location: Can you confirm the full path to the mcp.json file that you are editing for Cursor? I want to ensure it's the one Cursor is actively using.

Let's try updating the Python command path first.

何度かやりとりしてたら、
This is puzzling.
とか言いだした。
これはアカン。


自力で直す

Google Julesと話し合いをした結果、解決しそうにないので、自力で修正してしまう。
調査結果をGoogle Julesに説明。

調査していろいろ分かったよ。
server.pyのログ出力のところが良くなかったよ。
そこのパスを直したら、
当初のpipとPythonを使用する(python)版、
pipとPythonを使用する(fastmcp)版、
両方動作するようになったよ。

いろいろ修正のお願いが続いて悪いんだけど。
・server.pyのログ出力の、logging.basicConfigのfilenameパラメータの所、うまく回避できない?
・当初のpipとPythonを使用する(python)版に記載を戻して欲しい。

Google Julesが褒めてくれた。

That's brilliant!

けど、その後のGoogle Julesがお出しした修正の動作確認を押しつけられた。
その面倒な作業こそ、Google Jules、君にやって貰いたいのだけどね

Could you please pull these latest changes and verify all three methods to ensure everything is working as expected for you?

Direct execution with pip/Python: Using your MCP client (Cursor) configured with command: "python" and args: ["/path/to/mcp-thisweek/server.py"].
fastmcp run server.py with pip/Python: Using your MCP client configured with command: "/path/to/fastmcp" and args: ["run", "/path/to/mcp-thisweek/server.py"] (this should also work now).
Docker execution: As previously, using docker exec ... python /app/server.py.
Your confirmation on these would be greatly appreciated!

4.3 最後に少し手直し

少し気になる箇所をGoogle Julesに修正して貰う。

動作確認OKです。でも、少し修正を加えたい。
・server.pyのlogging.basicConfigのfilenameパラメータの所は、完全に消すのでなく、コメントアウトしておいてください。
・READMEのdocker runのコマンドの箇所、--rmオプションを付けてくれる?
docker run -d --rm --name mcp-thisweek-container mcp-thisweek

Google Julesの修正したコードを確認してpublish branch。


Pull Requestも作って貰う

Google JulesにPull Requestも作って貰おうとした。 しかし、それは出来ないようだ。

refactor/improve-mcp-thisweekブランチの内容で
Pull Requestを作成することは可能ですか?

Pull Requestのメッセージを作って貰う。
これもなかなか面倒くさいからね。

では、Pull Request用のタイトルと、
Descriptionのメッセージは造れますか?
Refactor: Improve mcp-thisweek usability, add Docker

This pull request introduces a comprehensive refactoring of the `mcp-thisweek` project to improve its usability, maintainability, and deployment options.

**Key Changes:**

*   **English README:** Added a new `README.md` in English and renamed the original Japanese README to `README.ja.md`. Both READMEs now include updated setup instructions.
*   **Simplified Pip/Python Usage:**
    *   `server.py` is now directly executable (e.g., `python server.py`), simplifying the setup for MCP clients.
    *   The recommended pip/Python setup in the READMEs now reflects this direct execution method.
    *   Ensured compatibility with `fastmcp run server.py` for users who prefer that invocation.
*   **Docker Support:**
    *   Added a `Dockerfile` to allow users to easily build and run `mcp-thisweek` as a Docker container.
    *   The container is configured to stay running in the background (`tail -f /dev/null`) and `server.py` is invoked via `docker exec`, as detailed in the READMEs.
    *   The `docker run` command in the READMEs now includes the `--rm` option for automatic container cleanup.
*   **Logging Improvements:**
    *   Modified `server.py` to default logging to `stderr` by commenting out the `filename` parameter in `logging.basicConfig`. This resolves path-related issues encountered with file-based logging in different execution environments.
*   **`.gitignore` Update:** Added common Python and Docker artifacts to the `.gitignore` file.
*   **Iterative Fixes:**
    *   Addressed issues with Python version compatibility for `fastmcp` in the Dockerfile by upgrading the base Python image.
    *   Resolved problems with the Docker container stopping prematurely by changing the `CMD` instruction.
    *   Worked through several iterations to ensure consistent behavior for both direct Python execution and `fastmcp run` methods.

These changes make `mcp-thisweek` more accessible, easier to set up for different user preferences, and provide robust deployment options via Docker. All functionalities (direct Python execution, `fastmcp run`, and Docker) have been confirmed to be working.

5 リリース!!

良さそう。
これでPull Requestを作成して、マージした。
https://github.com/taku-o/mcp-thisweek/pull/1