MCP クライアント
このページは、エージェントが英語版から翻訳し、確認しました。Zhehan が読めるのは英語と中国語です。校正へのご協力をお待ちしています。 校正に協力する 翻訳の問題を報告する
MCP は、アプリが外部のツールを使うための標準の方式です。このガイドでは、キーを使ってアプリを SwB とペアリングします。
始める前に
Streamable HTTP によるリモート MCP に対応したアプリを使ってください。この方式では、アプリが Web 経由でツールを呼び出します。キーを送るために、アプリが独自のリクエストヘッダーにも対応している必要があります。SwB のオーナー用クライアントか、SwB のパソコンのターミナルが必要です。
アプリと同じパソコンで SwB を起動するときは、空のフォルダーで uvx swb.one up を実行してください。ターミナルに表示されるワンタイムのサインインリンクを開いてください。ほかの方法はインストールをご覧ください。
Claude、ChatGPT、Grok、コーディングエージェントには、OAuth でサインインする専用のページがあります。これらのアプリには、それぞれのページを使ってください。
セットアップ用プロンプトをコピーする
Read the setup guide at https://swb.one/docs/setup/mcp-client.
Help me connect an MCP client that supports Streamable HTTP and custom request headers. Streamable HTTP is how the client sends tool requests to SwB.
Send a `User-Agent` header that names your app in each HTTP request to SwB.
For a new local SwB server, follow **This computer** at https://swb.one/prompts/deploy.md.
Use `http://localhost:8870` if the client runs on the SwB computer. Use the port shown at startup. Use my public HTTPS address if the client runs elsewhere.
## Owner client
Use owner access for the first client if it will set up other apps. On the SwB computer, set up a private owner client. Use the local SwB address with `/mcp` at the end. Load `SWB_KEY_OWNER` from the instance `.env` inside that client. Keep the key in its local config with file mode `0600`. Send it in the `Authorization: Bearer <key>` header only to the local address. Keep the key out of commands, logs and chat. Check that the client can call `inbox`. Give the owner client https://swb.one/prompts/coordinator.md for the remaining connections.
## Paired client
Ask me to pick a short name for the app, such as `notes-bot`. From an app with SwB owner access, call `connect(what="mcp-client", choose={"agent":"notes-bot"})` with my chosen name. If I use a terminal instead, ask me to run this command in my SwB instance folder.
```bash
swb connect mcp-client --choose agent=notes-bot
```
Use `uvx swb.one connect mcp-client --choose agent=notes-bot` if I run SwB with uvx. The result gives me a pairing code. It works once within 10 minutes.
A scope is a group of memory entries. The key gets `agent:<name>` and any scope I grant to that agent. It also gets the scope of a project named in the pairing. Read `general` if the key has access to it.
If you can edit the client settings on this computer, add an MCP server named `swb`. Use a hidden prompt if I have the pairing code. Send the code to `POST /connect` and read the response in memory. Use `mcp_url` for Streamable HTTP and `key` for the `Authorization: Bearer <key>` header. Write the key straight to the client config with file mode `0600`. Keep the code and key out of commands, logs and chat. For a local server, use the MCP address shown at startup.
If I must edit the settings myself, give me this command. Ask me to run it in a private folder on the computer that runs the client. For a different server, give me the command with its base address. Ask me to enter the pairing code at the hidden prompt.
```bash
bash -c '
umask 077
set -C
read -rsp "Pairing code: " code || exit
printf "\n"
printf "{\"code\":\"%s\"}" "$code" |
curl -fsS -A "SwB-Setup" http://localhost:8870/connect -H "Content-Type: application/json" \
--data-binary @- > .swb-pairing.json
'
```
SwB returns the key once. Ask me to open `.swb-pairing.json` in a private editor.
Ask me to add an MCP server named `swb` in the client settings. Ask me to choose Streamable HTTP. Ask me to use the `mcp_url` from the file. For a local server, ask me to use the MCP address shown at startup. Ask me to set `Authorization: Bearer <key>` with the `key` from the file. Ask me to delete the file after setup.
Have the new app call `inbox`. A successful call confirms the connection, even when the inbox is empty.
For a round trip, use an app with SwB owner access. On the SwB computer, you can use a private MCP session instead. Load `SWB_KEY_OWNER` from the instance `.env` inside the client. Send it only as a bearer token to the local SwB address. Keep the key out of commands, logs and chat.
Call `send(to="agent:notes-bot", task="SwB setup test. Reply pong.")`. Replace `notes-bot` with my chosen name. Ask the new agent to read the message with `inbox`. Ask it to answer with `reply` and the item's `handle`. From the owner session, call `wait` with the `conversation` returned by `send`. Show me the reply.
For the first shared memory check, use a scope both agents can read. Ask the new agent to call `memory_list` with the scope in `scopes`.
Call `swb_guide(trigger="setup")` in the new app. Subscribe to `switchboard.message.created` if it supports MCP events.
For each owner-only connection, give me its matching `swb connect` command. For example, give me `swb connect slack`.このプロンプトを、SwB のオーナー用クライアントか、接続したいアプリに貼り付けてください。
ローカルのオーナークライアント
ほかのアプリを設定するには、SwB のパソコンにある非公開のクライアントを使ってください。起動時に表示されるローカルの /mcp アドレスを使ってください。インスタンスの .env にある SWB_KEY_OWNER を、Authorization: Bearer <key> として使ってください。このキーはオーナーの全権限を与えます。キーは、クライアントの非公開のローカル設定に保存してください。設定ファイルの権限は 0600 にしてください。このキーはローカルの SwB にだけ送ってください。
クライアントをペアリングする
エージェントがローカルで設定を編集できる場合は、アプリの設定をエージェントに任せてください。キーは、アプリの非公開の設定に保存してください。設定ファイルの権限は 0600 にしてください。
アプリに名前を付ける
notes-bot のような、アプリの短い名前をエージェントに伝えてください。SwB は、そのアプリからのメッセージにこの名前を表示します。
ペアリングコードを取得する
SwB のオーナーのエージェントに、アプリ名を指定して connect_code を呼び出すよう頼んでください。SwB のインスタンスフォルダーで uvx swb.one connect mcp-client --choose agent=notes-bot を実行することもできます。notes-bot を、実際のアプリの名前に置き換えてください。
キーを取得する
アプリを動かすパソコンで、ターミナルから非公開のフォルダーを開いてください。https://swb.example.com を、実際の SwB のアドレスに置き換えてください。末尾の /connect はそのまま残してください。ローカルの SwB では、起動時に表示されるポートを使い、http://localhost:8870/connect を使ってください。入力内容を隠すプロンプトに、10 分以内にペアリングコードを入力してください。
bash -c '
umask 077
set -C
read -rsp "Pairing code: " code || exit
printf "\n"
printf "{\"code\":\"%s\"}" "$code" |
curl -fsS https://swb.example.com/connect -H "Content-Type: application/json" \
--data-binary @- > .swb-pairing.json
'キーを安全に保管する
ローカルのエディターで .swb-pairing.json を開いてください。コマンドは、応答を権限 0600 のファイルに保存します。その中の key をアプリの設定に使ってください。SwB がキーを返すのは 1 回だけです。
アプリに SwB を追加する
アプリの MCP 設定に、swb という名前のサーバーを追加してください。Streamable HTTP を選んでください。公開された SwB サーバーでは、ファイルにある mcp_url を使ってください。ローカルの SwB では、起動時に表示される MCP アドレスを使ってください。
キーを追加する
アプリの非公開の設定に、Authorization: Bearer <key> ヘッダーを追加してください。キーを保存したら、.swb-pairing.json を削除してください。
エージェントの動作
エージェントは、オーナーのサインインで connect(what="mcp-client") を呼び出します。SwB は MCP アドレスを返し、アプリ名を尋ねます。エージェントは choose={"agent":"notes-bot"} を付けて、もう一度 connect を呼び出します。
SwB はその名前用のペアリングコードを作り、POST /connect の手順を返します。ペアリングコードとは、10 分間だけ有効な 1 回限りのコードです。アプリがすでにキーを持っている場合、SwB はそのことを伝え、connect_revoke のあとでだけ新しいコードを作ります。
SwB サーバーのターミナルで swb connect mcp-client --choose agent=notes-bot を実行しても、同じ手順が表示されます。
認証情報
| 項目 | 表示される場所 | 形式 | 入力する場所 |
|---|---|---|---|
| ペアリングコード | connect か connect_code の結果 | XXXXX-XXXXX。10 分間有効で 1 回だけ使えます | POST /connect のリクエスト |
| エージェントのキー | POST /connect の応答。1 回だけ表示 | swb_ で始まります | アプリの非公開の設定にある Authorization ヘッダー |
キーはアプリの非公開の設定に保存してください。SwB は、キーそのものの代わりにキーのハッシュを保存します。
接続を確認する
新しいエージェントに inbox の呼び出しを頼んでください。オーナーとしてサインインしたエージェントに connect_list を呼び出してもらい、新しいキーの最終呼び出し時刻を確認してください。オーナーのエージェントから agent:notes-bot にテストメッセージを送ってもらってください。新しいエージェントに、inbox で読んで reply で回答してもらってください。
問題を解決する
POST /connect が失敗したら、SwB のアドレスを確認してください。コードの期限が切れたか使用済みの場合は、オーナーに新しいコードを頼んでください。キーが漏れたら、connect_revoke で取り消してください。取り消すと、SwB はそのキーを使う呼び出しを拒否します。