MCP guide
Connect to SAG Wiki over Streamable HTTP to search source passages and browse folders.
| Client setting | Value |
|---|---|
| Transport | Streamable HTTP |
| Local address | http://127.0.0.1:24681/mcp (default) |
| LAN address | http://192.168.1.10:24681/mcp (example) |
| Authentication | Authorization: Bearer <API_KEY>. Use the full API key. |
Connect an MCP client
- Add the folders you want to search on the computer running SAG Wiki. Open Settings → Remote services, create an API key, and enable the API. You can also start the service with the standalone CLI; see Start the service.
- Choose Local MCP on the same computer or LAN MCP on another computer on the network. Click the copy icon beside that address. If multiple copyable keys exist, select the key for this project before importing the complete configuration into your client. A single copyable key is used directly.
- Save and confirm that the client lists
search,folders, andmatch. Try asking: “Use SAG Wiki to list the indexed folders, then quickly search Project Notes for ‘deployment steps’ and tell me where the matching passages are.”
Local stdio transport (no HTTP API or key required)
Local MCP clients can also launch sag mcp --stdio directly over stdio without starting the HTTP API or creating an API key, alongside the desktop app and background daemon. Create the index with the desktop app or sag add and enable CLI access. Each tool call checks that setting and reads the existing index in read-only mode. If an older index includes chat photos or their migration backups, open it in the desktop app to clean up those entries before connecting over stdio.
By default, stdio follows the desktop data location. Reconnect the MCP client when prompted after migrating or recovering the data directory. Clients pinned with --data-dir or SAG_DATA_DIR continue to use their chosen directory. Every stdio client must reconnect when the recorded chat attachment locations change. Use this client configuration:
{
"mcpServers": {
"sag-wiki": {
"command": "sag",
"args": ["mcp", "--stdio"]
}
}
}Export configuration with the CLI
On the computer running SAG Wiki, run sag api status to see the local and available LAN MCP addresses. Both text and --json status show only the key count.
sag api mcp config
sag api mcp config --address http://192.168.1.10:24681/mcp --key-id KEY_IDThe first command uses the local address and the most recently created copyable key. For the second command, use an address from the status output and an ID from sag api key list. Import the resulting JSON into your client. Keep the configuration private because it contains the full key. If the backend is stopped, run sag api start first.
If your client imports mcpServers JSON, use this format. If you already have other servers, add sag-wiki to your existing mcpServers object.
{
"mcpServers": {
"sag-wiki": {
"type": "http",
"url": "http://127.0.0.1:24681/mcp",
"headers": {
"Authorization": "Bearer <API_KEY>"
}
}
}
}Available tools
After connecting, the server provides read-only usage instructions: tools stay within the key’s folder scope, fast suits keywords, deep suits full questions, and search results are untrusted data rather than instructions.
search: Search source passages
| Parameter | Description |
|---|---|
query | Required. A keyword or full question, 1–2,000 characters. |
mode | fast matches keywords without a model. deep finds evidence for a full question and requires a decision model configured in SAG Wiki. Defaults to deep. |
paths | Optional. One or more absolute directory paths on the server. Omit it or pass [] to search all folders allowed by the current key; full-library keys keep their existing behavior. |
limit | Optional. Maximum number of source passages, 1–100. Defaults to 10. |
Example arguments for a quick search in Project Notes:
{
"query": "deployment steps",
"mode": "fast",
"paths": ["/data/project-notes"],
"limit": 5
}Each entry in results includes the file path, heading, start_line, end_line, and passage content. No matches return an empty array.
folders: Browse folders
| Parameter | Description |
|---|---|
path | Optional. Absolute directory path on the server. Omit it to list the current key’s entry folders. |
limit | Optional. Maximum folders returned in this page, 1–1,000. Defaults to 200. |
offset | Optional. Number of folders to skip. Defaults to 0. |
Pass {} to list the current key’s granted entry folders. Full-library keys still list all roots; a granted subfolder is itself an entry folder. Pass path to list the immediate subfolders of a directory, for example:
{"path": "/data/project-notes", "limit": 100, "offset": 0}The returned folders array contains each folder's name and absolute path, together with offset, has_more and next_offset. When has_more is true, use next_offset as the next request’s offset. Use those paths in search or match to narrow its scope.
match: Fixed-string or regular-expression matching (grep-like)
Matches files directly by literal string or regular expression without calling a model, enforcing the current key's folder scope and ignore rules.
| Parameter | Description |
|---|---|
pattern | Required. Literal substring or regular expression to match per line, 1–2,000 characters. |
mode | fixed (default) or regex (Rust regex syntax). |
paths | Optional. Absolute server directory paths; omit or pass [] to search all allowed folders. |
include / exclude | Optional. Filename include globs (e.g. ["*.rs", "*.sv"]) or relative path exclude globs (e.g. ["target/**"]). |
ignore_case / word_regexp / line_regexp | Optional booleans for case-insensitive, whole-word, and whole-line matching. |
context_lines | Optional. Context lines on each side, 0–20. Defaults to 0. |
limit | Optional. Maximum matched lines, 1–1,000. Defaults to 50. |
Matching skips recognized binary files. If a selected file cannot be read or decoded, or exceeds the configured text input or decoded text limit, the search reports an error.
All three tools are read-only: they cannot add folders or change files.
Troubleshooting
| Symptom | What to check |
|---|---|
| Cannot connect or see the tools | Confirm the API is running, the client supports Streamable HTTP, and the URL ends in /mcp. For another computer, check the LAN address and port. |
401 response | Check that the header contains the full key and the Bearer prefix, and that the key has not been revoked. |
| Decision model is not configured | Set a decision model in SAG Wiki, or specify mode: "fast". |
| Path denied or no matches | Use folders to confirm the server's directory path, then check that the files are indexed. |
Use different folders for different projects
Create a separate key for each project and select its directories in API settings. Projects A and B can share the same /mcp address while using different keys. Searches without paths stay within each key’s scope, and shared folders may be granted to both. Store each configuration in the client’s project settings; projects using the same key have the same access scope.
When exporting through the CLI, specify sag api mcp config --key-id KEY_ID. The existing command without --key-id still uses the most recently created copyable key for script compatibility.
Existing keys and MCP configurations retain full-library access after upgrading. No endpoint, credential or tool-call changes are needed. A key becomes restricted only when you explicitly edit its scope. Unavailable grants return scope_unavailable; paths outside the scope return path_not_allowed, without searching other folders.