nodebb-plugin-integration
by Sergey-ek
README.md
# NodeBB Integration
AI and MCP integration layer for NodeBB.
The plugin connects NodeBB to AI services, provides permission-aware semantic search over forum content, exposes an OpenAI-compatible API for LLM access, and makes forum functionality available to external AI clients through the Model Context Protocol (MCP).
**Translations:** [Русский](README.ru.md) · [简体中文](README.zh-CN.md)
- **Version:** 0.7.0
- **License:** MIT
- **NodeBB:** 4.x
- **Node.js:** >= 22
## Features
### AI and semantic search
- Independent LLM and Embeddings configurations.
- OpenAI-compatible API support for both LLM and Embeddings providers.
- Configurable API endpoints, API keys, models and request timeouts.
- LLM Chat Completions with streaming support.
- Streaming tool-call support.
- LLM model listing.
- HTML-to-text normalization before embedding generation.
- Configurable embedding dimensions.
- Qdrant vector database integration.
- Automatic indexing of new and updated forum posts.
- Removal of vectors for deleted or otherwise unavailable content.
- Configurable category exclusions.
- Permission-aware semantic search using current NodeBB permissions.
- NodeBB remains the source of truth for post content and access permissions.
### AI API
- OpenAI-compatible API endpoints for model discovery and chat completions.
- Independent AI API authentication token.
- Non-streaming and Server-Sent Events (SSE) streaming responses.
- Support for multimodal messages and tool-call messages forwarded to the configured LLM provider.
- Independent from MCP enablement and MCP authentication.
### MCP and OAuth
- MCP server using Streamable HTTP transport.
- Separate MCP child process managed by the plugin.
- OAuth 2.0 authentication for MCP clients using Authorization Code + PKCE (`S256`).
- CIMD (Client ID Metadata Documents) support for public OAuth clients.
- Explicit per-user consent and MCP access management.
- Legacy static Bearer-token authentication for backward compatibility.
- Separate authentication token for the internal NodeBB API.
- Configurable MCP bind address, port and authentication mode.
- 15 MCP tools for forum information, reading, searching and content management.
### Administration
- NodeBB ACP configuration interface.
- Separate configuration sections for LLM, Embeddings, AI API, Qdrant, indexing and MCP.
- API key configuration status without exposing provider secrets.
- AI API token display, copy and regeneration.
- MCP Bearer token management.
## Requirements
- Node.js >= 22.
- npm >= 10.
- NodeBB >= 4.16.8.
- A running NodeBB instance.
Additional services are required for the corresponding features:
- An LLM provider implementing the OpenAI-compatible Chat Completions API.
- An Embeddings provider implementing the OpenAI-compatible Embeddings API.
- A reachable Qdrant instance for semantic search.
The LLM and Embeddings providers can be configured independently. They may use different services, endpoints, API keys and models.
MCP tools that do not depend on semantic search can be used independently of the LLM, Embeddings and Qdrant configuration. The `search_knowledge` tool requires a working Embeddings provider and Qdrant collection.
The AI API requires a configured LLM provider. It does not require MCP to be enabled.
## Installation
Install the plugin using the NodeBB administration interface or the standard NodeBB plugin installation procedure.
For a manual installation:
```bash
cd /path/to/nodebb
npm install nodebb-plugin-integration
```
Build and restart NodeBB using the standard procedure for your installation.
After installation, open:
**NodeBB ACP → Plugins → NodeBB Integration**
Configure the required options and save the settings.
## Upgrade notes
Version 0.7.0 introduces a new AI configuration and indexing architecture.
**Before using AI features after upgrading:**
1. Configure the LLM Base URL, API key and model.
2. Configure the Embeddings Base URL, API key, model and dimensions.
3. Verify that the configured Qdrant collection uses the same vector dimensions as the Embeddings configuration.
4. Perform a complete reindex of forum content.
Do not assume that previous AI or Embeddings settings are migrated automatically. Configure the new LLM and Embeddings settings explicitly.
The existing Qdrant vectors must be regenerated using the Embeddings model and dimensions configured for 0.7.0. A collection created for a different vector size is incompatible. During indexing, the plugin checks the collection configuration and reports an error instead of silently using an incompatible collection.
A full reindex is required even if the collection already exists and its dimensions match: vectors generated by a different model or configuration should not be mixed with the new embeddings.
The plugin does not automatically migrate old vectors or guarantee that an existing collection contains compatible embeddings.
MCP and OAuth configuration are separate from the new AI configuration. Their settings and authentication flows remain independent of the LLM and Embeddings providers.
## Configuration
The plugin configuration is managed through the NodeBB ACP:
**NodeBB ACP → Plugins → NodeBB Integration**
### LLM
The LLM provider is used for chat completions and the AI API.
| Setting | Description |
|---|---|
| LLM Base URL | OpenAI-compatible API base URL |
| LLM API Key | Provider API key |
| LLM Model | Default chat completion model |
| LLM Timeout | Request timeout in milliseconds |
Default values:
| Setting | Default |
|---|---|
| LLM Base URL | `https://api.openai.com/v1` |
| LLM Model | Empty; must be configured |
| LLM Timeout | `60000` ms |
The provider must implement the OpenAI-compatible Chat Completions API and model listing endpoint.
The API key is sent to the configured LLM provider. It is not returned by the plugin's public configuration endpoints.
For local or self-hosted OpenAI-compatible services, configure the corresponding Base URL and model. The API key may be left empty when the provider does not require authentication.
### Embeddings
Embeddings are configured independently of the LLM.
| Setting | Description |
|---|---|
| Embeddings Base URL | OpenAI-compatible Embeddings API base URL |
| Embeddings API Key | Provider API key |
| Embeddings Model | Embedding model name |
| Embeddings Dimensions | Expected vector size |
| Send Dimensions | Whether to include the `dimensions` parameter in the provider request |
| Embeddings Timeout | Request timeout in milliseconds |
Default values:
| Setting | Default |
|---|---|
| Embeddings Base URL | `https://api.openai.com/v1` |
| Embeddings Model | Empty; must be configured |
| Embeddings Dimensions | `1536` |
| Send Dimensions | Enabled |
| Embeddings Timeout | `60000` ms |
The provider must implement the OpenAI-compatible Embeddings API.
The plugin validates every returned embedding:
- The response must contain an embedding vector.
- The vector length must match the configured dimensions.
- Every vector value must be finite.
If **Send Dimensions** is enabled, the configured dimensions are sent to the provider as the `dimensions` parameter. Disable this option only when the selected provider does not support that parameter and returns vectors of the configured size by default.
The Embeddings API key is independent of the LLM API key. It is not exposed through the public plugin configuration.
### AI API
The plugin provides an OpenAI-compatible API for applications that need to use the configured LLM through NodeBB.
The AI API has its own automatically generated authentication token. This token is independent of:
- The LLM provider API key.
- The Embeddings provider API key.
- MCP OAuth access and refresh tokens.
- The legacy MCP Bearer token.
- The internal NodeBB API token.
The AI API token is displayed in the authenticated ACP configuration page. It can be copied or regenerated there.
Regenerating the token immediately invalidates clients using the previous token.
#### Endpoints
Base path:
`/api/v3/integration/ai/v1`
| Method | Endpoint | Description |
|---|---|---|
| `GET` | `/models` | List models available from the configured LLM provider |
| `POST` | `/chat/completions` | Create a chat completion |
Both endpoints require:
```http
Authorization: Bearer YOUR_AI_API_TOKEN
```
#### List models
```bash
curl https://forum.example.com/api/v3/integration/ai/v1/models \
-H "Authorization: Bearer YOUR_AI_API_TOKEN"
```
The endpoint forwards the model listing request to the configured LLM provider.
#### Chat completion
```bash
curl https://forum.example.com/api/v3/integration/ai/v1/chat/completions \
-H "Authorization: Bearer YOUR_AI_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model",
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}'
```
The `model` field can select a model for an individual request. If omitted, the configured default LLM model is used.
The API forwards the request to the configured provider using the OpenAI-compatible Chat Completions interface.
Messages and supported options are forwarded to the provider. This includes tool-call messages and multimodal message content supported by the selected provider.
#### Streaming
Set `stream` to `true` to receive Server-Sent Events:
```bash
curl -N https://forum.example.com/api/v3/integration/ai/v1/chat/completions \
-H "Authorization: Bearer YOUR_AI_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model",
"stream": true,
"messages": [
{
"role": "user",
"content": "Write a short introduction."
}
]
}'
```
Streaming responses use the `text/event-stream` content type and finish with:
```text
data: [DONE]
```
The API handles client disconnections and response backpressure.
The AI API is available independently of MCP. Disabling MCP does not disable the AI API.
### Qdrant
| Setting | Description |
|---|---|
| Qdrant URL | Qdrant server URL |
| Collection | Collection used to store post vectors |
Default values:
| Setting | Default |
|---|---|
| Qdrant URL | `http://qdrant:6333` |
| Collection | `nodebb_knowledge` |
When indexing a post, the plugin creates the configured collection if it does not exist. New collections use the configured embedding dimensions and Cosine distance.
During indexing, the plugin checks an existing collection's vector size and distance configuration. The collection must use:
- The same vector size as `embeddingDimensions`.
- Cosine distance.
An incompatible collection causes an error. The plugin does not automatically resize or recreate existing collections.
### Search and indexing
The plugin uses embeddings to index forum posts and Qdrant to store and retrieve vectors.
Post content is normalized before embedding generation:
- HTML markup is parsed and removed.
- Script, style, embedded and other non-content elements are skipped.
- Block elements are separated to preserve text structure.
- Code and preformatted content retain their whitespace.
- Text is limited to 30,000 characters before embedding generation.
The indexer handles relevant NodeBB post and topic lifecycle events, including post creation, editing, deletion and restoration, as well as topic deletion, restoration and movement.
Each post is represented by a deterministic vector point ID. Reindexing a post updates its existing point rather than creating a new point.
The indexer removes a post vector when the post or topic is deleted, the post is unavailable, the topic cannot be resolved, the category is invalid, or the category is excluded.
Operations for the same post are serialized within a single NodeBB process to avoid overlapping index and delete operations.
#### Full reindex
The ACP provides a **Start full reindex** action for rebuilding the Qdrant index.
Open **NodeBB ACP → Plugins → NodeBB Integration** and start the operation from the indexing section.
The reindex operation:
1. Takes a snapshot of the current NodeBB post IDs.
2. Processes the posts sequentially and updates their Qdrant points.
3. Tracks processed, indexed, skipped and failed posts.
4. Removes stale Qdrant points only after all posts in the snapshot have been processed successfully.
If any post fails to index, stale-vector cleanup is skipped. This prevents a partially completed reindex from deleting vectors that may still be needed.
The ACP displays the operation status and progress. A new reindex cannot be started while another reindex is running in the same NodeBB process.
**Multi-process limitation:** indexing operations and full reindex state are kept in process memory. They are not coordinated across multiple NodeBB processes. In a multi-process deployment, separate workers may run independent indexing operations or reindex tasks, and status polling may reach a different worker. Distributed coordination is not currently provided.
#### Search permissions
Search results are not returned solely on the basis of vector similarity.
Before returning a result, the plugin checks whether the acting NodeBB user can read both the corresponding post and topic. It then retrieves current post and topic data from NodeBB and validates that the content is still available and belongs to the expected topic and category.
Excluded Categories allows selected categories to be omitted from indexing and semantic search.
Qdrant is used as the vector index; NodeBB remains the source of post content and access permissions.
## MCP server
MCP settings are managed through:
**NodeBB ACP → Plugins → NodeBB Integration**
| Setting | Description |
|---|---|
| Enable MCP | Enables or disables the MCP server |
| Authentication mode | OAuth 2.0 or Legacy Bearer Token |
| Bind address | Address on which the MCP HTTP server listens |
| Port | MCP HTTP port |
| NodeBB URL | Internal URL used by the MCP process to reach NodeBB |
| Bearer token | Shared authentication token; used only in Legacy Bearer mode |
| Service user UID | NodeBB account used for MCP operations; used only in Legacy Bearer mode |
OAuth 2.0 is the default authentication mode. Each MCP client authorizes a specific NodeBB user. MCP operations then run with that user's identity and permissions.
Legacy Bearer Token mode is retained for backward compatibility. In this mode, all clients share the configured Bearer token and MCP operations run as the configured service user.
Default MCP connection settings:
```text
Bind address: 127.0.0.1
Port: 3100
NodeBB URL: http://127.0.0.1:4567
```
The default bind address restricts the MCP listener to localhost. Change it only when remote access is intentionally required and the network exposure is secured.
When exposing MCP through a reverse proxy, publish the external `/mcp` endpoint over HTTPS.
### Nginx reverse proxy
Add this location inside the existing HTTPS `server` block for your forum. Keep the regular NodeBB proxy location (usually `location /`) so that the OAuth authorization and metadata endpoints continue to be handled by NodeBB.
```nginx
location = /mcp {
proxy_pass http://nodebb:3100;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Connection "";
# Required for MCP Streamable HTTP responses.
proxy_buffering off;
proxy_request_buffering off;
proxy_cache off;
# Allow long-running MCP requests and streams.
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
```
The example assumes that Nginx and the NodeBB container are connected to the same Docker network and that the MCP process is reachable as `nodebb:3100`. In the plugin ACP, set **Bind address** to `0.0.0.0` for this container-to-container setup. Do not publish port 3100 to the public host; keep it accessible only on the private Docker network.
If Nginx runs directly on the same host and shares the host network namespace with the MCP process, use `proxy_pass http://127.0.0.1:3100;` and keep **Bind address** set to `127.0.0.1`.
The location is an exact match and the `proxy_pass` directive has no URI suffix, so Nginx forwards the original `/mcp` path unchanged. Do not route the OAuth `/.well-known` endpoints to port 3100; they are served by NodeBB through the regular forum proxy location.
Keep your existing ACME HTTP-01 challenge handling for `/.well-known/acme-challenge/` unchanged (for example, the Certbot webroot or standalone configuration). Do not route ACME challenge requests to the MCP port. The OAuth metadata paths, such as `/.well-known/oauth-authorization-server` and `/.well-known/oauth-protected-resource/mcp`, are separate from the ACME challenge path.
The plugin automatically generates a separate random token for its internal API. This token is used only between the MCP process and the NodeBB plugin. It is distinct from the client access token and must never be shared with MCP clients.
In OAuth mode, users manage their MCP access and revoke individual client grants from their NodeBB account page:
`/user/<userslug>/integration`
## MCP authentication
### OAuth 2.0
OAuth 2.0 is the default authentication mode.
The plugin implements the OAuth 2.0 Authorization Code flow with PKCE (`S256`). MCP clients are public clients and do not use a client secret.
The authorization server exposes its metadata at:
`https://forum.example.com/.well-known/oauth-authorization-server`
The plugin supports Client ID Metadata Documents (CIMD). A client identifies itself using an HTTPS URL that points to its metadata document.
The protected resource metadata endpoint is:
`https://forum.example.com/.well-known/oauth-protected-resource/mcp`
When a user connects a new client:
1. The plugin retrieves and validates the client's metadata.
2. The user authenticates with NodeBB.
3. NodeBB displays a consent screen.
4. After the user approves access, the client is automatically authorized for that user.
A previously approved client does not require consent again while its authorization grant and client metadata remain valid. If the grant is revoked or the client's metadata changes, the user must approve authorization again.
Each OAuth client acts as the NodeBB user who authorized it. The user's NodeBB permissions apply to MCP operations.
OAuth token lifetimes:
| Token | Lifetime |
|---|---|
| Authorization code | 5 minutes |
| Access token | 15 minutes |
| Refresh token | 30 days |
Refresh tokens are rotated when used.
Users can manage MCP access from their NodeBB account page. They can disable MCP access globally or revoke individual client grants. Disabling global access invalidates existing tokens. Enabling access again requires clients to authorize again.
### Legacy Bearer Token
Legacy Bearer Token mode is provided for backward compatibility.
In this mode, all MCP clients use the same configured static Bearer token. MCP operations run as the NodeBB account specified by the Service user UID setting.
Use this mode only when compatibility with an existing Bearer-token integration is required.
## MCP tools
The MCP server provides 15 tools:
| Tool | Description |
|---|---|
| `get_forum_info` | Get public forum information |
| `get_post` | Read a post |
| `get_topic` | Read topic metadata |
| `get_user` | Read public user profile fields |
| `search_knowledge` | Search indexed forum content semantically |
| `create_topic` | Create a topic |
| `delete_topic` | Soft-delete a topic |
| `restore_topic` | Restore a topic |
| `list_topics` | List accessible topics |
| `create_post` | Create a reply |
| `edit_post` | Edit a post |
| `delete_post` | Soft-delete a post |
| `restore_post` | Restore a post |
| `delete_user_posts` | Soft-delete a user's replies in batches |
| `list_posts` | List posts in a topic |
All write operations use native NodeBB methods and permission checks.
Deletion tools perform soft deletion, not permanent data removal. `delete_user_posts` skips the first post of every topic. Restoring a topic does not automatically restore posts that were separately deleted.
See the complete reference for argument schemas, defaults, limits, response fields, permissions, pagination and examples:
- [MCP API Reference (English)](docs/MCP.md)
- [Справочник MCP API (Русский)](docs/MCP.ru.md)
## Security
- OAuth 2.0 is the default MCP authentication mode. It uses Authorization Code + PKCE (`S256`) and explicit user consent.
- OAuth access tokens expire after 15 minutes. Refresh tokens have a 30-day lifetime and are rotated when used.
- OAuth client metadata is retrieved from HTTPS CIMD URLs. The plugin validates public DNS addresses and TLS certificates when fetching metadata.
- Users can disable their MCP access globally or revoke individual client grants.
- Legacy Bearer mode uses a shared static token and a configured service account. Use it only when backward compatibility is required.
- The internal NodeBB API uses a separate automatically generated token. Never expose this token to MCP clients.
- The AI API uses its own token, separate from MCP and provider credentials.
- LLM and Embeddings provider API keys are not returned by public plugin configuration endpoints.
- Internal API routes require authentication and are disabled when MCP is disabled.
- The default MCP bind address is `127.0.0.1`.
- Read and write operations use NodeBB permissions for the authenticated OAuth user or the configured legacy service user.
- Semantic search filters results by the acting user's permissions.
- Public user lookup returns only the selected profile fields.
- Secret values are not included in the plugin's public configuration information.
Use HTTPS for externally accessible MCP and OAuth endpoints. Do not expose the internal API token. In Legacy Bearer mode, protect the shared token as a credential with access to the configured service account. Protect the AI API token as a separate credential for LLM access through the plugin.
## Development
Install dependencies:
```bash
npm install
```
Run syntax checks:
```bash
npm run check
```
Run the test suite:
```bash
npm test
```
The tests cover API authentication, API handlers, argument validation, MCP tool behavior, AI API requests and streaming, and AI-related components.
## Project structure
```text
.
├── library.js
├── plugin.json
├── package.json
├── README.md
├── README.ru.md
├── docs/
│ ├── MCP.md
│ └── MCP.ru.md
├── src/
│ ├── ai/
│ │ ├── embeddings/
│ │ ├── llm/
│ │ ├── embeddings.js
│ │ ├── index.js
│ │ ├── indexer.js
│ │ ├── qdrant.js
│ │ ├── reindex.js
│ │ └── search.js
│ ├── config/
│ ├── mcp/
│ ├── nodebb/
│ ├── oauth/
│ └── routes/
│ └── ai-api.js
├── public/
├── languages/
└── test/
```
## Compatibility
Minimum tested NodeBB version: 4.16.8. Earlier versions have not been verified.
The plugin requires Node.js >= 22. Native NodeBB response fields and hooks may vary between NodeBB versions.
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues