docusaurus-plugin-mcp-server 0.5.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 +505 -0
- package/dist/adapters-entry.d.mts +180 -0
- package/dist/adapters-entry.d.ts +180 -0
- package/dist/adapters-entry.js +918 -0
- package/dist/adapters-entry.js.map +1 -0
- package/dist/adapters-entry.mjs +908 -0
- package/dist/adapters-entry.mjs.map +1 -0
- package/dist/cli/verify.d.mts +1 -0
- package/dist/cli/verify.d.ts +1 -0
- package/dist/cli/verify.js +710 -0
- package/dist/cli/verify.js.map +1 -0
- package/dist/cli/verify.mjs +702 -0
- package/dist/cli/verify.mjs.map +1 -0
- package/dist/index-CzA4FjeE.d.mts +190 -0
- package/dist/index-CzA4FjeE.d.ts +190 -0
- package/dist/index.d.mts +234 -0
- package/dist/index.d.ts +234 -0
- package/dist/index.js +1070 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1037 -0
- package/dist/index.mjs.map +1 -0
- package/dist/theme/index.d.mts +87 -0
- package/dist/theme/index.d.ts +87 -0
- package/dist/theme/index.js +299 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/index.mjs +291 -0
- package/dist/theme/index.mjs.map +1 -0
- package/package.json +145 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Steve Calvert
|
|
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,505 @@
|
|
|
1
|
+
# docusaurus-plugin-mcp-server
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
[](https://badge.fury.io/js/docusaurus-plugin-mcp-server)
|
|
5
|
+
[](https://github.com/scalvert/docusaurus-plugin-mcp-server/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
A Docusaurus plugin that exposes an [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server endpoint, allowing AI agents like Claude, Cursor, and other MCP-compatible tools to search and retrieve your documentation.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install docusaurus-plugin-mcp-server
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### 1. Add the Plugin
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
// docusaurus.config.js
|
|
21
|
+
module.exports = {
|
|
22
|
+
plugins: [
|
|
23
|
+
[
|
|
24
|
+
'docusaurus-plugin-mcp-server',
|
|
25
|
+
{
|
|
26
|
+
server: {
|
|
27
|
+
name: 'my-docs',
|
|
28
|
+
version: '1.0.0',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Create the API Endpoint
|
|
37
|
+
|
|
38
|
+
Choose your deployment platform:
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><strong>Vercel</strong></summary>
|
|
42
|
+
|
|
43
|
+
Create `api/mcp.js`:
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const { createVercelHandler } = require('docusaurus-plugin-mcp-server/adapters');
|
|
47
|
+
const path = require('path');
|
|
48
|
+
|
|
49
|
+
module.exports = createVercelHandler({
|
|
50
|
+
docsPath: path.join(__dirname, '../build/mcp/docs.json'),
|
|
51
|
+
indexPath: path.join(__dirname, '../build/mcp/search-index.json'),
|
|
52
|
+
name: 'my-docs',
|
|
53
|
+
baseUrl: 'https://docs.example.com',
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Add to `vercel.json`:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"functions": {
|
|
62
|
+
"api/mcp.js": {
|
|
63
|
+
"includeFiles": "build/mcp/**"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"rewrites": [
|
|
67
|
+
{ "source": "/mcp", "destination": "/api/mcp" }
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
</details>
|
|
73
|
+
|
|
74
|
+
<details>
|
|
75
|
+
<summary><strong>Netlify</strong></summary>
|
|
76
|
+
|
|
77
|
+
Create `netlify/functions/mcp.js`:
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
const { createNetlifyHandler } = require('docusaurus-plugin-mcp-server/adapters');
|
|
81
|
+
const path = require('path');
|
|
82
|
+
|
|
83
|
+
exports.handler = createNetlifyHandler({
|
|
84
|
+
docsPath: path.join(__dirname, '../../build/mcp/docs.json'),
|
|
85
|
+
indexPath: path.join(__dirname, '../../build/mcp/search-index.json'),
|
|
86
|
+
name: 'my-docs',
|
|
87
|
+
baseUrl: 'https://docs.example.com',
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Add to `netlify.toml`:
|
|
92
|
+
|
|
93
|
+
```toml
|
|
94
|
+
[build]
|
|
95
|
+
publish = "build"
|
|
96
|
+
|
|
97
|
+
[functions]
|
|
98
|
+
directory = "netlify/functions"
|
|
99
|
+
included_files = ["build/mcp/**"]
|
|
100
|
+
|
|
101
|
+
[[redirects]]
|
|
102
|
+
from = "/mcp"
|
|
103
|
+
to = "/.netlify/functions/mcp"
|
|
104
|
+
status = 200
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
</details>
|
|
108
|
+
|
|
109
|
+
<details>
|
|
110
|
+
<summary><strong>Cloudflare Workers</strong></summary>
|
|
111
|
+
|
|
112
|
+
Cloudflare Workers can't access the filesystem, so you need to import the data directly:
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
import { createCloudflareHandler } from 'docusaurus-plugin-mcp-server/adapters';
|
|
116
|
+
import docs from '../build/mcp/docs.json';
|
|
117
|
+
import searchIndex from '../build/mcp/search-index.json';
|
|
118
|
+
|
|
119
|
+
export default {
|
|
120
|
+
fetch: createCloudflareHandler({
|
|
121
|
+
docs,
|
|
122
|
+
searchIndexData: searchIndex,
|
|
123
|
+
name: 'my-docs',
|
|
124
|
+
baseUrl: 'https://docs.example.com',
|
|
125
|
+
}),
|
|
126
|
+
};
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
</details>
|
|
130
|
+
|
|
131
|
+
### 3. Build and Deploy
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
npm run build
|
|
135
|
+
# Deploy to your platform
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 4. Connect Your AI Tool
|
|
139
|
+
|
|
140
|
+
**Claude Code:**
|
|
141
|
+
```bash
|
|
142
|
+
claude mcp add --transport http my-docs https://docs.example.com/mcp
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Cursor / VS Code:**
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"mcpServers": {
|
|
149
|
+
"my-docs": {
|
|
150
|
+
"url": "https://docs.example.com/mcp"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 5. Add an Install Button (Optional)
|
|
157
|
+
|
|
158
|
+
Add a dropdown button to your docs site so users can easily install the MCP server in their AI tool:
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import { McpInstallButton } from 'docusaurus-plugin-mcp-server/theme';
|
|
162
|
+
|
|
163
|
+
function NavbarItems() {
|
|
164
|
+
return (
|
|
165
|
+
<McpInstallButton
|
|
166
|
+
serverUrl="https://docs.example.com/mcp"
|
|
167
|
+
serverName="my-docs"
|
|
168
|
+
/>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The button shows a dropdown with copy-to-clipboard configurations for all supported MCP clients (Claude Code, Cursor, VS Code, Windsurf, Claude Desktop).
|
|
174
|
+
|
|
175
|
+
**Props:**
|
|
176
|
+
|
|
177
|
+
| Prop | Type | Default | Description |
|
|
178
|
+
|------|------|---------|-------------|
|
|
179
|
+
| `serverUrl` | `string` | required | Your MCP server endpoint URL |
|
|
180
|
+
| `serverName` | `string` | required | Name for the MCP server |
|
|
181
|
+
| `label` | `string` | `"Install MCP"` | Button label |
|
|
182
|
+
| `className` | `string` | `""` | Optional CSS class |
|
|
183
|
+
| `clients` | `ClientId[]` | All HTTP-capable | Which clients to show |
|
|
184
|
+
|
|
185
|
+
## MCP Tools
|
|
186
|
+
|
|
187
|
+
The server exposes three tools for AI agents:
|
|
188
|
+
|
|
189
|
+
### `docs_search`
|
|
190
|
+
|
|
191
|
+
Search across documentation with relevance ranking.
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{
|
|
195
|
+
"name": "docs_search",
|
|
196
|
+
"arguments": {
|
|
197
|
+
"query": "authentication",
|
|
198
|
+
"limit": 5
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
| Parameter | Type | Default | Description |
|
|
204
|
+
|-----------|------|---------|-------------|
|
|
205
|
+
| `query` | `string` | required | Search query |
|
|
206
|
+
| `limit` | `number` | `5` | Max results (1-20) |
|
|
207
|
+
|
|
208
|
+
### `docs_get_page`
|
|
209
|
+
|
|
210
|
+
Retrieve full page content as markdown.
|
|
211
|
+
|
|
212
|
+
```json
|
|
213
|
+
{
|
|
214
|
+
"name": "docs_get_page",
|
|
215
|
+
"arguments": {
|
|
216
|
+
"route": "/docs/authentication"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
| Parameter | Type | Description |
|
|
222
|
+
|-----------|------|-------------|
|
|
223
|
+
| `route` | `string` | Page route path |
|
|
224
|
+
|
|
225
|
+
### `docs_get_section`
|
|
226
|
+
|
|
227
|
+
Retrieve a specific section by heading ID.
|
|
228
|
+
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"name": "docs_get_section",
|
|
232
|
+
"arguments": {
|
|
233
|
+
"route": "/docs/authentication",
|
|
234
|
+
"headingId": "oauth-configuration"
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
| Parameter | Type | Description |
|
|
240
|
+
|-----------|------|-------------|
|
|
241
|
+
| `route` | `string` | Page route path |
|
|
242
|
+
| `headingId` | `string` | Heading ID to extract |
|
|
243
|
+
|
|
244
|
+
## Plugin Options
|
|
245
|
+
|
|
246
|
+
| Option | Type | Default | Description |
|
|
247
|
+
|--------|------|---------|-------------|
|
|
248
|
+
| `outputDir` | `string` | `'mcp'` | Output directory for MCP artifacts (relative to build dir) |
|
|
249
|
+
| `contentSelectors` | `string[]` | `['article', 'main', ...]` | CSS selectors for finding content |
|
|
250
|
+
| `excludeSelectors` | `string[]` | `['nav', 'header', ...]` | CSS selectors for elements to remove |
|
|
251
|
+
| `minContentLength` | `number` | `50` | Minimum content length to consider a page valid |
|
|
252
|
+
| `server.name` | `string` | `'docs-mcp-server'` | Name of the MCP server |
|
|
253
|
+
| `server.version` | `string` | `'1.0.0'` | Version of the MCP server |
|
|
254
|
+
| `excludeRoutes` | `string[]` | `['/404*', '/search*']` | Routes to exclude (glob patterns) |
|
|
255
|
+
|
|
256
|
+
### Default Selectors
|
|
257
|
+
|
|
258
|
+
**Content selectors** (in priority order):
|
|
259
|
+
```javascript
|
|
260
|
+
['article', 'main', '.main-wrapper', '[role="main"]']
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Exclude selectors**:
|
|
264
|
+
```javascript
|
|
265
|
+
['nav', 'header', 'footer', 'aside', '[role="navigation"]', '[role="banner"]', '[role="contentinfo"]']
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Server Configuration
|
|
269
|
+
|
|
270
|
+
For the runtime adapters:
|
|
271
|
+
|
|
272
|
+
| Option | Type | Required | Description |
|
|
273
|
+
|--------|------|----------|-------------|
|
|
274
|
+
| `docsPath` | `string` | Yes* | Path to `docs.json` |
|
|
275
|
+
| `indexPath` | `string` | Yes* | Path to `search-index.json` |
|
|
276
|
+
| `docs` | `object` | Yes* | Pre-loaded docs (Cloudflare) |
|
|
277
|
+
| `searchIndexData` | `object` | Yes* | Pre-loaded search index (Cloudflare) |
|
|
278
|
+
| `name` | `string` | Yes | Server name |
|
|
279
|
+
| `version` | `string` | No | Server version |
|
|
280
|
+
| `baseUrl` | `string` | No | Base URL for full page URLs in responses |
|
|
281
|
+
|
|
282
|
+
*Use either file paths (Node.js) or pre-loaded data (Workers).
|
|
283
|
+
|
|
284
|
+
## Verifying Your Build
|
|
285
|
+
|
|
286
|
+
After running `npm run build`, use the included CLI to verify the MCP output:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
npx docusaurus-mcp-verify
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
This checks that:
|
|
293
|
+
- All required files exist (`docs.json`, `search-index.json`, `manifest.json`)
|
|
294
|
+
- Document structure is valid
|
|
295
|
+
- The MCP server can initialize and load the content
|
|
296
|
+
|
|
297
|
+
You can specify a custom build directory:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
npx docusaurus-mcp-verify ./custom-build
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Example output:
|
|
304
|
+
|
|
305
|
+
```
|
|
306
|
+
🔍 MCP Build Verification
|
|
307
|
+
==================================================
|
|
308
|
+
Build directory: /path/to/your/project/build
|
|
309
|
+
|
|
310
|
+
📁 Checking build output...
|
|
311
|
+
✓ Found 42 documents
|
|
312
|
+
✓ All required files present
|
|
313
|
+
✓ File structure valid
|
|
314
|
+
|
|
315
|
+
🚀 Testing MCP server...
|
|
316
|
+
✓ Server initialized with 42 documents
|
|
317
|
+
|
|
318
|
+
✅ All checks passed!
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Testing the Endpoint
|
|
322
|
+
|
|
323
|
+
The easiest way to test your MCP server is with the official MCP Inspector:
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
npx @modelcontextprotocol/inspector
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
This opens a visual interface where you can:
|
|
330
|
+
- Connect to your server URL
|
|
331
|
+
- Browse available tools
|
|
332
|
+
- Execute tool calls interactively
|
|
333
|
+
- View responses in a formatted display
|
|
334
|
+
|
|
335
|
+
Alternatively, test with curl:
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
# List available tools
|
|
339
|
+
curl -X POST https://docs.example.com/mcp \
|
|
340
|
+
-H "Content-Type: application/json" \
|
|
341
|
+
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
|
|
342
|
+
|
|
343
|
+
# Search documentation
|
|
344
|
+
curl -X POST https://docs.example.com/mcp \
|
|
345
|
+
-H "Content-Type: application/json" \
|
|
346
|
+
-d '{
|
|
347
|
+
"jsonrpc":"2.0",
|
|
348
|
+
"id":2,
|
|
349
|
+
"method":"tools/call",
|
|
350
|
+
"params":{
|
|
351
|
+
"name":"docs_search",
|
|
352
|
+
"arguments":{"query":"getting started"}
|
|
353
|
+
}
|
|
354
|
+
}'
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## How It Works
|
|
358
|
+
|
|
359
|
+
```mermaid
|
|
360
|
+
flowchart LR
|
|
361
|
+
subgraph Build["Build Time"]
|
|
362
|
+
A[Docusaurus Build] --> B[postBuild Hook]
|
|
363
|
+
B --> C[Extract Content]
|
|
364
|
+
C --> D[Build Search Index]
|
|
365
|
+
D --> E[Write Artifacts]
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
subgraph Artifacts["build/mcp/"]
|
|
369
|
+
F[docs.json]
|
|
370
|
+
G[search-index.json]
|
|
371
|
+
H[manifest.json]
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
subgraph Runtime["Runtime"]
|
|
375
|
+
I[Serverless Function]
|
|
376
|
+
J[MCP Server]
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
subgraph Clients["AI Agents"]
|
|
380
|
+
K[Claude]
|
|
381
|
+
L[Cursor]
|
|
382
|
+
M[Other MCP Clients]
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
E --> F & G & H
|
|
386
|
+
F & G --> I
|
|
387
|
+
I --> J
|
|
388
|
+
K & L & M <-->|MCP Protocol| J
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
The plugin operates in two phases:
|
|
392
|
+
|
|
393
|
+
**Build Time:** During `docusaurus build`, the plugin's `postBuild` hook processes all rendered HTML pages, extracts content, converts to markdown, builds a FlexSearch index, and outputs artifacts to `build/mcp/`.
|
|
394
|
+
|
|
395
|
+
**Runtime:** A serverless function loads the pre-built artifacts and handles MCP JSON-RPC requests from AI agents. The server is stateless and fast since all indexing happens at build time.
|
|
396
|
+
|
|
397
|
+
## Features
|
|
398
|
+
|
|
399
|
+
- **Full-text Search** - FlexSearch-powered search with relevance ranking
|
|
400
|
+
- **Page Retrieval** - Get complete page content as clean markdown
|
|
401
|
+
- **Section Extraction** - Retrieve specific sections by heading ID
|
|
402
|
+
- **Platform Adapters** - Pre-built adapters for Vercel, Netlify, and Cloudflare Workers
|
|
403
|
+
- **Build-time Processing** - Extracts content from rendered HTML, capturing React component output
|
|
404
|
+
- **Zero Runtime Docusaurus Dependency** - The MCP server runs independently
|
|
405
|
+
|
|
406
|
+
## Local Development
|
|
407
|
+
|
|
408
|
+
Run a local HTTP server for testing:
|
|
409
|
+
|
|
410
|
+
```javascript
|
|
411
|
+
// mcp-server.mjs
|
|
412
|
+
import http from 'http';
|
|
413
|
+
import { McpDocsServer } from 'docusaurus-plugin-mcp-server';
|
|
414
|
+
import path from 'path';
|
|
415
|
+
import { fileURLToPath } from 'url';
|
|
416
|
+
|
|
417
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
418
|
+
|
|
419
|
+
const server = new McpDocsServer({
|
|
420
|
+
docsPath: path.join(__dirname, 'build/mcp/docs.json'),
|
|
421
|
+
indexPath: path.join(__dirname, 'build/mcp/search-index.json'),
|
|
422
|
+
name: 'my-docs',
|
|
423
|
+
baseUrl: 'http://localhost:3000',
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
http.createServer(async (req, res) => {
|
|
427
|
+
if (req.method !== 'POST') {
|
|
428
|
+
res.writeHead(405);
|
|
429
|
+
res.end();
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
let body = '';
|
|
434
|
+
req.on('data', (chunk) => (body += chunk));
|
|
435
|
+
req.on('end', async () => {
|
|
436
|
+
const response = await server.handleRequest(JSON.parse(body));
|
|
437
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
438
|
+
res.end(JSON.stringify(response));
|
|
439
|
+
});
|
|
440
|
+
}).listen(3456, () => {
|
|
441
|
+
console.log('MCP server at http://localhost:3456');
|
|
442
|
+
});
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
Connect Claude Code:
|
|
446
|
+
```bash
|
|
447
|
+
claude mcp add --transport http my-docs http://localhost:3456
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
## API Reference
|
|
451
|
+
|
|
452
|
+
### Main Exports
|
|
453
|
+
|
|
454
|
+
```javascript
|
|
455
|
+
import {
|
|
456
|
+
// Docusaurus plugin (default export)
|
|
457
|
+
mcpServerPlugin,
|
|
458
|
+
|
|
459
|
+
// MCP Server class
|
|
460
|
+
McpDocsServer,
|
|
461
|
+
|
|
462
|
+
// Tool definitions
|
|
463
|
+
docsSearchTool,
|
|
464
|
+
docsGetPageTool,
|
|
465
|
+
docsGetSectionTool,
|
|
466
|
+
|
|
467
|
+
// Utilities
|
|
468
|
+
htmlToMarkdown,
|
|
469
|
+
extractContent,
|
|
470
|
+
extractHeadingsFromMarkdown,
|
|
471
|
+
buildSearchIndex,
|
|
472
|
+
|
|
473
|
+
// Default options
|
|
474
|
+
DEFAULT_OPTIONS,
|
|
475
|
+
} from 'docusaurus-plugin-mcp-server';
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### Adapter Exports
|
|
479
|
+
|
|
480
|
+
```javascript
|
|
481
|
+
import {
|
|
482
|
+
createVercelHandler,
|
|
483
|
+
createNetlifyHandler,
|
|
484
|
+
createCloudflareHandler,
|
|
485
|
+
generateAdapterFiles,
|
|
486
|
+
} from 'docusaurus-plugin-mcp-server/adapters';
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### Theme Exports
|
|
490
|
+
|
|
491
|
+
```tsx
|
|
492
|
+
import {
|
|
493
|
+
McpInstallButton,
|
|
494
|
+
type McpInstallButtonProps,
|
|
495
|
+
} from 'docusaurus-plugin-mcp-server/theme';
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
## Requirements
|
|
499
|
+
|
|
500
|
+
- Node.js >= 20
|
|
501
|
+
- Docusaurus 3.x
|
|
502
|
+
|
|
503
|
+
## License
|
|
504
|
+
|
|
505
|
+
MIT
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { M as McpServerConfig, P as ProcessedDoc } from './index-CzA4FjeE.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Vercel adapter for MCP server
|
|
6
|
+
*
|
|
7
|
+
* Creates a Vercel serverless function handler for the MCP server.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // api/mcp.js
|
|
11
|
+
* const { createVercelHandler } = require('docusaurus-plugin-mcp-server/adapters');
|
|
12
|
+
* const path = require('path');
|
|
13
|
+
*
|
|
14
|
+
* module.exports = createVercelHandler({
|
|
15
|
+
* docsPath: path.join(__dirname, '../build/mcp/docs.json'),
|
|
16
|
+
* indexPath: path.join(__dirname, '../build/mcp/search-index.json'),
|
|
17
|
+
* name: 'my-docs',
|
|
18
|
+
* baseUrl: 'https://docs.example.com',
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Vercel request object (extends Node.js IncomingMessage)
|
|
24
|
+
*/
|
|
25
|
+
interface VercelRequest extends IncomingMessage {
|
|
26
|
+
body?: unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Vercel response object (extends Node.js ServerResponse)
|
|
30
|
+
*/
|
|
31
|
+
interface VercelResponse extends ServerResponse {
|
|
32
|
+
status(code: number): VercelResponse;
|
|
33
|
+
json(data: unknown): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a Vercel serverless function handler for the MCP server
|
|
37
|
+
*
|
|
38
|
+
* Uses the MCP SDK's StreamableHTTPServerTransport for proper protocol handling.
|
|
39
|
+
*/
|
|
40
|
+
declare function createVercelHandler(config: McpServerConfig): (req: VercelRequest, res: VercelResponse) => Promise<void>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Netlify adapter for MCP server
|
|
44
|
+
*
|
|
45
|
+
* Creates a Netlify serverless function handler for the MCP server.
|
|
46
|
+
* Converts Netlify's AWS Lambda-style events to Web Standard Request
|
|
47
|
+
* and uses the MCP SDK's transport for proper protocol handling.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // netlify/functions/mcp.js
|
|
51
|
+
* const { createNetlifyHandler } = require('docusaurus-plugin-mcp-server/adapters');
|
|
52
|
+
* const path = require('path');
|
|
53
|
+
*
|
|
54
|
+
* exports.handler = createNetlifyHandler({
|
|
55
|
+
* docsPath: path.join(__dirname, '../../build/mcp/docs.json'),
|
|
56
|
+
* indexPath: path.join(__dirname, '../../build/mcp/search-index.json'),
|
|
57
|
+
* name: 'my-docs',
|
|
58
|
+
* baseUrl: 'https://docs.example.com',
|
|
59
|
+
* });
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Netlify event object (simplified interface)
|
|
64
|
+
*/
|
|
65
|
+
interface NetlifyEvent {
|
|
66
|
+
httpMethod: string;
|
|
67
|
+
headers: Record<string, string | undefined>;
|
|
68
|
+
body: string | null;
|
|
69
|
+
isBase64Encoded?: boolean;
|
|
70
|
+
path?: string;
|
|
71
|
+
rawUrl?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Netlify context object (simplified interface)
|
|
75
|
+
*/
|
|
76
|
+
interface NetlifyContext {
|
|
77
|
+
functionName: string;
|
|
78
|
+
functionVersion?: string;
|
|
79
|
+
invokedFunctionArn?: string;
|
|
80
|
+
memoryLimitInMB?: string;
|
|
81
|
+
awsRequestId?: string;
|
|
82
|
+
logGroupName?: string;
|
|
83
|
+
logStreamName?: string;
|
|
84
|
+
getRemainingTimeInMillis?: () => number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Netlify function response
|
|
88
|
+
*/
|
|
89
|
+
interface NetlifyResponse {
|
|
90
|
+
statusCode: number;
|
|
91
|
+
headers?: Record<string, string>;
|
|
92
|
+
body?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create a Netlify serverless function handler for the MCP server
|
|
96
|
+
*
|
|
97
|
+
* Uses the MCP SDK's WebStandardStreamableHTTPServerTransport for
|
|
98
|
+
* proper protocol handling.
|
|
99
|
+
*/
|
|
100
|
+
declare function createNetlifyHandler(config: McpServerConfig): (event: NetlifyEvent, _context: NetlifyContext) => Promise<NetlifyResponse>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Cloudflare Workers adapter for MCP server
|
|
104
|
+
*
|
|
105
|
+
* Creates a Cloudflare Workers fetch handler for the MCP server.
|
|
106
|
+
* Since Workers can't access the filesystem, this adapter requires
|
|
107
|
+
* pre-loaded docs and search index data.
|
|
108
|
+
*
|
|
109
|
+
* Uses the MCP SDK's WebStandardStreamableHTTPServerTransport for proper
|
|
110
|
+
* protocol handling with Web Standard Request/Response.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* // src/worker.js
|
|
114
|
+
* import { createCloudflareHandler } from 'docusaurus-plugin-mcp-server/adapters';
|
|
115
|
+
* import docs from '../build/mcp/docs.json';
|
|
116
|
+
* import searchIndex from '../build/mcp/search-index.json';
|
|
117
|
+
*
|
|
118
|
+
* export default {
|
|
119
|
+
* fetch: createCloudflareHandler({
|
|
120
|
+
* docs,
|
|
121
|
+
* searchIndexData: searchIndex,
|
|
122
|
+
* name: 'my-docs',
|
|
123
|
+
* baseUrl: 'https://docs.example.com',
|
|
124
|
+
* }),
|
|
125
|
+
* };
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Config for Cloudflare Workers adapter
|
|
130
|
+
*/
|
|
131
|
+
interface CloudflareAdapterConfig {
|
|
132
|
+
/** Pre-loaded docs data (imported from docs.json) */
|
|
133
|
+
docs: Record<string, ProcessedDoc>;
|
|
134
|
+
/** Pre-loaded search index data (imported from search-index.json) */
|
|
135
|
+
searchIndexData: Record<string, unknown>;
|
|
136
|
+
/** Server name */
|
|
137
|
+
name: string;
|
|
138
|
+
/** Server version */
|
|
139
|
+
version?: string;
|
|
140
|
+
/** Base URL for constructing full page URLs */
|
|
141
|
+
baseUrl?: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create a Cloudflare Workers fetch handler for the MCP server
|
|
145
|
+
*
|
|
146
|
+
* Uses the MCP SDK's WebStandardStreamableHTTPServerTransport for
|
|
147
|
+
* proper protocol handling.
|
|
148
|
+
*/
|
|
149
|
+
declare function createCloudflareHandler(config: CloudflareAdapterConfig): (request: Request) => Promise<Response>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Adapter file generator
|
|
153
|
+
*
|
|
154
|
+
* Generates platform-specific adapter files for deploying the MCP server.
|
|
155
|
+
*/
|
|
156
|
+
type Platform = 'vercel' | 'netlify' | 'cloudflare';
|
|
157
|
+
interface GeneratorOptions {
|
|
158
|
+
/** Target platform */
|
|
159
|
+
platform: Platform;
|
|
160
|
+
/** Server name */
|
|
161
|
+
name: string;
|
|
162
|
+
/** Base URL for the documentation site */
|
|
163
|
+
baseUrl: string;
|
|
164
|
+
/** Output path for the generated files (defaults to current directory) */
|
|
165
|
+
outputPath?: string;
|
|
166
|
+
}
|
|
167
|
+
interface GeneratedFile {
|
|
168
|
+
/** Relative path for the file */
|
|
169
|
+
path: string;
|
|
170
|
+
/** File contents */
|
|
171
|
+
content: string;
|
|
172
|
+
/** Description of the file */
|
|
173
|
+
description: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Generate adapter files for a specific platform
|
|
177
|
+
*/
|
|
178
|
+
declare function generateAdapterFiles(options: GeneratorOptions): GeneratedFile[];
|
|
179
|
+
|
|
180
|
+
export { type CloudflareAdapterConfig, type GeneratedFile, type GeneratorOptions, type NetlifyContext, type NetlifyEvent, type Platform, type VercelRequest, type VercelResponse, createCloudflareHandler, createNetlifyHandler, createVercelHandler, generateAdapterFiles };
|