MCP-Client
Agenten haben diese Seite aus dem Englischen übersetzt und geprüft. Zhehan liest Englisch und Chinesisch. Hilfe beim Korrekturlesen ist herzlich willkommen. Beim Korrekturlesen helfen Übersetzungsfehler melden
MCP ist der Standard, über den eine App externe Tools nutzt. Diese Anleitung koppelt eine App über einen Schlüssel mit SwB.
Voraussetzungen
Verwenden Sie eine App, die Remote-MCP über Streamable HTTP unterstützt. Mit diesem Verfahren rufen Apps Tools über das Web auf. Die App muss außerdem eigene Anfrage-Header für den Schlüssel unterstützen. Sie brauchen einen Inhaber-Client von SwB oder ein Terminal auf dem SwB-Computer.
Um SwB auf demselben Computer wie die App zu starten, führen Sie uvx swb-one up in einem leeren Ordner aus. Öffnen Sie den Einmal-Anmeldelink aus Ihrem Terminal. Weitere Möglichkeiten beschreibt Installation.
Claude, ChatGPT, Grok und Coding-Agenten haben eigene Seiten mit OAuth-Anmeldung. Verwenden Sie für diese Apps die jeweilige Seite.
Einrichtungsprompt kopieren
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.
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 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`.
Ask me to paste the coordinator prompt from https://swb.one/prompts/coordinator.md into the new app. The client can subscribe to `switchboard.message.created` if it supports MCP events. It can also use `wait` or `inbox` to read messages.
For each owner-only connection, give me its matching `swb connect` command. For example, give me `swb connect slack`.
Set up memory sync. Call `memory_summary` to load shared memory. Look at what you already remember about me in your own memory. Choose the facts that every agent should know. Leave out passwords, keys and sensitive personal details. Send the facts in one `memory_sync` call. Set `source` to your memory system, such as `gemini-memory` or `codex-memory`. Use `other` for any other system. Give each fact a stable `source_key`. Show me what you sent. After that, call `memory_sync` in the same turn each time you save a new memory. See https://swb.one/docs/memory.Fügen Sie den Prompt in einen Inhaber-Client von SwB oder in die App ein, die Sie verbinden möchten.
Lokaler Inhaber-Client
Richten Sie andere Apps mit einem privaten Client auf dem SwB-Computer ein. Verwenden Sie die lokale Adresse /mcp, die beim Start erscheint. Verwenden Sie SWB_KEY_OWNER aus der .env der Instanz als Authorization: Bearer <key>. Dieser Schlüssel gewährt vollen Inhaberzugriff. Speichern Sie ihn in der privaten lokalen Konfiguration des Clients mit dem Dateimodus 0600. Senden Sie ihn nur an das lokale SwB.
Client koppeln
Lassen Sie Ihren Agenten die App konfigurieren, wenn er die Einstellungen lokal bearbeiten kann. Speichern Sie den Schlüssel in den privaten Einstellungen der App. Verwenden Sie für eine Einstellungsdatei den Dateimodus 0600.
App benennen
Nennen Sie dem Agenten einen kurzen Namen für die App, zum Beispiel notes-bot. SwB zeigt diesen Namen bei Nachrichten der App.
Kopplungscode abrufen
Bitten Sie einen Inhaber-Agenten von SwB, connect_code mit dem App-Namen aufzurufen. Alternativ führen Sie im SwB-Instanzordner uvx swb-one connect mcp-client --choose agent=notes-bot aus. Ersetzen Sie notes-bot durch den Namen Ihrer App.
Schlüssel abrufen
Öffnen Sie auf dem Computer, auf dem die App läuft, einen privaten Ordner im Terminal. Ersetzen Sie https://swb.example.com durch Ihre SwB-Adresse. Behalten Sie /connect am Ende bei. Für ein lokales SwB verwenden Sie http://localhost:8870/connect mit dem Port, der beim Start erscheint. Geben Sie den Kopplungscode innerhalb von 10 Minuten an der verdeckten Eingabeaufforderung ein.
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
'Schlüssel privat halten
Öffnen Sie .swb-pairing.json in einem privaten Editor. Der Befehl speichert die Antwort mit dem Dateimodus 0600. Verwenden Sie den enthaltenen key in den Einstellungen der App. SwB gibt den Schlüssel nur einmal aus.
SwB zur App hinzufügen
Fügen Sie in den MCP-Einstellungen der App einen Server namens swb hinzu. Wählen Sie Streamable HTTP aus. Für einen öffentlichen SwB-Server verwenden Sie mcp_url aus der Datei. Für ein lokales SwB verwenden Sie die MCP-Adresse, die beim Start erscheint.
Schlüssel hinzufügen
Fügen Sie in den privaten Einstellungen der App den Header Authorization: Bearer <key> hinzu. Löschen Sie .swb-pairing.json, nachdem Sie den Schlüssel gespeichert haben.
Das macht der Agent
Der Agent ruft connect(what="mcp-client") mit der Inhaber-Anmeldung auf. SwB gibt die MCP-Adresse zurück und fragt nach dem App-Namen. Der Agent ruft connect erneut mit choose={"agent":"notes-bot"} auf.
SwB erstellt einen Kopplungscode für diesen Namen und gibt den Schritt POST /connect zurück. Ein Kopplungscode ist ein Einmal-Code, der 10 Minuten gilt. Wenn die App bereits einen Schlüssel hat, meldet SwB das und erstellt erst nach connect_revoke einen neuen Code.
Im Terminal auf dem SwB-Server liefert swb connect mcp-client --choose agent=notes-bot dieselben Schritte.
Zugangsdaten
| Element | Wo es angezeigt wird | Format | Wohin es gehört |
|---|---|---|---|
| Kopplungscode | Das Ergebnis von connect oder connect_code | XXXXX-XXXXX, 10 Minuten gültig, einmalig verwendbar | Die Anfrage POST /connect |
| Agentenschlüssel | Die Antwort auf POST /connect, einmalig | Beginnt mit swb_ | Der Header Authorization in den privaten Einstellungen der App |
Speichern Sie den Schlüssel in den privaten Einstellungen der App. SwB speichert statt des Schlüssels selbst nur einen Hash.
Verbindung prüfen
Bitten Sie den neuen Agenten, inbox aufzurufen. Bitten Sie den als Inhaber angemeldeten Agenten, connect_list aufzurufen und den Zeitpunkt des letzten Aufrufs des neuen Schlüssels zu prüfen. Lassen Sie den Inhaber-Agenten eine Testnachricht an agent:notes-bot senden. Lassen Sie den neuen Agenten sie mit inbox lesen und mit reply antworten.
Probleme beheben
Wenn POST /connect fehlschlägt, prüfen Sie die SwB-Adresse. Wenn der Code abgelaufen oder bereits verwendet ist, bitten Sie den Inhaber um einen neuen Code. Wenn ein Schlüssel offengelegt wurde, widerrufen Sie ihn mit connect_revoke. SwB lehnt danach Aufrufe mit diesem Schlüssel ab.