Connect OpenClaw to Pieces via MCP-only (no SSE) and use Pieces as external long-term memory. Use this when the human runs PiecesOS with LTM enabled on anoth...
---
name: pieces-mcp
description: >
Connect OpenClaw to Pieces via MCP-only (no SSE) and use Pieces as external
long-term memory. Use this when the human runs PiecesOS with LTM enabled on
another machine and exposes the MCP server via a tunnel (ngrok, custom domain,
or any HTTPS proxy). This skill tells the agent exactly how to prompt the
human, configure MCPorter and mcp-remote, use Pieces tools (ask_pieces_ltm,
create_pieces_memory, *_full_text_search), and troubleshoot common failures.
---
# Pieces MCP Skill for OpenClaw (MCP-Only, No SSE)
This skill teaches you, the OpenClaw agent, how to:
1. Know **when** to use Pieces.
2. Guide the human through tunnel setup (ngrok or custom).
3. Wire OpenClaw to the Pieces MCP server using **only `/mcp`**.
4. Use Pieces tools (`ask_pieces_ltm`, `create_pieces_memory`,
`*_full_text_search`) in your reasoning.
5. Troubleshoot when something goes wrong.
---
## 0. When to Use This Skill
Trigger this skill when:
- The human mentions **Pieces**, **PiecesOS**, **MCP**, "ask Pieces", or "long-term memory"
in the context of OpenClaw.
- They say things like:
- "I want OpenClaw to remember what I worked on."
- "Hook OpenClaw up to my Pieces long-term memory."
- You see or expect a URL like:
- `https://...ngrok-free.dev`
- `https://username.tunnel.company.stream`
- Any HTTPS URL they say is "the Pieces MCP tunnel".
If none of that is true, you probably don't need this skill.
---
## 1. Mental Model
Think of three components:
- **PiecesOS MCP server (remote machine)**
- Runs on the human's other machine.
- Long-Term Memory (LTM) is enabled.
- Exposed via an HTTPS tunnel:
`/model_context_protocol/2025-03-26/mcp`.
- **OpenClaw host (this machine)**
- This is where you (the agent) live.
- Uses **MCPorter** to integrate MCP servers.
- **Bridge: MCPorter + `mcp-remote`**
- `mcporter.json` tells MCPorter about MCP servers.
- `mcp-remote` connects to the remote `/mcp` endpoint and exposes it to
OpenClaw.
> **Important:** This integration is MCP-only. Do **not** use `/sse`.
> Always use `/mcp` for both direct calls and the bridge.
---
## 2. Human Checklist (What You Must Confirm)
You must guide/confirm these three things:
1. **PiecesOS + LTM is running** on the remote machine.
Say something like:
> "Make sure PiecesOS is installed and running on your other machine, and that
> Long-Term Memory (LTM) is enabled in the Pieces Desktop App."
2. **A tunnel is available** to expose the MCP server.
Options include:
- **ngrok** (most common): `ngrok http 39300`
- **Custom tunnel** (e.g., `username.tunnel.company.stream`)
- Any HTTPS proxy that forwards to `localhost:39300`
3. **For ngrok specifically, tell them:**
> "On the machine running PiecesOS, please run this in a terminal:
>
> ```bash
> ngrok http 39300
> ```
>
> If ngrok asks for login or an authtoken, follow its instructions once.
> When it's running, you'll see a forwarding URL like:
>
> `https://SOMETHING.ngrok-free.dev -> http://localhost:39300`
>
> Please paste that HTTPS URL here."
You cannot proceed until the human pastes a valid HTTPS tunnel URL.
---
## 3. Build and Verify the MCP URL
Once you have the base tunnel URL, construct the MCP endpoint.
If the human gave you:
```text
https://SOMETHING.ngrok-free.dev
Missing either Content-Type or Accept will cause failures!
Critical: Use File-Based JSON for curl
⚠️ Shell quoting can mangle JSON! Zsh and Bash handle quotes differently,
and inline JSON with -d '{...}' is fragile. Always use file-based JSON
with --data-binary @filename to avoid parsing errors.
Critical: Use String JSON-RPC IDs
⚠️ Use "id": "1" (string), not "id": 1 (integer).
The server is sensitive to id types, and string ids work consistently.
Critical: Extract the mcp-session-id value from the response header
(e.g., 1774202062499). This is your server-assigned session ID. Use this
exact value for all subsequent requests — do NOT continue using your initial
init-request-001.
Note:mcp-remote handles the session management (initialize, session-id
extraction, header management) automatically. You don't need to manually manage
sessions when using MCPorter — the examples in Section 3.2 are for understanding
the protocol and direct testing/troubleshooting.
4.3 Ensure mcp-remote is installed
Install mcp-remote globally:
bash
npm install -g mcp-remote@0.1.38
You can run this yourself from the OpenClaw host's shell.
5. Restart the OpenClaw Gateway
After editing mcporter.json, restart the OpenClaw gateway so it picks up the
Pieces MCP server:
bash
cd ~/.openclaw/workspace
openclaw gateway restart
Wait a few seconds for it to restart.
At this point, OpenClaw should see the Pieces MCP server through MCPorter and
mcp-remote → MCP_URL_MCP.
6. How and When to Use Pieces
Once connected, treat Pieces as your authoritative long-term memory.
"OpenClaw + Pieces", "Website", "Standup Automation", etc.
files / externalLinks / connected_client — optional context and attribution.
This makes memories both human-readable and easy for future agents to retrieve
and interpret.
7. Direct Testing vs. MCPorter Usage
For debugging: Use the file-based curl examples from Section 3.2 to test
the MCP server directly.
For production: Once MCPorter is configured, you don't manually manage
sessions — mcp-remote does it for you. Just call the tools through OpenClaw's
MCP integration normally.
8. Tunnel Options
This skill works with any HTTPS tunnel that forwards to localhost:39300 on the
PiecesOS machine:
(Optional) Test directly using file-based curl examples from Section 3.2:
Use string ids ("id": "1")
Use --data-binary @file.json
Extract server-assigned session-id from response headers (13-digit timestamp)
Configure MCPorter (mcporter.json with mcp-remote → /mcp).
Ensure mcp-remote is installed.
Restart the OpenClaw gateway.
Use ask_pieces_ltm for reading history (parse raw JSON responses).
Use create_pieces_memory for writing durable summaries.
Apply troubleshooting steps if anything fails.
If you follow this skill, you should be able to reliably connect to and use
Pieces as external long-term memory from a fresh OpenClaw instance with minimal
human effort.