Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated agent-plugin MCP server bundle. Rebuilt by `npm run build`; CI
# fails if the committed copy is stale. Keep bytes exact on every platform.
plugin/server/llmwiki-mcp.cjs -text linguist-generated=true
22 changes: 22 additions & 0 deletions .github/plugin/marketplace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "llmwiki",
"owner": {
"name": "Microsoft"
},
"metadata": {
"description": "Agent plugin for LLM Wiki, a personal knowledge base that your agent maintains.",
"version": "1.0.1"
},
"plugins": [
{
"name": "llmwiki",
"description": "Skills to ask, research, ingest, save and fix an LLM Wiki, a Wiki Librarian agent, and the LLM Wiki MCP server.",
"version": "1.0.1",
"source": "./plugin",
"homepage": "https://github.com/microsoft/llmwiki#readme",
"repository": "https://github.com/microsoft/llmwiki",
"license": "MIT",
"keywords": ["wiki", "knowledge-base", "mcp", "markdown", "skills"]
}
]
}
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ jobs:
- name: Build VS Code extension
run: npm run build --workspace=packages/vscode

- name: Check the committed plugin server bundle is up to date
run: |
if ! git diff --exit-code --stat -- plugin/server/; then
echo "::error::plugin/server/llmwiki-mcp.cjs is stale. Run 'npm run build' and commit the result."
exit 1
fi

- name: Lint core
run: npm run lint --workspace=packages/core

Expand Down
116 changes: 83 additions & 33 deletions ARCHITECTURE.md

Large diffs are not rendered by default.

121 changes: 94 additions & 27 deletions README.md

Large diffs are not rendered by default.

Binary file modified docs/images/interface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 134 additions & 10 deletions docs/mcp-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
- [wiki_add_crosslinks](#wiki_add_crosslinks)
- [wiki_update_index](#wiki_update_index)
- [wiki_ingest_with_context](#wiki_ingest_with_context)
- [wiki_fix](#wiki_fix)
- [wiki_delete_page](#wiki_delete_page)
- [Workspace Tools](#workspace-tools)
- [wiki_open](#wiki_open)
- [wiki_init](#wiki_init)
- [Security Model](#security-model)
- [Example Workflows](#example-workflows)
- [See Also](#see-also)
Expand All @@ -33,13 +38,15 @@ The `llmwiki` MCP server exposes wiki operations over the [Model Context Protoco

| Property | Value |
|----------|-------|
| **Server name** | `llmwiki` |
| **Version** | `0.1.0` |
| **Server name** | `llmwiki` (title: LLM Wiki) |
| **Version** | The `@llmwiki/core` package version |
| **Protocol** | MCP over stdio |
| **Launcher** | `llmwiki-mcp [wiki-root]` (bin from `@llmwiki/core`) |
| **VS Code** | Auto-registered by the LLM Wiki extension via `mcpServerDefinitionProviders` |
| **Response format** | JSON text content |
| **Agent plugin** | `plugin/` β€” `copilot plugin install microsoft/llmwiki:plugin` |
| **Response format** | JSON text content; `wiki_status`, `wiki_query`, `wiki_lint` and `wiki_fix` also return `structuredContent` matching their `outputSchema` |
| **Error shape** | `{ isError: true }` with an error message string |
| **Instructions** | Usage guidance plus the wiki's `AGENTS.md` (when the wiki is known at startup) |

### Connecting

Expand All @@ -58,9 +65,11 @@ The `llmwiki` MCP server exposes wiki operations over the [Model Context Protoco
}
```

The wiki-root argument is optional; when omitted the launcher defaults to `<cwd>/.wiki`. Install `@llmwiki/core` globally (`npm i -g @llmwiki/core`) to skip the `npx` indirection.
The wiki root comes from the argument or the `LLMWIKI_ROOT` environment variable. Without either, the server uses `<cwd>/.wiki` when it exists at startup, otherwise looks in the client's workspace roots, and adds the [workspace tools](#workspace-tools) so an agent can open or create one. Install `@llmwiki/core` globally (`npm i -g @llmwiki/core`) to skip the `npx` indirection.

The server provides **7 read tools** for querying and inspecting the wiki, and **7 write tools** for creating, updating, and maintaining content. All tools accept a single JSON object as input and return a single JSON object as output.
The server provides **7 read tools** for querying and inspecting the wiki, and **9 write tools** for creating, updating, and maintaining content. All tools accept a single JSON object as input and return a single JSON object as output.

Every tool has a `title` and [annotations](https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-annotations). Read tools set `readOnlyHint: true`, so VS Code runs them without asking for confirmation. Write tools set `readOnlyHint: false`; those that can overwrite or delete content also set `destructiveHint: true`. All tools set `openWorldHint: false`.

---

Expand Down Expand Up @@ -423,6 +432,9 @@ Create a new wiki entity page at `wiki/entities/{slug}.md` with proper frontmatt
| `name` | string | **Yes** | Entity name (used for title and slug generation) |
| `content` | string | **Yes** | Markdown body content |
| `tags` | string[] | No | Tags for frontmatter and index |
| `sources` | string[] | No | Existing source summary pages under `sources/` that the page is derived from (e.g. `["sources/report-summary.md"]`). Anything else is rejected. If all of them are later removed, `wiki_fix` deletes the page. |

An existing page with the same slug is overwritten, so check for one first.

**Output**

Expand All @@ -433,6 +445,7 @@ Create a new wiki entity page at `wiki/entities/{slug}.md` with proper frontmatt
| `title` | string | Entity name used as title |
| `type` | string | Always `"entity"` |
| `tags` | string[] | Applied tags |
| `sources` | string[] | Recorded sources, when given |

**Example**

Expand Down Expand Up @@ -470,6 +483,9 @@ Create a new wiki concept page at `wiki/concepts/{slug}.md` with proper frontmat
| `name` | string | **Yes** | Concept name (used for title and slug generation) |
| `content` | string | **Yes** | Markdown body content |
| `tags` | string[] | No | Tags for frontmatter and index |
| `sources` | string[] | No | Existing source summary pages under `sources/` that the page is derived from. Anything else is rejected. If all of them are later removed, `wiki_fix` deletes the page. |

An existing page with the same slug is overwritten, so check for one first.

**Output**

Expand All @@ -480,6 +496,7 @@ Create a new wiki concept page at `wiki/concepts/{slug}.md` with proper frontmat
| `title` | string | Concept name used as title |
| `type` | string | Always `"concept"` |
| `tags` | string[] | Applied tags |
| `sources` | string[] | Recorded sources, when given |

**Example**

Expand Down Expand Up @@ -520,6 +537,7 @@ Update an existing wiki page by merging partial frontmatter changes and/or appen
| `tags` | string[] | No | New tags (replaces existing tags) |
| `bodyAppend` | string | No | Markdown to append to existing body |
| `bodyReplace` | string | No | Markdown to replace entire body |
| `addSources` | string[] | No | Summary pages of other sources whose content you are adding (e.g. `["sources/second-report-summary.md"]`). Appended to the page's existing `sources`, so the page is only deleted once all of its sources are removed. Must be existing summary pages under `sources/`. Ignored for pages that list no sources, so hand-written pages never become eligible for cleanup. |

**Output**

Expand All @@ -530,6 +548,7 @@ Update an existing wiki page by merging partial frontmatter changes and/or appen
| `frontmatter` | object | Updated frontmatter |
| `bodyUpdated` | boolean | Whether the body was changed |
| `indexUpdated` | boolean | Whether the index was refreshed |
| `sourcesUpdated` | boolean | Whether `addSources` added any source |

> **Note:** Fails gracefully if the target page does not exist.

Expand Down Expand Up @@ -661,7 +680,7 @@ Ingest a source file into the wiki and return enhanced context including related

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `sourcePath` | string | **Yes** | Path to source file, relative to project root |
| `sourcePath` | string | **Yes** | Path to the source file inside the wiki root β€” relative to the wiki root (e.g. `raw/article.md`) or absolute |
| `dryRun` | boolean | No | If `true`, preview the ingest without writing files |
| `force` | boolean | No | If `true`, re-ingest even if the source was previously processed |

Expand All @@ -671,7 +690,7 @@ Ingest result plus enriched context:

| Field | Type | Description |
|-------|------|-------------|
| `ingest` | object | Standard ingest output (`status`, `pages_created`, `pages_updated`, `dry_run`, etc.) |
| `ingest` | object | Standard ingest output (`status`, `pages_created`, `pages_updated`, `dry_run`, etc.). When `status` is `"skipped"` because the source was already ingested, `summary_page` names the existing summary page. |
| `source_word_count` | number | Word count of the source file |
| `source_content_type` | string | Detected content type from file extension (e.g. `"markdown"`, `"pdf"`, `"text"`, `"html"`) |
| `related_pages` | array | Existing wiki pages related to the ingested content (each with `path`, `title`, `score`, `excerpt`) |
Expand Down Expand Up @@ -714,6 +733,100 @@ Ingest result plus enriched context:

---

### `wiki_fix`

Apply every deterministic fix in one pass: delete entity/concept pages whose `sources` were all removed, drop stale index entries, add unlisted pages to the index, and add missing frontmatter defaults. Findings that need judgment (broken links, invalid page types, missing pages) are returned in `remaining`. Successful fixes are logged in `log.md` as `lint-fix`.

Preview with `dryRun` first. The preview lints the wiki as it would be after the deletions, so `remaining` already includes the links those deletions would break. When `removed_pages` is not empty, agents should apply the fixes only after the user approves deleting those pages.

**Input Schema**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `dryRun` | boolean | No | If `true`, report what would change without writing anything |

**Output** (also returned as `structuredContent`)

| Field | Type | Description |
|-------|------|-------------|
| `dry_run` | boolean | Whether this was a preview |
| `removed_pages` | string[] | Derived pages deleted (or that would be deleted) because their sources are gone |
| `fixed` | LintFinding[] | Findings that were fixed |
| `remaining` | LintFinding[] | Findings that still need attention |
| `fixedCount` | number | `fixed.length` |
| `remainingCount` | number | `remaining.length` |

**Example**

```json
// Request
{ "tool": "wiki_fix", "input": { "dryRun": true } }

// Response
{
"command": "fix",
"api_version": "1",
"dry_run": true,
"removed_pages": ["entities/old-vendor.md"],
"fixed": [
{ "severity": "error", "category": "stale-entries", "message": "Stale index entry \"Deleted\" points to missing file \"concepts/deleted.md\"", "file": "concepts/deleted.md" }
],
"remaining": [
{ "severity": "error", "category": "broken-links", "message": "Broken link to \"concepts/missing.md\" in page \"concepts/linked.md\"", "file": "concepts/linked.md" }
],
"fixedCount": 1,
"remainingCount": 1
}
```

---

### `wiki_delete_page`

Delete a wiki page and remove it from the index. Refuses `index.md` and `log.md` (in any letter case), non-markdown files, and paths that leave the wiki directory, including through a symlinked folder. The deletion is logged in `log.md`. Agents should only call it after the user confirms.

**Input Schema**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `pagePath` | string | **Yes** | Relative path within `wiki/` (e.g. `"concepts/ai.md"`) |

**Output**

| Field | Type | Description |
|-------|------|-------------|
| `status` | string | Always `"deleted"` |
| `path` | string | Normalized path of the deleted page |
| `linkedFrom` | array | Pages that still link to it (`page`, `title`, `linkText`), so their links can be fixed |

---

## Workspace Tools

These tools are listed only when the server was started without a wiki root (no argument and no `LLMWIKI_ROOT`), for example from the agent plugin.

### `wiki_open`

Select the wiki to work with. Read-only.

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `path` | string | **Yes** | Absolute path of the project folder that contains `.wiki`, or of the `.wiki` folder itself |

Returns `{ "status": "opened", "wiki_root", "wiki_page_count", "source_count" }`. A folder counts as a wiki when it has `.wiki/wiki/` (the same test `wiki_init` uses). If its `index.md` is missing, `wiki_fix` rebuilds it.

### `wiki_init`

Create a new wiki (`.wiki/` with `raw/`, `wiki/`, `index.md`, `log.md` and `AGENTS.md`) and open it. Does nothing if the folder already has one.

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `path` | string | No | Absolute path of the project folder. Defaults to the first workspace root reported by the client. |

Returns the init result plus `wiki_root`.

---

## Security Model

All MCP tools enforce a layered security model to prevent unauthorized file system access and data corruption.
Expand All @@ -732,6 +845,12 @@ Every tool that reads or writes wiki files validates paths with `assertWithinDir
| **Empty slug rejection** | `wiki_create_entity`, `wiki_create_concept` | Names that produce empty slugs are rejected |
| **Target existence check** | `wiki_add_crosslinks` | All target pages must exist before links are written |
| **Index injection prevention** | `wiki_update_index`, `wiki_write_page` | Upsert pattern prevents duplicate or malformed index entries |
| **Protected files** | `wiki_delete_page` | `index.md`, `log.md` (in any letter case) and non-markdown files cannot be deleted, and the path is checked again after resolving symlinked folders |
| **Source containment** | `wiki_ingest_with_context`, `wiki_create_entity`, `wiki_create_concept`, `wiki_update_page` | Source paths must resolve inside the wiki root; recorded `sources`/`addSources` must be existing pages |

### Concurrent Writes

Tools that read, merge and write a page or `index.md` (for example `wiki_update_page`, `wiki_add_crosslinks`, `wiki_fix` and the create tools with `sources`) hold the wiki write lock, a `wiki/.llmwiki.lock` file. The VS Code extension's ingest and cleanup use the same lock, so two writers in different processes can't overwrite each other's changes. A lock left behind by a process that crashed is removed after 10 seconds.

---

Expand Down Expand Up @@ -788,13 +907,18 @@ Ingest a source file, create a new entity from the findings, and link it to exis

### 3. Maintain Wiki Health

Run a lint pass, fix issues found, and update the index to keep metadata accurate.
Run a lint pass, apply the deterministic fixes, fix what remains, and update the index to keep metadata accurate.

```jsonc
// Step 1 β€” Run lint to discover problems
{ "tool": "wiki_lint", "input": {} }

// Step 2 β€” Fix a page with outdated content
// Step 2 β€” Preview, then apply the deterministic fixes
// (if the preview lists removed_pages, apply only after the user approves)
{ "tool": "wiki_fix", "input": { "dryRun": true } }
{ "tool": "wiki_fix", "input": {} }

// Step 3 β€” Fix a page with outdated content
{
"tool": "wiki_update_page",
"input": {
Expand All @@ -804,7 +928,7 @@ Run a lint pass, fix issues found, and update the index to keep metadata accurat
}
}

// Step 3 β€” Update the index entry to match
// Step 4 β€” Update the index entry to match
{
"tool": "wiki_update_index",
"input": {
Expand Down
4 changes: 2 additions & 2 deletions docs/workflows/smart-ingest.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The agent doesn't just dump raw content into pages β€” it performs a structured
6. **Enrich** existing pages with knowledge from the new source.
7. **Verify** wiki health to catch broken links, missing metadata, or orphan pages.

This workflow uses the `llmwiki` MCP server β€” 14 tools over stdio transport. Launch it via the `llmwiki-mcp` bin shipped by `@llmwiki/core`:
This workflow uses the `llmwiki` MCP server over stdio transport. Launch it via the `llmwiki-mcp` bin shipped by `@llmwiki/core` (in VS Code the extension registers it for you, and the `/wiki-ingest` skill runs this workflow):

```bash
npx -p @llmwiki/core llmwiki-mcp /abs/path/to/your-project/.wiki
Expand Down Expand Up @@ -623,6 +623,6 @@ If `wiki_lint` returns errors after the workflow, inspect each finding:

## See Also

- [MCP Tools Reference](../mcp-tools.md) β€” Full schema documentation for all 14 tools
- [MCP Tools Reference](../mcp-tools.md) β€” Full schema documentation for all tools
- [Model Context Protocol Specification](https://modelcontextprotocol.io/) β€” The MCP protocol standard
- [ARCHITECTURE.md](../../ARCHITECTURE.md) β€” System architecture and the three-layer model
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"scripts": {
"build": "npm run build --workspace=packages/core && npm run build --workspace=packages/vscode",
"test": "vitest run",
"test:integration": "node tests/vscode/integration/build.mjs && node tests/vscode/integration/out/runTest.js",
"coverage": "vitest run --coverage",
"lint": "npm run lint --workspace=packages/core && npm run lint --workspace=packages/vscode",
"dev": "vitest watch"
Expand Down
4 changes: 2 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ See the [main README](https://github.com/microsoft/llmwiki#readme) for the full

## Use as an MCP server

The package ships an `llmwiki-mcp` binary that exposes 14 wiki tools over stdio.
The package ships an `llmwiki-mcp` binary that exposes the wiki tools, resources and prompts over stdio.

```bash
# Direct invocation
Expand All @@ -39,7 +39,7 @@ npx llmwiki-mcp ./.wiki
}
```

The single positional argument is the path to a `.wiki/` directory; it defaults to `./.wiki` when omitted.
The single positional argument (or the `LLMWIKI_ROOT` environment variable) is the path to a `.wiki/` directory. Without it, the server uses `./.wiki` if present, otherwise looks for the wiki in the client's workspace roots, and adds `wiki_open` and `wiki_init` tools so an agent can select or create one.

## License

Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ export const API_VERSION = '1';
* All wiki data (raw/, wiki/, AGENTS.md) lives under this directory.
*/
export const WIKI_DIR_NAME = '.wiki';

/**
* Version of the `@llmwiki/core` package, reported by the MCP server.
* A unit test keeps it in sync with `packages/core/package.json`.
*/
export const CORE_VERSION = '0.1.2';
Loading
Loading