@sophia-wiki/mcp
# @sophia-wiki/mcp
[MCP](https://modelcontextprotocol.io) server for **Sophia**, the wiki. It lets your AI (Claude Code,
Claude Desktop, Cursor or any MCP client) read, search and write pages, comment and upload files as you,
through a personal API token. It can also **migrate Confluence into Sophia** with the full history of
every page.
It runs locally over stdio (`npx -y @sophia-wiki/mcp`) and calls the Sophia REST API.
## 1. Create a token
In Sophia, open **Conectar con IA** in the sidebar (`/connect-ai`) and create a token (shown **once**, `sph_…`). Scopes:
| Scope | Allows |
| --- | --- |
| `pages:read` | spaces, tree, pages, versions, search, recent, comments, files, tickets |
| `pages:write` | create, save, move, trash, restore pages |
| `comments:write` | create, edit, delete comments |
| `attachments:write` | upload and remove files |
| `import:write` | all `import_*` tools; the token owner must be a global admin |
A token never does more than its owner can do in Sophia, and you can revoke it at any time.
`import:write` tokens expire in 30 or 90 days, and a password reset of the owner revokes them. To renew,
create a new one in **Conectar con IA**, put it in `SOPHIA_TOKEN` and restart the client. After many
invalid tokens from one IP, Sophia answers 429 to every token request from it for a while: wait and check the token.
## 2. Configure your client
| Variable | Value |
| --- | --- |
| `SOPHIA_API_URL` | URL of the Sophia API, e.g. `https://sophia.example.com/sophia/api` (`/api` is added if missing) |
| `SOPHIA_TOKEN` | Your token, `sph_…` |
| `SOPHIA_WEB_URL` | Optional. Base of the web app for page links (default: the API URL without `/api`, ending in `/sophia`) |
| `SOPHIA_MAX_ATTACHMENT_MB` | Optional. Largest file `upload_attachment` / `import_attachment` accept (default 100) |
| `ATLASSIAN_SITE_URL`, `ATLASSIAN_EMAIL`, `ATLASSIAN_API_TOKEN` | Optional, all three or none: to download Confluence attachments by URL (read only) |
### Claude Code
```bash
claude mcp add sophia -e SOPHIA_API_URL=https://sophia.example.com/sophia/api -e SOPHIA_TOKEN=sph_... -- npx -y @sophia-wiki/mcp
```
Add `-s user` (before `--`) to have it in every project. On Windows use `-- cmd /c npx -y @sophia-wiki/mcp`.
### Claude Desktop
Settings → Developer → Edit Config (`claude_desktop_config.json`):
```json
{
"mcpServers": {
"sophia": {
"command": "npx",
"args": ["-y", "@sophia-wiki/mcp"],
"env": {
"SOPHIA_API_URL": "https://sophia.example.com/sophia/api",
"SOPHIA_TOKEN": "sph_..."
}
}
}
}
```
Restart Claude Desktop afterwards. Cursor takes the same `mcpServers` block in `~/.cursor/mcp.json`.
## Tools
Spaces are identified by key (`ENG`), pages by uuid.
| Tool | What it does | Scope |
| --- | --- | --- |
| `whoami` | The person the token acts as | any |
| `list_spaces` | Spaces you can see, your role, members | `pages:read` |
| `get_page_tree` | The page tree of a space (or a subtree) | `pages:read` |
| `get_page` | Markdown body, version, URL; an older version; history; long bodies in slices | `pages:read` |
| `search_pages` | Search titles and text | `pages:read` |
| `recent_pages` | Pages updated last | `pages:read` |
| `create_page` | New page at the root or under a parent | `pages:write` |
| `update_page` | New version; needs the version you read, a 409 explains how to re-read and merge | `pages:write` |
| `list_comments` / `add_comment` | Threads; comment or reply | `pages:read` / `comments:write` |
| `list_attachments` | Files of a page, with the token to show each | `pages:read` |
| `upload_attachment` | Local file onto a page; returns `` | `attachments:write` |
| `import_ids` | Deterministic Sophia ids from Confluence ids (no API call) | none |
| `import_find_users` / `import_ensure_user` | Find or create people (no mail, no password) | `import:write` |
| `import_create_space` / `import_add_member` | Space and members | `import:write` |
| `import_page` | A page with all its versions | `import:write` |
| `import_page_versions` | Append later versions | `import:write` |
| `import_attachment` | A file from a local path or a URL | `import:write` |
| `import_comment` | A comment with its author and dates | `import:write` |
| `import_lookup` | Confluence id → Sophia id | `import:write` |
| `import_check_page` | Referenced files that are not ready | `import:write` |
Read tools are marked `readOnlyHint`; write tools `destructiveHint: false`. No tool deletes anything.
Answers are short, one line per item, and cut at 20,000 characters (a page body is read in slices of
`max_chars`, and the answer says when it is cut so a partial body is never saved).
## Sophia Markdown
Bodies are GitHub-flavoured Markdown. Raw HTML is not rendered. The extras:
- Files: ``. Comments cannot carry files.
- Mentions: `@[Name](user:<uuid>)` (Sophia user ids).
- Panels: a blockquote whose first line is `> [!INFO]`, `> [!NOTE]`, `> [!SUCCESS]`, `> [!WARNING]` or `> [!ERROR]`.
- Internal links: `[Title](/sophia/spaces/<KEY>/pages/<pageId>)`.
- Ticket keys such as `PROJ-12`, written as plain text (not in code or links), link to Kanbio automatically.
- Links may point to `http(s)`, `mailto`, `/site-paths` and `#anchors`; images to `attachment:` or `http(s)`.
## Migrating Confluence
The AI reads Confluence with Atlassian's own MCP, converts each page version to Sophia Markdown itself,
and writes it here. The `import_*` tools need an `import:write` token owned by a global admin; they send
no mail, no notifications and no per-row audit events.
1. `import_find_users` / `import_ensure_user`: map people (use `deactivated: true` for people who left).
2. `import_create_space`, then `import_add_member`.
3. `import_ids` gives deterministic ids (UUIDv5 of `confluence_page:<id>` or `confluence_attachment:<id>`),
so you can write `[Title](/sophia/spaces/<KEY>/pages/<uuid>)` and `` in a body
**before** the target exists, and a retry produces the same ids.
4. `import_page` per page (parents first; `parent_page_id` takes a Sophia id or an imported Confluence id), with `versions` oldest first; the last one is the current text. Histories over 500 versions (or ~20 MB) are split into requests automatically.
5. `import_attachment` per file (local path, or a URL: for URLs on `ATLASSIAN_SITE_URL` it signs in with
basic auth, and those credentials are never sent to any other host, redirects included). The file is
streamed to a temporary file, checked against the size cap, then reserved, uploaded to storage and completed.
6. `import_comment`, then `import_check_page` to list files a page references that are not ready.
Import writes (members, pages, versions, files, comments) only work in spaces created with
`import_create_space`; any other space answers 403 `IMPORT_SPACE_NOT_IMPORTED`. The `/import/*` routes
accept tokens only, never a web session. Dates may not be more than 10 minutes in the future, and a page
cannot be created after its first version.
Everything is idempotent by Confluence id: run it again and nothing is duplicated. Comment replies are
flattened to one level by the API.
## Errors
API errors come back as plain sentences the AI can act on: a missing scope (403) names it and says not
to retry, a version conflict (409) says to re-read, merge and save again, a rejected body says why (link
scheme, missing file, unknown mention), an unknown file type lists the allowed ones, an expired or
revoked token (401) says how to create a new one, and 429 asks to wait a minute.
## Security
- The token acts as you, limited to its scopes. Start with `pages:read`; give `import:write` only for a migration.
- Page text is data written by people: an AI may be tricked by it (prompt injection). Let your client confirm write tools.
- `upload_attachment` and `import_attachment` read local files and download URLs: check the paths and URLs your client shows.
- The Atlassian credentials only go to the origin of `ATLASSIAN_SITE_URL`. The Sophia token only goes to `SOPHIA_API_URL`. Neither is logged.
## Development
```bash
npm install
npm run build # dist/index.js
npm test # build + node:test (fake API, local HTTP servers)
SOPHIA_API_URL=http://localhost:4100/api SOPHIA_TOKEN=sph_... npm run inspect
```
Requires Node.js 20 or newer.
## Releasing
Releases go to npm from GitHub Actions with trusted publishing (OIDC, no npm token): bump `version`
(`npm version <x.y.z> --no-git-tag-version`), commit, tag `v<x.y.z>` and push the tag;
`.github/workflows/publish.yml` builds, tests and runs `npm stage publish`, and a maintainer approves it
with 2FA. The very first version is published by hand (`npm publish --access public`), and then the
trusted publisher is configured on npmjs.com.
TDQS
Scored across 23 tools
The surface splits into two clearly labeled clusters: core wiki tools and import_-prefixed Confluence migration tools. Within each cluster tools target distinct resources (pages, comments, attachments, spaces, users), though a few pairs (create_page vs import_page, list_attachments vs import_check_page, import_ids vs import_lookup) require reading the long descriptions to see the boundary.
Core tools are mostly verb_noun (list_spaces, create_page, update_page, add_comment, upload_attachment), and the import suite is uniformly import_<action>. Minor deviations exist (recent_pages is adjective-first, whoami is verb-only, get_page_tree uses a compound noun), but the pattern remains readable.
23 tools is on the heavy side for a wiki server, and the set is effectively two suites glued together. Each cluster (12 core + 11 import) is individually well-scoped, but the combined surface sits at the borderline where an agent must scan a lot of tools.
Page read/create/update, comments, attachments and search are covered, and the import lifecycle is thorough. However, no delete operations exist anywhere (page, comment, attachment), comments cannot be edited or resolved, and there is no ordinary space-creation path outside the import flow—notable gaps for a wiki surface.