0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Codex × llama.cpp でMCPツール呼び出しがハング、失敗する問題と対処法

0
Last updated at Posted at 2026-07-02

問題

この問題は、codex.*mcpを呼び出したときに、ローカルモデルの初回応答が1分を超えると発生するようです。また、codex 0.116.0も必要なようです。
そのため、起動時はモデルにあいさつし、llama.cppにシステムプロンプトをキャッシュさせる必要があります。

codexで下記の問題が発生しました。
codexがローカルプロバイダーモード(lmstudio、またはllama.cpp系サーバー)でmcpツールを呼び出すと、永遠にハングしてしまいます。

 run codex.list_mcp_resources


• Calling codex.list_mcp_resources({})

• Working (36s • esc to interrupt)


› Summarize recent commits

  Qwen3.6-35B-A3B-UD-Q6_K.gguf medium · ~\Documents\LocalAI

また、mcpを呼び出した瞬間、応答が完了したとマークされてしまいます。

1.27.558.506 W srv  server_chat_: unsupported Responses tool type 'custom' skipped
1.27.558.521 W srv  server_chat_: unsupported Responses tool type 'namespace' skipped
1.27.558.558 W srv  server_chat_: unsupported Responses tool type 'namespace' skipped
1.27.558.654 W srv  server_chat_: unsupported Responses tool type 'namespace' skipped
1.27.558.714 W srv  server_chat_: unsupported Responses tool type 'web_search' skipped
1.27.595.107 I srv  params_from_: Chat format: peg-gemma4
1.27.605.934 I slot get_availabl: id  0 | task -1 | selected slot by LCP similarity, sim_best = 0.933 (> 0.100 thold), f_keep = 0.898
1.27.606.158 I slot launch_slot_: id  0 | task 829 | processing task, is_child = 0
1.27.606.167 I slot update_slots: id  0 | task 829 | Checking checkpoint with [5703, 7238] against 6232...
1.27.613.401 W slot update_slots: id  0 | task 829 | restored context checkpoint (pos_min = 5703, pos_max = 7238, n_tokens = 7239, n_past = 7238, size = 72.669 MiB)
1.28.237.657 I slot create_check: id  0 | task 829 | created context checkpoint 2 of 32 (pos_min = 6221, pos_max = 7756, n_tokens = 7757, size = 72.669 MiB)
1.28.365.745 I reasoning-budget: activated, budget=2147483647 tokens
1.28.402.682 I reasoning-budget: deactivated (natural end)
1.28.599.985 I slot print_timing: id  0 | task 829 | prompt eval time =     736.73 ms /   537 tokens (    1.37 ms per token,   728.90 tokens per second)
1.28.599.991 I slot print_timing: id  0 | task 829 |        eval time =     257.08 ms /    16 tokens (   16.07 ms per token,    62.24 tokens per second)
1.28.599.992 I slot print_timing: id  0 | task 829 |       total time =     993.81 ms /   553 tokens
1.28.599.992 I slot print_timing: id  0 | task 829 |    graphs reused =        832
1.28.600.427 I slot      release: id  0 | task 829 | stop processing: n_tokens = 7790, truncated = 0
1.28.600.445 I srv  update_slots: all slots are idle

解決策

これは現codex最新バージョンの仕様であり、バージョン0.116.0のcodexを使用する必要があります。

codex 0.116.0インストール

mkdir codex-0116
cd codex-0116

npm init -y

npm install "@openai/codex@0.116.0"

ssd問題を修正

codexの0.142.0より下は、cドライブのssdの寿命を破壊するコードが含まれているため、使用する場合回避策を実行することが推奨されます。

CREATE TRIGGERのほうのpythonスクリプト実行すると、ssdの寿命破壊が起こらなくなる場合があります。

mcpタイムアウトを指定

codex.list_mcp_resourcesはタイムアウトを設定できないので、「AIに使うな」と指示しなければなりません。

mcpのタイムアウトをstartup_timeout_sectool_timeout_secで長くする必要があります。

%USERPROFILE%.codex\config.toml
[mcp_servers.clion]
url = "http://127.0.0.1:64311/stream"
enabled = true
startup_timeout_sec = 10000
tool_timeout_sec = 100000
[mcp_servers.chrome-devtools]
command = "npx"
args = ["chrome-devtools-mcp@latest", "--categoryExperimentalWebmcp=true",  "--chromeArg=--enable-features=WebMCPTesting,DevToolsWebMCPSupport"]
enabled = true
startup_timeout_sec = 10000
tool_timeout_sec = 100000

起動

これは私の環境での数値です。

このモデルをlmstudioでダウンロードしました。
モデルの大きさは、アクティブパラメーターがあるため、おそらく大きくても速度は変わらないと思います。搭載メモリに応じた量子化を選択してください。

これには改行が含まれます

 ./codex-0116/node_modules/.bin/codex
 -m Qwen3.6-35B-A3B-UD-Q6_K.gguf
 --config model_provider="local" 
 --config oss_provider="lmstudio"
 --config sandbox_mode="workspace-write"
 --config bypass-sandbox=false
 --config bypass-approvals=false
 --sandbox workspace-write
 --config model_catalog_json="model_catalog.json"

model_catalog.json

外部のモデルはmodel_catalog.jsonでモデルのメタデータを指定する必要があります。
slugは、モデル識別子と合わせ、context_windowmax_context_windowtruncation_policy.limitcontext length設定と同期する必要があります。

model_catalog.json
{
  "models": [
    {
      "slug": "Qwen3.6-35B-A3B-UD-Q6_K.gguf",
      "display_name": "Qwen3.6 35B A3B (Q6_K, local TurboQuant+)",
      "description": "Local GGUF via llama-server / TurboQuant+",
      "shell_type": "shell_command",
      "visibility": "list",
      "supported_in_api": true,
      "priority": 0,
      "context_window": 98304,
      "max_context_window": 98304,
      "effective_context_window_percent": 90,
      "input_modalities": ["text"],
      "supports_search_tool": false,
      "supports_image_detail_original": false,
      "supports_reasoning_summaries": false,
      "support_verbosity": false,
      "apply_patch_tool_type": "freeform",
      "web_search_tool_type": "text",

      "base_instructions": "You are a helpful AI assistant running locally. Provide accurate and concise answers.",

      "experimental_supported_tools": [
        "mcp"
      ],
      "supports_parallel_tool_calls": false,

      "truncation_policy": {
        "mode": "tokens",
        "limit": 98304
      },

      "supported_reasoning_levels": []
    }
  ]
}

おまけ

llama-cpp-turboquant

対応しているモデルであれば、lmstudioを使用するよりもllama-cpp-turboquantのほうが2倍ほど早いです。
なお特別な量子化をしなくても、turboquantの恩恵を受けられる場合があります。

rtx 4070 ti superでおおよそ倍の速度が出ることを確認済みです。

codex --oss -m gemma-4-26b-a4b-qat
  lmstudio: 30.24tok/sec
  llama-cpp-turboquan: 69.53 tokens/second
  (--n-gpu-layers 999 --n-cpu-moe 8)

codex --oss -m Qwen3.6-35B-A3B-GGUF
  llama-cpp-turboquan: 45.35 tokens per second
  (--n-gpu-layers 999 --n-cpu-moe 25)

ダウンロード

プレビルドバイナリをダウンロードしましょう

image.png

どこかへ展開しておき、llama-server.exeがあることを確認します。

起動引数

threads: cpuで処理するスレッド数
n-cpu-moe: どれだけcpuに負荷を負担させるか。減らすとメモリ使用量減。0に近いほどGPUが使用される。
m: モデル指定
mmproj: マルチモーダルモデル指定(画像)
c: context length
-fa on --cache-type-k q8_0 --cache-type-v turbo3: 高速化ON

これには改行が含まれます

--n-cpu-moe 40は、GPUメモリの実装量に応じて調整してください

"./turboquant-plus-tqp-v0.2.0-windows-x64-cuda12.4\llama-server.exe"
--host 127.0.0.1 --port 1234
--parallel 1 --threads 12
--n-gpu-layers 999 --n-cpu-moe 40
--device CUDA0
-fa on --cache-type-k q8_0 --cache-type-v turbo3
-c 98304
-m "C:\Users\owner\.lmstudio\models\unsloth\Qwen3.6-35B-A3B-GGUF\Qwen3.6-35B-A3B-UD-Q6_K.gguf" 
--mmproj "C:\Users\owner\.lmstudio\models\unsloth\Qwen3.6-35B-A3B-GGUF\mmproj-F32.gg
uf"

codex設定

[features]
apps = false

[model_providers.local]
name = "Local llama.cpp"
base_url = "http://127.0.0.1:1234/v1"
requires_openai_auth = false
stream_idle_timeout_ms = 10000000
web_search = "disabled"
wire_api = "responses"

おわりに

良きローカルAIライフを!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?