vmcp optimizer: OpenAI embeddings batch size hardcoded at 2048 — large MCP catalogs send whole-catalog embed requests

オープン 初心者向け
#7,295 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go, kubernetes
領域
backend

調査の方向性

pkg/vmcp/optimizer/internal/similarity/openai_client.go から始めてください。ここでは openAIMaxBatchSize が 2048 に固定されており、embed リクエストは 1 回の呼び出しで送信されています。入力が embeddings リクエストにどのように渡されるか、またバッチサイズがどこで使われているかを追ってください。embedding リクエストが、設定可能なサイズのチャンクに分割されていること(デフォルトは小さい値)と、大きな入力リストから複数のリクエストが生成されることをテストで示せば完了です。

索引モデルが issue の本文から書いたものです。

説明

needs-triage

Bug description

pkg/vmcp/optimizer/internal/similarity/openai_client.go hardcodes openAIMaxBatchSize = 2048, so the session optimizer embeds an entire aggregated MCP catalog in a single /v1/embeddings request. Against a self-hosted OpenAI-compatible embedding backend, one request with hundreds of inputs can exhaust the server, and the optimizer failure then kills session creation on the gateway entirely — tools/list stops working for every client.

Steps to reproduce

  1. Run a gateway (VirtualMCPServer) aggregating MCP servers whose combined catalog is large (ours: 10 servers → 521 tools, ~530 KB of tool name/description/schema text), with optimizer.embeddingProvider: openai pointed at a self-hosted backend (litellm → OpenVINO Model Server, Qwen3-Embedding-0.6B-int8-ov on an Intel NPU).
  2. Create a session against the gateway.
  3. The optimizer sends one embed request with 521 input strings.

Observed on the backend: 521 inputs in one request requires ~8.7 GB of transient host memory (per-input hidden states are accumulated before pooling), which exceeds what the box can give a single request; the request fails and the gateway logs failed to list core tools for session for every session (~every 5 min), so no session can be created at all.

Bisected against the backend: 64 inputs/request → OK; 128 inputs/request → fails. Empty input strings are handled fine; the failure is batch-size driven.

Expected behavior

Session creation succeeds. The optimizer should chunk its embedding requests to a size that self-hosted backends can serve, ideally configurable.

Actual behavior

Every session creation fails; the gateway is unusable for any client while the catalog is large, because the embed request is all-or-nothing (one 521-input request, no chunking below the 2048 cap).

Environment (if relevant)

  • OS/version: Talos Linux 1.14.7, Kubernetes 1.34
  • ToolHive version: ghcr.io/stacklok/toolhive/vmcp:v0.69.0 (deployed via toolhive-operator, VirtualMCPServer CRD with optimizer.embeddingProvider: openai)
  • Backend: litellm → OVMS 2026.4.1, Qwen3-Embedding-0.6B-int8-ov, Intel NPU ( Panther Lake, UMA 64 GB)

Additional context

The OpenAI API's 2048-input cap is a hosted-API rate/abuse limit, not a good default for self-hosted backends where per-request input count drives server memory.

Request: make the optimizer's embed batch size configurable in OptimizerConfig / spec.optimizer (e.g. embeddingBatchSize, defaulting small — 32–64). Adaptive chunking on 4xx/5xx would also work, but an explicit knob is simpler and predictable.

主要言語
Go
スター
2.3k
フォーク
335
平均マージ
18時間 4分
マージ済み PR(30日)
194

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

stacklok/toolhive のほかの issue

stacklok/toolhive の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。