@sondt2709/wikijs-mcp 0.1.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.
- package/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/http-D7MoxUTD.js +67 -0
- package/dist/http-D7MoxUTD.js.map +1 -0
- package/dist/index.js +1020 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sondt2709
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# wikijs-mcp
|
|
2
|
+
|
|
3
|
+
An [MCP](https://modelcontextprotocol.io) server for managing [Wiki.js](https://js.wiki) 2.x
|
|
4
|
+
pages: search, read, create, update, move, delete, browse version history, and list assets —
|
|
5
|
+
all through the Wiki.js GraphQL API.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
| ---------------------- | -------------------------------------------------------- |
|
|
11
|
+
| `search_pages` | Full-text search across pages. |
|
|
12
|
+
| `list_pages` | List pages with ordering, tag, and locale filters. |
|
|
13
|
+
| `get_page` | Fetch a page by id or path, including its content. |
|
|
14
|
+
| `get_page_tree` | Browse the page hierarchy. |
|
|
15
|
+
| `list_tags` | List all tags, or search tags matching a query. |
|
|
16
|
+
| `create_page` | Create a new page. |
|
|
17
|
+
| `update_page` | Partially update a page by id. |
|
|
18
|
+
| `move_page` | Move/rename a page (requires `manage:pages` permission). |
|
|
19
|
+
| `delete_page` | Delete a page (destructive). |
|
|
20
|
+
| `get_page_history` | Fetch a page's version history trail. |
|
|
21
|
+
| `get_page_version` | Fetch the content of a specific historical version. |
|
|
22
|
+
| `restore_page_version` | Restore a page to a prior version. |
|
|
23
|
+
| `list_assets` | List asset folders and files (read-only). |
|
|
24
|
+
|
|
25
|
+
## Quick start (stdio)
|
|
26
|
+
|
|
27
|
+
Add the server to Claude Code with `claude mcp add`:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
claude mcp add wikijs -e WIKIJS_URL=https://wiki.example.com -e WIKIJS_TOKEN=your-api-key-here -- npx @sondt2709/wikijs-mcp
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For Claude Desktop, Cursor, or any other MCP client that reads a JSON config, add:
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"mcpServers": {
|
|
38
|
+
"wikijs": {
|
|
39
|
+
"command": "npx",
|
|
40
|
+
"args": ["@sondt2709/wikijs-mcp"],
|
|
41
|
+
"env": {
|
|
42
|
+
"WIKIJS_URL": "https://wiki.example.com",
|
|
43
|
+
"WIKIJS_TOKEN": "your-api-key-here"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Getting an API key
|
|
51
|
+
|
|
52
|
+
1. Log in to your Wiki.js instance as an administrator.
|
|
53
|
+
2. Go to **Administration → API Access**.
|
|
54
|
+
3. Toggle **Enable API** on.
|
|
55
|
+
4. Click **New API Key**, give it a name and expiration, and grant it the permissions
|
|
56
|
+
your workflow needs (`read:pages` at minimum; `write:pages`, `manage:pages`, and
|
|
57
|
+
`manage:system` for creating/updating/moving/deleting pages).
|
|
58
|
+
5. Copy the generated token — it's shown only once — and use it as `WIKIJS_TOKEN`.
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
| Variable / flag | Default | Description |
|
|
63
|
+
| --------------------------- | ------- | ------------------------------------------------------------------- |
|
|
64
|
+
| `WIKIJS_URL` / `--url` | — | Base URL of your Wiki.js instance (required). |
|
|
65
|
+
| `WIKIJS_TOKEN` / `--token` | — | API key from Administration → API Access (required). |
|
|
66
|
+
| `TRANSPORT` / `--transport` | `stdio` | `stdio` or `http`. |
|
|
67
|
+
| `PORT` / `--port` | `3000` | Port to listen on when `TRANSPORT=http`. |
|
|
68
|
+
| `LOG_LEVEL` / `--log-level` | `info` | pino log level: `fatal`, `error`, `warn`, `info`, `debug`, `trace`. |
|
|
69
|
+
|
|
70
|
+
CLI flags take precedence over environment variables. See `.env.example` for a template.
|
|
71
|
+
|
|
72
|
+
## HTTP / Docker mode
|
|
73
|
+
|
|
74
|
+
Run the server as a long-lived streamable-HTTP service instead of stdio — useful for
|
|
75
|
+
sharing one instance across multiple clients, or running behind a reverse proxy.
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
cp .env.example .env # set WIKIJS_URL and WIKIJS_TOKEN
|
|
79
|
+
docker compose up
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This builds the image from the included `Dockerfile` and starts the server with
|
|
83
|
+
`TRANSPORT=http` on port 3000:
|
|
84
|
+
|
|
85
|
+
- MCP endpoint: `http://localhost:3000/mcp`
|
|
86
|
+
- Health check: `http://localhost:3000/healthz`
|
|
87
|
+
|
|
88
|
+
Point your MCP client at the `/mcp` endpoint instead of spawning the process directly.
|
|
89
|
+
|
|
90
|
+
## MCP Inspector
|
|
91
|
+
|
|
92
|
+
To poke at the server interactively:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pnpm inspect
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
This builds the project and launches the [MCP Inspector](https://github.com/modelcontextprotocol/inspector)
|
|
99
|
+
against the stdio transport.
|
|
100
|
+
|
|
101
|
+
To inspect an HTTP deployment instead, start the server with `docker compose up` (or
|
|
102
|
+
`TRANSPORT=http pnpm dev`), then run `npx @modelcontextprotocol/inspector` on its own and
|
|
103
|
+
connect the Inspector UI to `http://localhost:3000/mcp` using the "Streamable HTTP"
|
|
104
|
+
transport option.
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pnpm install # install dependencies
|
|
110
|
+
pnpm dev # run from source with --watch
|
|
111
|
+
pnpm lint # eslint
|
|
112
|
+
pnpm typecheck # tsc --noEmit
|
|
113
|
+
pnpm format # prettier --write
|
|
114
|
+
pnpm build # bundle to dist/
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
End-to-end tests run against a real, disposable Wiki.js instance in Docker:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pnpm e2e:wiki:up # start local Wiki.js in Docker
|
|
121
|
+
pnpm e2e:bootstrap # headless setup: admin account + API key + e2e/.env
|
|
122
|
+
pnpm test:e2e # build + run the e2e suite
|
|
123
|
+
pnpm e2e:wiki:down # tear down the container and its data
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
See [`e2e/setup.md`](e2e/setup.md) for details, including a manual setup fallback if
|
|
127
|
+
the bootstrap script fails.
|
|
128
|
+
|
|
129
|
+
[Lefthook](https://github.com/evilmartians/lefthook) runs `eslint --fix` and `prettier`
|
|
130
|
+
on staged files at `pre-commit`, and `typecheck` + `build` at `pre-push`. It's installed
|
|
131
|
+
automatically via the `prepare` script after `pnpm install`.
|
|
132
|
+
|
|
133
|
+
## Releasing
|
|
134
|
+
|
|
135
|
+
Pushing a tag matching `v*` (e.g. `v0.2.0`) triggers `.github/workflows/release.yml`,
|
|
136
|
+
which lints, typechecks, builds, and publishes the package to npm with provenance.
|
|
137
|
+
|
|
138
|
+
The `NPM_TOKEN` repository secret must be set (an npm automation token with publish
|
|
139
|
+
access to `@sondt2709/wikijs-mcp`) before pushing a release tag, or the workflow will fail at the
|
|
140
|
+
publish step.
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { t as buildServer } from "./index.js";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
4
|
+
//#region src/http.ts
|
|
5
|
+
const MAX_BODY_BYTES = 4 * 1024 * 1024;
|
|
6
|
+
async function readJsonBody(req) {
|
|
7
|
+
const chunks = [];
|
|
8
|
+
let total = 0;
|
|
9
|
+
for await (const chunk of req) {
|
|
10
|
+
total += chunk.length;
|
|
11
|
+
if (total > MAX_BODY_BYTES) throw new Error(`Request body exceeds ${MAX_BODY_BYTES} byte limit`);
|
|
12
|
+
chunks.push(chunk);
|
|
13
|
+
}
|
|
14
|
+
const raw = Buffer.concat(chunks).toString("utf8");
|
|
15
|
+
return raw.length === 0 ? void 0 : JSON.parse(raw);
|
|
16
|
+
}
|
|
17
|
+
function startHttpServer(config, logger) {
|
|
18
|
+
const httpServer = createServer((req, res) => {
|
|
19
|
+
handle(req, res);
|
|
20
|
+
});
|
|
21
|
+
async function handle(req, res) {
|
|
22
|
+
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
|
|
23
|
+
if (url.pathname === "/healthz") {
|
|
24
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
25
|
+
res.end(JSON.stringify({ status: "ok" }));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (url.pathname !== "/mcp") {
|
|
29
|
+
res.writeHead(404, { "content-type": "application/json" });
|
|
30
|
+
res.end(JSON.stringify({ error: "not found — MCP endpoint is /mcp" }));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const body = req.method === "POST" ? await readJsonBody(req) : void 0;
|
|
35
|
+
const server = buildServer(config, logger);
|
|
36
|
+
const transport = new StreamableHTTPServerTransport({
|
|
37
|
+
sessionIdGenerator: void 0,
|
|
38
|
+
enableJsonResponse: true
|
|
39
|
+
});
|
|
40
|
+
res.on("close", () => {
|
|
41
|
+
transport.close();
|
|
42
|
+
server.close();
|
|
43
|
+
});
|
|
44
|
+
await server.connect(transport);
|
|
45
|
+
await transport.handleRequest(req, res, body);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
logger.error({ err: err.message }, "MCP request failed");
|
|
48
|
+
if (!res.headersSent) {
|
|
49
|
+
res.writeHead(500, { "content-type": "application/json" });
|
|
50
|
+
res.end(JSON.stringify({ error: "internal server error" }));
|
|
51
|
+
} else res.end();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
httpServer.on("error", (err) => {
|
|
55
|
+
if (err.code === "EADDRINUSE") logger.error({ port: config.port }, `Port ${config.port} is already in use`);
|
|
56
|
+
else logger.error({ err: err.message }, "HTTP server error");
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
|
59
|
+
httpServer.listen(config.port, () => {
|
|
60
|
+
logger.info({ port: config.port }, "wikijs-mcp listening on http (streamable), endpoint /mcp");
|
|
61
|
+
});
|
|
62
|
+
return httpServer;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { startHttpServer };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=http-D7MoxUTD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-D7MoxUTD.js","names":[],"sources":["../src/http.ts"],"sourcesContent":["import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http';\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport type { Config } from './config.ts';\nimport type { Logger } from './logger.ts';\nimport { buildServer } from './server.ts';\n\nconst MAX_BODY_BYTES = 4 * 1024 * 1024; // 4MB\n\nasync function readJsonBody(req: IncomingMessage): Promise<unknown> {\n const chunks: Buffer[] = [];\n let total = 0;\n for await (const chunk of req) {\n total += (chunk as Buffer).length;\n if (total > MAX_BODY_BYTES) {\n throw new Error(`Request body exceeds ${MAX_BODY_BYTES} byte limit`);\n }\n chunks.push(chunk as Buffer);\n }\n const raw = Buffer.concat(chunks).toString('utf8');\n return raw.length === 0 ? undefined : (JSON.parse(raw) as unknown);\n}\n\nexport function startHttpServer(config: Config, logger: Logger): Server {\n const httpServer = createServer((req, res) => {\n void handle(req, res);\n });\n\n async function handle(req: IncomingMessage, res: ServerResponse): Promise<void> {\n const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);\n\n if (url.pathname === '/healthz') {\n res.writeHead(200, { 'content-type': 'application/json' });\n res.end(JSON.stringify({ status: 'ok' }));\n return;\n }\n\n if (url.pathname !== '/mcp') {\n res.writeHead(404, { 'content-type': 'application/json' });\n res.end(JSON.stringify({ error: 'not found — MCP endpoint is /mcp' }));\n return;\n }\n\n try {\n // Stateless mode: fresh server + transport per request.\n const body = req.method === 'POST' ? await readJsonBody(req) : undefined;\n const server = buildServer(config, logger);\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n enableJsonResponse: true,\n });\n res.on('close', () => {\n void transport.close();\n void server.close();\n });\n await server.connect(transport);\n await transport.handleRequest(req, res, body);\n } catch (err) {\n logger.error({ err: (err as Error).message }, 'MCP request failed');\n if (!res.headersSent) {\n res.writeHead(500, { 'content-type': 'application/json' });\n res.end(JSON.stringify({ error: 'internal server error' }));\n } else {\n res.end();\n }\n }\n }\n\n httpServer.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EADDRINUSE') {\n logger.error({ port: config.port }, `Port ${config.port} is already in use`);\n } else {\n logger.error({ err: err.message }, 'HTTP server error');\n }\n process.exit(1);\n });\n\n httpServer.listen(config.port, () => {\n logger.info({ port: config.port }, 'wikijs-mcp listening on http (streamable), endpoint /mcp');\n });\n return httpServer;\n}\n"],"mappings":";;;;AAMA,MAAM,iBAAiB,IAAI,OAAO;AAElC,eAAe,aAAa,KAAwC;CAClE,MAAM,SAAmB,CAAC;CAC1B,IAAI,QAAQ;CACZ,WAAW,MAAM,SAAS,KAAK;EAC7B,SAAU,MAAiB;EAC3B,IAAI,QAAQ,gBACV,MAAM,IAAI,MAAM,wBAAwB,eAAe,YAAY;EAErE,OAAO,KAAK,KAAe;CAC7B;CACA,MAAM,MAAM,OAAO,OAAO,MAAM,CAAC,CAAC,SAAS,MAAM;CACjD,OAAO,IAAI,WAAW,IAAI,KAAA,IAAa,KAAK,MAAM,GAAG;AACvD;AAEA,SAAgB,gBAAgB,QAAgB,QAAwB;CACtE,MAAM,aAAa,cAAc,KAAK,QAAQ;EAC5C,OAAY,KAAK,GAAG;CACtB,CAAC;CAED,eAAe,OAAO,KAAsB,KAAoC;EAC9E,MAAM,MAAM,IAAI,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI,QAAQ,QAAQ,aAAa;EAE/E,IAAI,IAAI,aAAa,YAAY;GAC/B,IAAI,UAAU,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;GACzD,IAAI,IAAI,KAAK,UAAU,EAAE,QAAQ,KAAK,CAAC,CAAC;GACxC;EACF;EAEA,IAAI,IAAI,aAAa,QAAQ;GAC3B,IAAI,UAAU,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;GACzD,IAAI,IAAI,KAAK,UAAU,EAAE,OAAO,mCAAmC,CAAC,CAAC;GACrE;EACF;EAEA,IAAI;GAEF,MAAM,OAAO,IAAI,WAAW,SAAS,MAAM,aAAa,GAAG,IAAI,KAAA;GAC/D,MAAM,SAAS,YAAY,QAAQ,MAAM;GACzC,MAAM,YAAY,IAAI,8BAA8B;IAClD,oBAAoB,KAAA;IACpB,oBAAoB;GACtB,CAAC;GACD,IAAI,GAAG,eAAe;IACpB,UAAe,MAAM;IACrB,OAAY,MAAM;GACpB,CAAC;GACD,MAAM,OAAO,QAAQ,SAAS;GAC9B,MAAM,UAAU,cAAc,KAAK,KAAK,IAAI;EAC9C,SAAS,KAAK;GACZ,OAAO,MAAM,EAAE,KAAM,IAAc,QAAQ,GAAG,oBAAoB;GAClE,IAAI,CAAC,IAAI,aAAa;IACpB,IAAI,UAAU,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;IACzD,IAAI,IAAI,KAAK,UAAU,EAAE,OAAO,wBAAwB,CAAC,CAAC;GAC5D,OACE,IAAI,IAAI;EAEZ;CACF;CAEA,WAAW,GAAG,UAAU,QAA+B;EACrD,IAAI,IAAI,SAAS,cACf,OAAO,MAAM,EAAE,MAAM,OAAO,KAAK,GAAG,QAAQ,OAAO,KAAK,mBAAmB;OAE3E,OAAO,MAAM,EAAE,KAAK,IAAI,QAAQ,GAAG,mBAAmB;EAExD,QAAQ,KAAK,CAAC;CAChB,CAAC;CAED,WAAW,OAAO,OAAO,YAAY;EACnC,OAAO,KAAK,EAAE,MAAM,OAAO,KAAK,GAAG,0DAA0D;CAC/F,CAAC;CACD,OAAO;AACT"}
|