claude-custom-mcp
by vaeromon
README.md
<div align="center">
# claude-custom-mcp
**Give Claude tools that run on your own device.**<br>
A self-hosted [MCP](https://modelcontextprotocol.io) server built for Claude: phone with Termux, Raspberry Pi or home server, no open ports.
[](https://github.com/vaeromon/claude-custom-mcp/actions/workflows/ci.yml)




[English](README.md) · [Bahasa Indonesia](README.id.md)
<img src="docs/img/architecture.svg" alt="Claude connects over HTTPS and OAuth to a Cloudflare Worker, which reaches your device through a Quick Tunnel" width="100%">
</div>
<table>
<tr>
<td width="33%" valign="top"><b>🔐 Private by default</b><br>OAuth 2.1 with PKCE. One key you control. Short-lived, rotating tokens.</td>
<td width="33%" valign="top"><b>🧩 Add a tool in one file</b><br>Drop a folder in <code>termux/tools/</code>, restart. No redeploy.</td>
<td width="33%" valign="top"><b>💸 Free to run</b><br>Cloudflare free plan and a free Quick Tunnel. No runtime dependencies.</td>
</tr>
</table>
## Contents
[Quick start](#quick-start) · [How it works](#how-it-works) · [Configuration](#configuration) · [Adding tools](#adding-tools) · [Security](#security) · [Troubleshooting](#troubleshooting) · [Contributing](#development)
## Quick start
<img src="docs/img/steps.en.svg" alt="Four steps: run the agent, deploy the Worker, start the agent, connect Claude" width="100%">
### 1. Run the agent
<details open>
<summary><b>Termux (Android)</b></summary>
```sh
pkg install nodejs cloudflared git
git clone https://github.com/vaeromon/claude-custom-mcp && cd claude-custom-mcp/termux
npm run setup
```
</details>
<details>
<summary><b>Linux, macOS, Raspberry Pi, server</b></summary>
Install Node.js 20.12+ and [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/), then:
```sh
git clone https://github.com/vaeromon/claude-custom-mcp && cd claude-custom-mcp/termux
npm run setup
```
</details>
`setup` writes `termux/.env` and prints `MCP_KEY` and `TERMUX_KEY`. Keep both for step 2.
### 2. Deploy the Worker
<details open>
<summary><b>Option A: Deploy button</b> (easiest)</summary>
Click to deploy your own copy:
[](https://deploy.workers.cloudflare.com/?url=https://github.com/vaeromon/claude-custom-mcp/tree/main/worker)
Paste `MCP_KEY` and `TERMUX_KEY` when asked.
</details>
<details>
<summary><b>Option B: Git integration</b> (auto-deploys on every push)</summary>
Fork this repo. In the Cloudflare dashboard: **Workers & Pages > Create > Import a repository**.
| Field | Value |
|---|---|
| Root directory | `worker` |
| Deploy command | `npx wrangler deploy` |
After the first deploy, add two **Secrets** under *Settings > Variables and Secrets*: `MCP_KEY` and `TERMUX_KEY`.
</details>
<details>
<summary><b>Option C: Command line</b></summary>
```sh
cd worker && npm install
npx wrangler login
npx wrangler secret put MCP_KEY
npx wrangler secret put TERMUX_KEY
npx wrangler deploy
```
</details>
Your URL is `https://claude-custom-mcp.<your-subdomain>.workers.dev`. Put it in `termux/.env` as `WORKER_URL`, or run `npm run setup -- --url <url>`.
### 3. Start the agent
```sh
cd termux && ./start.sh # or: npm start
```
Wait for **`Tunnel URL sent to Worker`**.
### 4. Connect Claude
1. **Customize > Connectors > Add custom connector**
2. URL: `https://<your-worker-url>/mcp`
3. Authentication: OAuth, register the client automatically
4. On the page that opens, enter `MCP_KEY`
5. In a chat, ask Claude to run `ping_termux`
> [!NOTE]
> Claude's free plan allows one custom connector.
## How it works
<img src="docs/img/flow.en.svg" alt="Sequence: Claude calls a tool, the Worker checks the token and finds the tunnel URL, forwards the call to the agent, and returns the result" width="100%">
The agent runs a Cloudflare Quick Tunnel whose URL changes on every restart. It re-registers the current URL with the Worker every minute, so the Worker always knows where to send calls.
<details>
<summary><b>Repository layout</b></summary>
```
worker/ Cloudflare Worker
wrangler.jsonc settings (name, domain, vars)
src/index.js routing
src/core/ MCP, OAuth, register, store, termux client
src/tools/<name>/ tools that run on the Worker
scripts/gen-tools.js builds the tool list automatically
termux/ agent for your device
agent.js local server + tunnel + registration
setup.js key generator
tools/<name>/ tools that run on your device
docs/ guides and diagrams (img/generate.py rebuilds the SVGs)
test/ npm test
```
</details>
## Configuration
Worker settings live in `worker/wrangler.jsonc` under `vars`. Keys are secrets and never go in that file.
| Name | Where | Default | Meaning |
|---|---|---|---|
| `MCP_KEY` | Worker secret | required | Password on the login page. Also signs tokens. |
| `TERMUX_KEY` | Worker secret + `termux/.env` | required | Shared secret between Worker and agent. |
| `SERVER_NAME` | Worker var | `claude-custom-mcp` | Name on the login page and in MCP `serverInfo`. |
| `ALLOWED_REDIRECT_URIS` | Worker var | Claude callbacks | Comma-separated OAuth redirect URIs a client may use. |
| `TOOL_TIMEOUT_MS` | Worker var | `15000` | Max wait for a Termux tool call. |
| `WORKER_URL` | `termux/.env` | required | Your Worker's URL. |
| `PORT` | `termux/.env` | `3939` | Local agent port (127.0.0.1 only). |
<details>
<summary><b>Use your own domain</b></summary>
Uncomment `routes` in `wrangler.jsonc`, set your domain, and set `workers_dev` to `false`. The domain must be on your Cloudflare account and must not already have a DNS record for that name.
</details>
<details>
<summary><b>Run the Worker locally</b></summary>
```sh
cp worker/.dev.vars.example worker/.dev.vars # fill in both keys
npm run dev
```
</details>
## Adding tools
Copy `termux/tools/_template` to `termux/tools/my_tool`, edit it, restart the agent. Tools that should run on the Worker itself go in `worker/src/tools/`. Full guide: [docs/tools.md](docs/tools.md).
## Security
Tools run code on your device on behalf of an AI, so read [SECURITY.md](SECURITY.md) before adding powerful ones.
- Login uses OAuth with PKCE. Only the redirect URIs you allow can register.
- Access tokens last 1 hour. Refresh tokens last 30 days and are single-use (rotated on every refresh).
- To rotate keys: `npm run setup -- --renew`, update both Worker secrets, restart the agent, reconnect the connector. Changing `MCP_KEY` revokes all tokens.
## Troubleshooting
<details>
<summary><b><code>ping_termux</code> says "down"</b></summary>
Is the agent running? Is <code>cloudflared</code> installed? Look for <code>Tunnel URL sent to Worker</code> in the agent output.
</details>
<details>
<summary><b>Claude can't finish connecting although the key is right</b></summary>
Bot Fight Mode or a WAF rule on your domain may be blocking the requests.
</details>
<details>
<summary><b>A new tool doesn't show up</b></summary>
Disconnect and reconnect the connector, then start a new chat.
</details>
<details>
<summary><b>The tunnel won't start</b></summary>
Quick Tunnels do not work if <code>~/.cloudflared/config.yaml</code> exists.
</details>
<details>
<summary><b>Android kills the agent</b></summary>
Disable battery optimization for Termux.
</details>
> [!WARNING]
> Quick Tunnels are meant for testing: no uptime guarantee, and the URL changes on every restart (handled automatically). For something permanent, use a named Cloudflare Tunnel and adapt `termux/lib/tunnel.js`.
## Development
```sh
npm test
```
See [CONTRIBUTING.md](CONTRIBUTING.md). Licensed under [MIT](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues