AI Gateway MCP Server
# AI Gateway MCP Server
[](https://www.npmjs.com/package/@ayatec/ai-gateway-mcp-server)
[](https://github.com/ayatec/ai-gateway-mcp-server/actions/workflows/ci.yml)
[](https://opensource.org/licenses/MIT)
Vercel AI Gateway を通じて複数の AI プロバイダー・モデルに統一的にアクセスできる MCP サーバー。
Web 検索、マルチモデル調査・比較など、LLM を活用した 4 つのツールを提供します。
## 提供ツール
### `ask` -- AI に質問
任意のモデルに質問を送り、回答を得ます。
| パラメータ | 型 | 必須 | デフォルト | 説明 |
| ------------ | ------ | ---- | ---------------- | ---------------------------------------- |
| `question` | string | Yes | - | 質問内容 |
| `model` | string | No | `openai/gpt-5.4` | モデル ID |
| `context` | string | No | - | 追加コンテキスト |
| `max_tokens` | number | No | - | 最大出力トークン数(省略時はモデル任せ) |
### `search` -- Web 検索
検索対応モデルを使って最新情報を取得します。
| パラメータ | 型 | 必須 | デフォルト | 説明 |
| ------------ | ------ | ---- | ----------------------- | ---------------------------------------- |
| `query` | string | Yes | - | 検索クエリ |
| `model` | string | No | `google/gemini-3-flash` | 検索対応モデル ID |
| `max_tokens` | number | No | - | 最大出力トークン数(省略時はモデル任せ) |
### `research` -- マルチモデル調査・比較
複数モデルに並列クエリし、結果を統合または比較表示します。
| パラメータ | 型 | 必須 | デフォルト | 説明 |
| ---------------------- | -------- | ---- | ---------------------- | --------------------------------------------------- |
| `query` | string | Yes | - | 調査クエリ |
| `mode` | string | No | `search` | `search`(Web 検索)または `ask`(Q&A) |
| `models` | string[] | No | mode に応じた 4 モデル | 2~4 モデル ID の配列 |
| `synthesize` | boolean | No | `true` | `true`: 統合回答、`false`: 各モデルの回答を並列表示 |
| `synthesis_model` | string | No | `openai/gpt-5.4` | 統合に使うモデル(`synthesize:true` 時のみ) |
| `max_tokens` | number | No | - | 各モデルの最大出力トークン数(省略時はモデル任せ) |
| `synthesis_max_tokens` | number | No | - | 統合の最大出力トークン数(省略時はモデル任せ) |
**処理フロー:**
1. **Query Stage**: 指定(またはデフォルト)モデルに並列リクエスト
- `search` デフォルト: `perplexity/sonar`, `gemini-3-flash`, `gpt-5-mini`
- `ask` デフォルト: `gpt-5.4`, `claude-opus-4.6`, `gemini-3.1-pro-preview`, `sonar-reasoning-pro`
2. **Synthesis Stage** (`synthesize:true`): `openai/gpt-5.4` が全結果を精査・統合し、矛盾点を指摘、ソースを明記
3. **Comparison** (`synthesize:false`): 各モデルの回答をコスト・レイテンシ付きで並列表示
### `list_models` -- モデル一覧
利用可能なモデルの情報(価格・能力・検索コスト)を表示します。
| パラメータ | 型 | 必須 | 説明 |
| ------------ | ------ | ---- | ----------------------------------------------------------------------- |
| `provider` | string | No | プロバイダーでフィルタ(`openai`, `anthropic`, `google`, `perplexity`) |
| `capability` | string | No | 能力でフィルタ(`search`, `reasoning`, `fast`, `cheap`, `code`) |
## サポートモデル
### OpenAI
| モデル ID | 入力 | 出力 | 検索 | 特徴 |
| ---------------------- | ----- | ------ | ---- | -------------------------------------------------------------------------------------------------------- |
| `openai/gpt-5.4` | $2.50 | $15.00 | Yes | OpenAI 最上位。推論・コード・エージェント性能が 5.2 から大幅向上、1.05M コンテキスト、キャッシュ割引 90% |
| `openai/gpt-5.4-mini` | $0.75 | $4.50 | Yes | GPT-5 Mini の上位版。推論・コーディング・ビジョンが大幅向上、400K コンテキスト |
| `openai/gpt-5.4-nano` | $0.20 | $1.25 | Yes | GPT-5 Nano の上位版。Web 検索対応で GPT-5 Mini より安い、コーディングも向上 |
| `openai/gpt-5.3-codex` | $1.75 | $14.00 | Yes | エージェント型コード特化版。5.2-codex から 25% 高速化、mid-task steering 対応、Terminal-Bench 最高水準 |
| `openai/gpt-5-mini` | $0.25 | $2.00 | Yes | 低コスト汎用モデル。コーディングに特に強く、推論・検索も対応する万能型 |
| `openai/gpt-5-nano` | $0.05 | $0.40 | No | 最安モデル。シンプルな生成・分類向けで推論・検索は非対応 |
| `openai/gpt-oss-120b` | $0.10 | $0.50 | No | OpenAI 公開の OSS モデル。低コストで推論・コード対応、検索非対応 |
### Anthropic
| モデル ID | 入力 | 出力 | 検索 | 特徴 |
| ----------------------------- | ----- | ------ | ---- | ------------------------------------------------------------------------------------------- |
| `anthropic/claude-opus-4.6` | $5.00 | $25.00 | Yes | Anthropic 最上位。SWE-bench 最強クラスでコーディング精度が突出、1M コンテキスト |
| `anthropic/claude-sonnet-4.6` | $3.00 | $15.00 | Yes | Opus の約 1/2 コストで高品質。エージェント用途やコスパ重視の汎用タスク向け、1M コンテキスト |
| `anthropic/claude-haiku-4.5` | $1.00 | $5.00 | Yes | Anthropic 軽量モデル。低レイテンシで検索・コード対応、高速処理向け |
### Google
| モデル ID | 入力 | 出力 | 検索 | 特徴 |
| -------------------------------------- | ----- | ------ | ---- | ---------------------------------------------------------------------------------------------------- |
| `google/gemini-3-flash` | $0.50 | $3.00 | Yes | Google Search grounding 対応で検索精度が高い。コーディングも強く、search デフォルト、1M コンテキスト |
| `google/gemini-3.1-flash-lite-preview` | $0.25 | $1.50 | No | 最速クラスのスループット。低コストで推論・知識に強いが検索非対応、preview 版 |
| `google/gemini-3.1-pro-preview` | $2.00 | $12.00 | Yes | Google 最上位。科学推論・マルチモーダルに強く、Gemini 3 Pro の後継、1M コンテキスト |
### Perplexity
| モデル ID | 入力 | 出力 | 検索 | 特徴 |
| -------------------------------- | ----- | ------ | ---- | --------------------------------------------------------------------------- |
| `perplexity/sonar` | $1.00 | $1.00 | Yes | 検索特化で最安。単発の事実確認やニュース検索に最適、低レイテンシ |
| `perplexity/sonar-pro` | $3.00 | $15.00 | Yes | 高精度検索。最大 5 回の内部検索で深掘りでき、技術ドキュメントの詳細調査向け |
| `perplexity/sonar-reasoning-pro` | $2.00 | $8.00 | Yes | 推論+検索のハイブリッド。根拠付きの分析が必要な複雑な調査向け |
> 価格は 1M トークンあたり(USD)
## セットアップ
### 1. 環境変数
[Vercel AI Gateway](https://vercel.com/ai-gateway) の API キーを取得し、設定します。
| 変数名 | 必須 | 説明 |
| --------------------- | ---- | --------------------------------------- |
| `AI_GATEWAY_API_KEY` | Yes | Vercel AI Gateway API キー |
| `ZERO_DATA_RETENTION` | No | `true` で Gateway レベルの ZDR を有効化 |
## プライバシー・データ保持
各プロバイダーへのリクエストに、プライバシー保護のための設定を自動付与します。
| プロバイダー | 対応 |
| -------------- | ----------------------------------------------------- |
| **OpenAI** | `store: false` を全リクエストに付与(データ保存無効) |
| **Anthropic** | API 経由はデフォルトで学習不使用 |
| **Google** | 有料 API はデフォルトで学習不使用 |
| **Perplexity** | API はデフォルトで Zero Data Retention |
`ZERO_DATA_RETENTION=true` を設定すると、Vercel AI Gateway レベルの ZDR が有効になり、ZDR 契約済みプロバイダーにのみリクエストがルーティングされます。Perplexity は自前で ZDR を保証しているため Gateway ZDR の適用対象外です。
### 2. MCP 設定
#### npx で使う場合(推奨)
##### Claude Code
```bash
claude mcp add ai-gateway npx @ayatec/ai-gateway-mcp-server -e AI_GATEWAY_API_KEY=your-key
```
##### Claude Desktop / その他の MCP クライアント
```json
{
"mcpServers": {
"ai-gateway": {
"command": "npx",
"args": ["@ayatec/ai-gateway-mcp-server"],
"env": {
"AI_GATEWAY_API_KEY": "your-key"
}
}
}
}
```
#### ローカルビルドで使う場合
開発中のバージョンを使いたい場合や、ソースを修正して使いたい場合はこちら。
```bash
git clone https://github.com/ayatec/ai-gateway-mcp-server.git
cd ai-gateway-mcp-server
cp .env.example .env
# .env を編集して API キーを設定
pnpm install
pnpm build
```
##### Claude Code
```bash
claude mcp add ai-gateway node /path/to/ai-gateway-mcp-server/dist/index.js -e AI_GATEWAY_API_KEY=your-key
```
##### Claude Desktop / その他の MCP クライアント
```json
{
"mcpServers": {
"ai-gateway": {
"command": "node",
"args": ["/path/to/ai-gateway-mcp-server/dist/index.js"],
"env": {
"AI_GATEWAY_API_KEY": "your-key"
}
}
}
}
```
## 開発
### コマンド
```bash
pnpm install # 依存パッケージインストール
pnpm build # ビルド
pnpm dev # ウォッチモードでビルド
pnpm start # サーバー起動(ビルド後)
pnpm dev:tool # ツールの手動テスト
pnpm test # テスト実行
pnpm test:watch # テスト(ウォッチモード)
pnpm type-check # 型チェック
pnpm lint # ESLint実行
pnpm lint:fix # ESLint自動修正
pnpm format # Prettier実行
pnpm format:check # フォーマットチェック
```
### ローカルテスト
`pnpm dev:tool` で各ツールを個別にテストできます。
```bash
# ask(デフォルト: gpt-5.4)
pnpm dev:tool ask --question "TypeScriptの利点は?"
# ask(モデル指定)
pnpm dev:tool ask --question "Rustとは?" --model "anthropic/claude-sonnet-4.6"
# search(デフォルト: google/gemini-3-flash)
pnpm dev:tool search --query "Vercel AI SDK 最新情報"
# research(4モデル並列検索→統合、デフォルト)
pnpm dev:tool research --query "WebAssemblyの現状と将来"
# research(askモード、比較表示)
pnpm dev:tool research --query "関数型プログラミングの利点" --mode ask --synthesize false
# research(モデル指定)
pnpm dev:tool research --query "latest TypeScript features" --models '["openai/gpt-5.4","perplexity/sonar"]'
# list_models
pnpm dev:tool list_models
pnpm dev:tool list_models --provider openai
pnpm dev:tool list_models --capability search
```
### リリース
[Changesets](https://github.com/changesets/changesets) でバージョン管理しています。
1. changeset ファイルを作成して main に push
2. GitHub Actions が自動で CHANGELOG 更新・バージョンバンプ・npm publish
## 技術スタック
- **TypeScript** (ESM, NodeNext, strict)
- **[Vercel AI SDK](https://ai-sdk.dev/)** -- `gateway` プロバイダーで全モデルに統一アクセス
- **[MCP SDK](https://modelcontextprotocol.io/)** -- Model Context Protocol サーバー実装
- **[Zod](https://zod.dev/)** -- スキーマバリデーション
- **[Vitest](https://vitest.dev/)** -- テスト
- **[Changesets](https://github.com/changesets/changesets)** -- バージョン管理・CHANGELOG 自動生成
## ライセンス
MIT
TDQS
Scored across 4 tools
There is some overlap between search and research (mode:search) and between ask and research (mode:ask), but the descriptions clearly explain the differences (single vs. multi-model, with or without web search). The primary purposes are distinct enough that an agent can reliably select the right tool.
All tool names are lowercase imperative verbs (list_models, ask, search, research), with 'list_models' being the only verb_noun combo. There are no mixed styles like camelCase or inconsistent verb forms, making the naming pattern predictable and clear.
With only four tools, the set is tightly scoped for an AI gateway: listing models, single-query ask, single-query search, and multi-model research. Each tool earns its place and there is no bloat or unnecessary overlap for the stated purpose.
The main operations for an AI gateway are covered—listing models, asking without search, searching with web access, and multi-model research. Minor gaps like streaming responses or detailed model comparison are absent, but they are not essential for typical AI query workflows, so agents can work around them.