@onllm-dev/4dpocket-mcp 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +98 -0
  2. package/bin.mjs +105 -0
  3. package/package.json +41 -0
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # @onllm-dev/4dpocket-mcp
2
+
3
+ MCP client launcher for [4DPocket](https://github.com/onllm-dev/4DPocket) — connects stdio-based MCP clients (Claude Desktop, Cursor, Claude Code, Zed, etc.) to a remote 4DPocket instance over streamable HTTP with PAT auth.
4
+
5
+ ## Install
6
+
7
+ No install needed — use via `npx`:
8
+
9
+ ```bash
10
+ npx @onllm-dev/4dpocket-mcp --url https://your.pocket.tld --token fdp_pat_xxx
11
+ ```
12
+
13
+ ## Get a PAT
14
+
15
+ 1. Open your 4DPocket instance → **Settings → API Tokens & MCP**
16
+ 2. Click **Create Token**, pick a name and scope
17
+ 3. Copy the `fdp_pat_...` string (shown once)
18
+
19
+ ## Claude Desktop
20
+
21
+ Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
22
+
23
+ ```json
24
+ {
25
+ "mcpServers": {
26
+ "4dpocket": {
27
+ "command": "npx",
28
+ "args": [
29
+ "-y",
30
+ "@onllm-dev/4dpocket-mcp",
31
+ "--url", "https://your.pocket.tld",
32
+ "--token", "fdp_pat_xxx"
33
+ ]
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ Restart Claude Desktop.
40
+
41
+ ## Cursor
42
+
43
+ `~/.cursor/mcp.json`:
44
+
45
+ ```json
46
+ {
47
+ "mcpServers": {
48
+ "4dpocket": {
49
+ "command": "npx",
50
+ "args": ["-y", "@onllm-dev/4dpocket-mcp", "--url", "https://your.pocket.tld", "--token", "fdp_pat_xxx"]
51
+ }
52
+ }
53
+ }
54
+ ```
55
+
56
+ ## Claude Code
57
+
58
+ If your 4DPocket server supports HTTP MCP directly, you can skip this package and wire it natively:
59
+
60
+ ```bash
61
+ claude mcp add --transport http 4dpocket https://your.pocket.tld/mcp \
62
+ --header "Authorization: Bearer fdp_pat_xxx"
63
+ ```
64
+
65
+ Use `@onllm-dev/4dpocket-mcp` when your client only speaks stdio.
66
+
67
+ ## Env vars
68
+
69
+ Instead of flags you can use env vars:
70
+
71
+ ```bash
72
+ FDP_URL=https://your.pocket.tld FDP_TOKEN=fdp_pat_xxx npx @onllm-dev/4dpocket-mcp
73
+ ```
74
+
75
+ ## Available tools
76
+
77
+ Once connected, your MCP client gets these 4DPocket tools:
78
+
79
+ - `save_knowledge` — save a URL or note
80
+ - `search_knowledge` — hybrid search across your saved items
81
+ - `get_knowledge` — fetch an item by id
82
+ - `update_knowledge` — edit title/notes/tags
83
+ - `refresh_knowledge` — re-fetch and reprocess content
84
+ - `delete_knowledge` — remove an item (requires `allow_deletion` PAT)
85
+ - `list_collections`
86
+ - `add_to_collection`
87
+ - `get_entity`
88
+ - `get_related_entities`
89
+
90
+ ## Troubleshooting
91
+
92
+ - **`401 Unauthorized`** — the token is wrong, revoked, or doesn't start with `fdp_pat_`. Create a new one.
93
+ - **`404 Not Found` on `/mcp`** — your server is older than 0.2.0. Upgrade the 4DPocket instance.
94
+ - **`ENOTFOUND` / `ECONNREFUSED`** — the `--url` isn't reachable from your machine. Check VPN / firewall.
95
+
96
+ ## License
97
+
98
+ MIT
package/bin.mjs ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ // @onllm-dev/4dpocket-mcp — thin launcher that proxies an MCP stdio client
3
+ // (Claude Desktop, Cursor, Claude Code, etc.) to a remote 4DPocket server
4
+ // over streamable HTTP with PAT auth.
5
+ //
6
+ // Usage:
7
+ // npx @onllm-dev/4dpocket-mcp --url https://yours.tld --token fdp_pat_xxx
8
+ // FDP_URL=... FDP_TOKEN=... npx @onllm-dev/4dpocket-mcp
9
+
10
+ import { spawn } from "node:child_process";
11
+ import { createRequire } from "node:module";
12
+ import path from "node:path";
13
+ import process from "node:process";
14
+
15
+ const require = createRequire(import.meta.url);
16
+
17
+ const HELP = `@onllm-dev/4dpocket-mcp — MCP client for 4DPocket
18
+
19
+ Usage:
20
+ npx @onllm-dev/4dpocket-mcp --url <server-url> --token <pat>
21
+
22
+ Options:
23
+ --url <url> 4DPocket server URL (e.g. https://pocket.example.com).
24
+ Reads FDP_URL env var if omitted.
25
+ --token <pat> Personal Access Token (fdp_pat_...).
26
+ Reads FDP_TOKEN env var if omitted.
27
+ --help, -h Show this help.
28
+ --version, -v Show version.
29
+
30
+ Claude Desktop / Cursor config example:
31
+ {
32
+ "mcpServers": {
33
+ "4dpocket": {
34
+ "command": "npx",
35
+ "args": ["-y", "@onllm-dev/4dpocket-mcp",
36
+ "--url", "https://yours.tld",
37
+ "--token", "fdp_pat_xxx"]
38
+ }
39
+ }
40
+ }
41
+ `;
42
+
43
+ function fail(msg) {
44
+ process.stderr.write(`4dpocket-mcp: ${msg}\n\n${HELP}`);
45
+ process.exit(2);
46
+ }
47
+
48
+ function parseArgs(argv) {
49
+ const out = { url: process.env.FDP_URL ?? null, token: process.env.FDP_TOKEN ?? null };
50
+ for (let i = 0; i < argv.length; i++) {
51
+ const a = argv[i];
52
+ if (a === "--help" || a === "-h") { process.stdout.write(HELP); process.exit(0); }
53
+ if (a === "--version" || a === "-v") {
54
+ const pkg = require("./package.json");
55
+ process.stdout.write(`${pkg.version}\n`);
56
+ process.exit(0);
57
+ }
58
+ if (a === "--url") { out.url = argv[++i]; continue; }
59
+ if (a === "--token") { out.token = argv[++i]; continue; }
60
+ fail(`unknown argument: ${a}`);
61
+ }
62
+ return out;
63
+ }
64
+
65
+ function normalizeUrl(raw) {
66
+ // Strip trailing slash, strip a trailing /mcp or /mcp/ if the user already
67
+ // included it, then append /mcp/ — FastMCP's streamable-HTTP transport
68
+ // requires the trailing slash.
69
+ let u;
70
+ try { u = new URL(raw); } catch { fail(`invalid --url: ${raw}`); }
71
+ let p = u.pathname.replace(/\/+$/, "");
72
+ if (p.endsWith("/mcp")) p = p.slice(0, -"/mcp".length);
73
+ u.pathname = `${p}/mcp/`;
74
+ return u.toString();
75
+ }
76
+
77
+ function resolveMcpRemoteBin() {
78
+ const pkgPath = require.resolve("mcp-remote/package.json");
79
+ const pkg = require(pkgPath);
80
+ const rel = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.["mcp-remote"];
81
+ if (!rel) fail("mcp-remote is installed but exposes no 'mcp-remote' bin; reinstall.");
82
+ return path.resolve(path.dirname(pkgPath), rel);
83
+ }
84
+
85
+ const { url, token } = parseArgs(process.argv.slice(2));
86
+ if (!url) fail("missing --url (or FDP_URL env var).");
87
+ if (!token) fail("missing --token (or FDP_TOKEN env var).");
88
+ if (!token.startsWith("fdp_pat_")) {
89
+ process.stderr.write(
90
+ `4dpocket-mcp: warning: token does not start with fdp_pat_ — is this really a 4DPocket PAT?\n`
91
+ );
92
+ }
93
+
94
+ const mcpUrl = normalizeUrl(url);
95
+ const binAbs = resolveMcpRemoteBin();
96
+
97
+ const child = spawn(
98
+ process.execPath,
99
+ [binAbs, mcpUrl, "--header", `Authorization: Bearer ${token}`],
100
+ { stdio: "inherit" }
101
+ );
102
+ child.on("exit", (code, signal) => {
103
+ if (signal) process.kill(process.pid, signal);
104
+ else process.exit(code ?? 0);
105
+ });
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@onllm-dev/4dpocket-mcp",
3
+ "version": "0.2.0",
4
+ "description": "MCP client for 4DPocket — connect Claude Desktop, Cursor, and other MCP clients to your self-hosted 4DPocket instance.",
5
+ "type": "module",
6
+ "bin": {
7
+ "4dpocket-mcp": "./bin.mjs"
8
+ },
9
+ "files": [
10
+ "bin.mjs",
11
+ "README.md"
12
+ ],
13
+ "keywords": [
14
+ "mcp",
15
+ "model-context-protocol",
16
+ "4dpocket",
17
+ "knowledge-base",
18
+ "claude",
19
+ "cursor"
20
+ ],
21
+ "author": "onllm-dev",
22
+ "license": "MIT",
23
+ "homepage": "https://github.com/onllm-dev/4DPocket#mcp",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/onllm-dev/4DPocket.git",
27
+ "directory": "mcp-npm"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/onllm-dev/4DPocket/issues"
31
+ },
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "dependencies": {
36
+ "mcp-remote": "^0.1.38"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ }
41
+ }