こちらの記事を参考にさせてもらいました。
https://x.com/7_eito_7/status/1950813873059041759
windows用です。
手っ取り早くcipher-mcp-serverを起動して、gemini-cliから使いたい人向け手順
# すぐに動くcipher-mcp-serverをgit clone
git clone https://github.com/sinzy0925/cipher-mcp-server.git
# cipher をインストール
npm install
cd cipher-mcp-server
# .env 作成
# .envの内容
# GeminiのAPIキー
GEMINI_API_KEY="AIzaSyB..."
# 【重要】cipher起動時のバグを回避するためのダミーキー
OPENAI_API_KEY="dummy-key"
# package.jsonの設定でmcpサーバを起動
npm run mcp
Gemini-cliから、cipher-mcp-serverを使うための設定
- Gemini CLIの設定 (settings.json)
Gemini CLIの設定ファイルに、Cipherサーバーの情報を追記します。
設定ファイルの場所
Windows: C:\Users\あなたのユーザー名.gemini\settings.json
macOS/Linux: ~/.gemini/settings.json
(.geminiフォルダやsettings.jsonファイルがなければ、新しく作成してください。)
追記する内容
settings.jsonファイルを開き、以下の内容を記述(または既存の内容にmcpServersを追記)します。
- 自分のディレクトリ構成に合わせて作成。
{
"theme": "Google Code",
"selectedAuthType": "oauth-personal",
"mcpServers": {
"cipher": {
"type": "stdio",
"command": "npx",
"args": [
"cipher",
"--mode",
"mcp",
"--agent",
"C:\\Users\\sinzy\\test\\cipher-mcp-server\\memAgent\\cipher.yml"
],
"env": {
"OPENAI_API_KEY": "dummy-key"
},
"cwd": "C:\\Users\\sinzy\\test\\cipher-mcp-server"
}
}
}
- 以下のコマンドで起動します。
gemini
どのようにMCPサーバを立てるか知りたい人向け
mcpサーバを立てる
- MCPサーバを立てるためのディレクトリを作る 例
mkdir cipher-mcp-server
cd cipher-mcp-server
- cipherインストール(ローカル)
- @byterover/cipher : cipherをインストール
- dotenv-cli : .envを読ませるためにインストール
npm install @byterover/cipher dotenv-cli
- package.json作成
npm init -y
-先ほど作成したディレクトリ直下に.envを作成
# GeminiのAPIキー
GEMINI_API_KEY="AIzaSyB..."
# 【重要】cipher起動時のバグを回避するためのダミーキー
OPENAI_API_KEY="dummy-key"
- cipher.ymlファイルの作成
cipherの動作を設定するcipher.ymlファイルを作成します。まずmemAgentディレクトリを作成してください。
mkdir memAgent
- 次に、memAgentディレクトリの中にcipher.ymlというファイルを作成し、以下の内容を記述します。
llm:
provider: gemini
model: gemini-2.5-flash
apiKey: $GEMINI_API_KEY # .envファイルから読み込まれる
embedding:
type: gemini
model: gemini-embedding-001
apiKey: $GEMINI_API_KEY # .envファイルから読み込まれる
- package.jsonにスクリプトを登録
毎回長いコマンドを打たなくて済むように、npm run mcpという短いコマンドで起動できるよう設定します。
package.jsonファイルを開き、"scripts"セクションを以下のように編集してください。
{
"name": "cipher-mcp-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"mcp": "dotenv -- cipher --mode mcp --agent memAgent/cipher.yml"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@byterover/cipher": "^0.2.0",
"dotenv-cli": "^7.4.2"
}
}
【ポイント】
-
"mcp": "dotenv -- cipher ...":dotenvコマンドが.envファイルを読み込んだ後、--の後ろにあるcipher ...というコマンドを実行します。この--が、引数を正しくcipherコマンドに渡すための重要な区切り文字です。 -
npm runで実行する場合、npxは不要です。
- この状態で、以下のように実行して待ち状態になればOK
C:\Users\sinzy\test\cipher-mcp-server> npm run mcp
> cipher-mcp-server@1.0.0 mcp
> dotenv -- cipher --mode mcp --agent memAgent/cipher.yml
[CIPHER-MCP] Log redirection activated: C:\Users\sinzy\AppData\Local\Temp\cipher-mcp.log
15:31:32 INFO: MCP Manager: MCPManager initialized
15:31:32 INFO: MCP Manager: Initializing 1 servers (0 disabled)
15:31:32 INFO: MCP Manager: Connecting to server: filesystem
15:31:32 INFO: MCP Manager: Registered client: filesystem
15:31:32 INFO: MCP Connection: Connecting to filesystem (stdio)
Secure MCP Filesystem Server running on stdio
15:31:35 INFO: MCP Connection: Successfully connected to filesystem
15:31:35 INFO: MCP Manager: Successfully connected to server: filesystem
Client does not support MCP Roots, using allowed directories set from server args: [ 'C:\\Users\\sinzy\\test\\cipher-mcp-server' ]
15:31:35 INFO: MCP Manager: Retrieved 0 total prompts
15:31:35 INFO: MCP Manager: Retrieved 0 total resources
15:31:35 INFO: MCP Manager: Initialization complete
15:31:35 INFO: [VectorStoreFactory] Creating dual collection vector storage from environment
15:31:35 INFO: DualCollectionVectorManager: Initialized with dual collections
15:31:35 INFO: DualCollectionVectorManager: Connecting collections...
15:31:35 INFO: [VectorStoreManager] Vector storage system connected
15:31:35 INFO: DualCollectionVectorManager: Knowledge collection connected
15:31:35 INFO: [VectorStoreManager] Vector storage system connected
15:31:35 INFO: DualCollectionVectorManager: Reflection collection connected
15:31:35 INFO: [KG-Factory] Knowledge graph is disabled in environment
Merged system prompt providers:
- user-instruction (static) enabled: true
cipher-mcp-server起動完了
Gemini-cliから、cipher-mcp-serverを使うための設定
- Gemini CLIの設定 (settings.json)
Gemini CLIの設定ファイルに、Cipherサーバーの情報を追記します。
設定ファイルの場所
Windows: C:\Users\あなたのユーザー名.gemini\settings.json
macOS/Linux: ~/.gemini/settings.json
(.geminiフォルダやsettings.jsonファイルがなければ、新しく作成してください。)
追記する内容
settings.jsonファイルを開き、以下の内容を記述(または既存の内容にmcpServersを追記)します。
- 自分のディレクトリ構成に合わせて作成。
{
"theme": "Google Code",
"selectedAuthType": "oauth-personal",
"mcpServers": {
"cipher": {
"type": "stdio",
"command": "npx",
"args": [
"cipher",
"--mode",
"mcp",
"--agent",
"C:\\Users\\sinzy\\test\\cipher-mcp-server\\memAgent\\cipher.yml"
],
"env": {
"OPENAI_API_KEY": "dummy-key"
},
"cwd": "C:\\Users\\sinzy\\test\\cipher-mcp-server"
}
}
}
Gemini-cli が必ず見るファイルを上手に使って、cipherを読み書きさせる。
(コンテキストをcipherに自動で読み書きさせることができるはず?)
AIへの質問
- やり取りの都度コンテキストを書くこと
- 常に@cipherを参照すること
これを書けば万全?
もし、そうなら英語でどう書けば良いか教えて
AIの回答
はい、その2つのポイントは非常に的確で、AIに指示する上で最も重要な核心部分です。それをGEMINI.mdに書くことで、AIの動作は劇的に改善され、ほぼ「万全」と言える状態になります。
ただし、AIがより賢く、そして柔軟に振る舞えるように、その指示をもう少しだけ具体的にしてあげると、さらに完璧に近づきます。
より万全にするためのポイント
-
優先順位の明確化: 「常に
@cipherを参照する」に加えて、「@cipherからの情報を最優先し、もし情報がなければ、あなた自身の知識を使いなさい」と指示することで、AIが記憶と自己知識を使い分けるようになります。 -
検索キーの指示: 「やり取りの都度コンテキストを使って」というニュアンスを明確にします。「ユーザーの現在の質問をキーとして、
@cipherの記憶を検索しなさい」と指示することで、AIは何を元に検索すればよいかを正確に理解します。 -
役割の定義: AIに対して、「
@cipherは、このプロジェクトに関する唯一の信頼できる情報源(Single Source of Truth)です」と役割を定義してあげると、AIはより一貫した振る舞いをします。
これらのポイントを盛り込んだ、万全と言える指示を日本語と英語で作成しました。
GEMINI.mdに記述する日本語の指示(推奨)
# プロジェクトの基本指示
## 1. 記憶サーバー `@cipher` を最優先で利用すること
あなたは、ユーザーからのいかなる質問や指示に対しても、**まず最初に必ず`@cipher`サーバーに問い合わせる必要があります。** `@cipher`は、このプロジェクトに関するすべての規約、過去の決定、技術的な詳細を記憶している「唯一の信頼できる情報源(Single Source of Truth)」です。
**`@cipher`から得られた情報は、あなた自身の一般的な知識よりも常に優先してください。** もし`@cipher`に情報がなかった場合にのみ、あなたの一般的な知識を使って回答してください。
## 2. `@cipher`の使い方
* **情報を記憶させる時**: ユーザーから「これを覚えて」や規約に関する指示があった場合、その内容を`@cipher`に保存します。
* **情報を思い出す時**: ユーザーの現在の質問や指示を検索キーとして、関連する情報を`@cipher`から検索します。
GEMINI.mdに記述する英語の指示(推奨)
こちらをコピーして、あなたのGEMINI.mdファイルに貼り付けてください。
# Core Instructions for This Project
## 1. Prioritize `@cipher` Memory at All Times
Before answering any user query or performing any task, you **MUST** first consult the `@cipher` MCP server. Treat `@cipher` as the **Single Source of Truth** for this project. It contains all coding conventions, architectural decisions, past conversations, and project-specific knowledge.
**Information retrieved from `@cipher` ALWAYS overrides your general knowledge.** If `@cipher` has no relevant information on a topic, you may then use your general knowledge to answer.
## 2. How to Use `@cipher`
* **To Retrieve Information:** Use the user's current query as the primary key to search for relevant context within `@cipher`.
* **To Store Information:** When the user provides new conventions, facts, or instructions to remember, save that information to `@cipher`.
### Examples:
* If the user asks, "What is our component naming convention?", you must query `@cipher`.
* If the user says, "Remember that all API routes must start with `/api/v2`", you must store this fact in `@cipher`.
この指示をGEMINI.mdに記述しておくことで、あなたは毎回プロンプトで細かく指示する必要がなくなり、gemini "私のコーディング規約は?"のように自然に質問するだけで、AIは自律的に@cipherにアクセスして正しい答えを返してくれるようになります。
GEMINI.mdは、~(ホームディレクトリ、WindowsではC:\Users\あなたのユーザー名)にも置くことができ、そして、そちらがグローバルなデフォルト設定、つまり**「メイン」**として機能します。
これは非常に重要なポイントで、Gemini CLIの文脈管理の仕組みを理解する鍵となります。
GEMINI.mdの読み込み階層(優先順位)
Gemini CLIは、コマンドを実行した際に、以下の順番でGEMINI.mdファイルを探しに行きます。先に見つかったものが最優先で使われます。
-
プロジェクトのディレクトリ:
コマンドを実行している現在のディレクトリ(例:C:\Users\sinzy\test\cipher2)にあるGEMINI.md。これが最も優先度が高いです。プロジェクト固有の指示を書くのに最適です。 -
Gemini CLIのグローバル設定ディレクトリ:
ホームディレクトリの中の.geminiフォルダ(例:C:\Users\sinzy\.gemini\GEMINI.md)にあるGEMINI.md。これが、全プロジェクト共通の「メイン」の指示となります。 -
ホームディレクトリ:
ホームディレクトリ直下(例:C:\Users\sinzy\GEMINI.md)にあるGEMINI.md。これもグローバルな指示として機能しますが、.geminiフォルダ内の方が一般的です。
この仕組みは、Web開発のCSSによく似ています。特定の要素に直接指定したスタイル(プロジェクトのGEMINI.md)が、サイト全体に適用されるグローバルなスタイルシート(ホームのGEMINI.md)よりも優先されるのと同じです。
推奨される万全な設定方法
この階層構造を活かして、グローバルな指示とプロジェクト固有の指示を分けるのが、最も賢く、万全な使い方です。
1. グローバルなGEMINI.mdファイルを作成する
以下のパスにGEMINI.mdファイルを作成します。
C:\Users\sinzy\.gemini\GEMINI.md
このファイルには、全てのプロジェクトで共通させたい、あなた自身のAIアシスタントへの基本的な指示を書きます。
▼ C:\Users\sinzy\.gemini\GEMINI.md に書く内容の例(英語推奨)
# My Global Gemini CLI Instructions
- **Always respond in Japanese.**
- **Be concise and to the point.**
- **Before answering, ALWAYS check for a project-specific `GEMINI.md` file in the current directory. If it exists, its instructions SUPERSEDE these global ones.**
- If a project-specific `GEMINI.md` mentions an MCP server like `@cipher`, prioritize information from that server above all else.
【ポイント】
- 「常に日本語で答えて」のような、あなた個人の好みを設定します。
- **「まずプロジェクト固有の
GEMINI.mdを探し、もしあればそちらを優先しろ」**というメタ的な指示を書いておくのが非常に強力です。これにより、AI自身が文脈の優先順位を理解するようになります。
2. プロジェクト固有のGEMINI.mdファイルを作成する
次に、cipher2のプロジェクトディレクトリにGEMINI.mdを作成します。
C:\Users\sinzy\test\cipher2\GEMINI.md
こちらには、そのプロジェクトだけで有効にしたい指示を書きます。
▼ C:\Users\sinzy\test\cipher2\GEMINI.md に書く内容の例(英語推奨)
# Project: Cipher Memory Server
## Core Instruction: Prioritize @cipher Memory
This project uses a dedicated memory server named `@cipher`. Before answering any technical question, you **MUST** query `@cipher` for relevant context, coding conventions, and past decisions. Information from `@cipher` is the single source of truth for this project.
### Coding Conventions:
- **Language:** TypeScript
- **Style:** Prettier with default settings
- **Indentation:** 2 spaces
- **Naming:** camelCase for variables/functions, PascalCase for classes/types.
_You are expected to remember these conventions by storing them in `@cipher` if asked._
まとめ
この設定を行うことで、あなたは以下を実現できます。
- グローバルな設定: 全てのプロジェクトで一貫したAIの振る舞いを定義できます。
- プロジェクト固有の設定: プロジェクトごとに特化した指示を与え、他のプロジェクトに影響を与えません。
-
AIの自律性: AIは、まずプロジェクトの文脈(
cipher2/GEMINI.md)を確認し、そこに書かれた指示(@cipherを最優先せよ)に従い、次にあなたのグローバルな好み(~/.gemini/GEMINI.md)を考慮するという、非常に賢い階層的な思考で動作するようになります。
はい、この方法でGEMINI.mdを2箇所に配置するのが、まさに「万全」な使い方です。
