Skip to content
Draft
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 docs/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default defineNuxtConfig({
description: 'Write beautiful docs with Markdown.',
},
},
mcp: {
name: 'Docus documentation',
},
studio: {
route: '/admin',
repository: {
Expand Down
3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"docus": "workspace:*",
"nuxt-studio": "1.0.0-alpha.2",
"tailwindcss": "^4.1.17",
"unist-util-visit": "^5.0.0"
"unist-util-visit": "^5.0.0",
"zod": "^3.24.1"
},
"devDependencies": {
"nuxt": "4.2.1"
Expand Down
18 changes: 16 additions & 2 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
{
"extends": "./.nuxt/tsconfig.json"
}
"files": [],
"references": [
{
"path": "./.nuxt/tsconfig.app.json"
},
{
"path": "./.nuxt/tsconfig.server.json"
},
{
"path": "./.nuxt/tsconfig.shared.json"
},
{
"path": "./.nuxt/tsconfig.node.json"
}
]
}
1 change: 1 addition & 0 deletions layer/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineNuxtConfig({
'@nuxt/content',
'@nuxt/image',
'@nuxtjs/robots',
'nuxt-mcp-toolkit',
'nuxt-og-image',
'nuxt-llms',
() => {
Expand Down
4 changes: 3 additions & 1 deletion layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"README.md"
],
"dependencies": {
"nuxt-mcp-toolkit": "^0.0.2",
"@iconify-json/lucide": "^1.2.73",
"@iconify-json/simple-icons": "^1.2.59",
"@iconify-json/vscode-icons": "^1.2.35",
Expand All @@ -43,7 +44,8 @@
"pkg-types": "^2.3.0",
"scule": "^1.3.0",
"tailwindcss": "^4.1.17",
"ufo": "^1.6.1"
"ufo": "^1.6.1",
"zod": "^3.24.1"
},
"peerDependencies": {
"better-sqlite3": "12.x",
Expand Down
67 changes: 67 additions & 0 deletions layer/server/api/.docus-mcp/get-page.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { z } from 'zod'
import { queryCollection } from '@nuxt/content/server'
import type { Collections } from '@nuxt/content'
import { getAvailableLocales, getCollectionFromPath } from '../../utils/content'

const querySchema = z.object({
path: z.string().describe('The page path (e.g., /en/getting-started/installation)'),
})

export default defineCachedEventHandler(async (event) => {
const { path } = await getValidatedQuery(event, querySchema.parse)
const config = useRuntimeConfig(event).public

const siteUrl = import.meta.dev ? 'http://localhost:3000' : getRequestURL(event).origin
const availableLocales = getAvailableLocales(config)
const collectionName = config.i18n?.locales
? getCollectionFromPath(path, availableLocales)
: 'docs'

try {
const page = await queryCollection(event, collectionName as keyof Collections)
.where('path', '=', path)
.select('title', 'path', 'description')
.first()

if (!page) {
return {
content: [
{
type: 'text',
text: 'Page not found',
},
],
isError: true,
}
}

const content = await $fetch<string>(`/raw${path}.md`, {
baseURL: siteUrl,
})

return {
title: page.title,
path: page.path,
description: page.description,
content,
url: `${siteUrl}${page.path}`,
}
}
catch {
return {
content: [
{
type: 'text',
text: 'Failed to get page',
},
],
isError: true,
}
}
}, {
maxAge: 60 * 60,
getKey: (event) => {
const query = getQuery(event)
return `mcp-get-page-${query.path}`
},
})
54 changes: 54 additions & 0 deletions layer/server/api/.docus-mcp/list-pages.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { z } from 'zod'
import { queryCollection } from '@nuxt/content/server'
import type { Collections } from '@nuxt/content'
import { getCollectionsToQuery, getAvailableLocales } from '../../utils/content'

const querySchema = z.object({
locale: z.string().optional().describe('Language code (e.g., "en", "fr")'),
})

export default defineCachedEventHandler(async (event) => {
const { locale } = await getValidatedQuery(event, querySchema.parse)
const config = useRuntimeConfig(event).public

const siteUrl = import.meta.dev ? 'http://localhost:3000' : getRequestURL(event).origin
const availableLocales = getAvailableLocales(config)
const collections = getCollectionsToQuery(locale, availableLocales)

const allPages = await Promise.all(
collections.map(async (collectionName) => {
try {
const pages = await queryCollection(event, collectionName as keyof Collections)
.select('title', 'path', 'description')
.all()

return pages.map(page => ({
title: page.title,
path: page.path,
description: page.description,
locale: collectionName.replace('docs_', ''),
url: `${siteUrl}${page.path}`,
}))
}
catch {
return {
content: [
{
type: 'text',
text: 'Failed to list pages',
},
],
isError: true,
}
}
}),
)

return allPages.flat()
}, {
maxAge: 60 * 60,
getKey: (event) => {
const query = getQuery(event)
return `mcp-list-pages-${query.locale || 'all'}`
},
})
14 changes: 14 additions & 0 deletions layer/server/mcp/tools/get-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { z } from 'zod'

export default defineMcpTool({
description: 'Retrieves the full markdown content of a specific documentation page by path',
inputSchema: {
path: z.string().describe('The page path (e.g., /en/getting-started/installation)'),
},
handler: async (params) => {
const result = await $fetch('/api/.docus-mcp/get-page', { query: params })
return {
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
}
},
})
14 changes: 14 additions & 0 deletions layer/server/mcp/tools/list-pages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { z } from 'zod'

export default defineMcpTool({
description: 'Lists all available documentation pages with their titles, paths, and descriptions',
inputSchema: {
locale: z.string().optional().describe('The locale to filter pages by'),
},
handler: async (params) => {
const result = await $fetch('/api/.docus-mcp/list-pages', { query: params })
return {
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
}
},
})
2 changes: 1 addition & 1 deletion layer/server/routes/raw/[...slug].md.get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { withLeadingSlash } from 'ufo'
import { stringify } from 'minimark/stringify'
import { queryCollection } from '@nuxt/content/nitro'
import { queryCollection } from '@nuxt/content/server'
import type { Collections } from '@nuxt/content'

export default eventHandler(async (event) => {
Expand Down
37 changes: 37 additions & 0 deletions layer/server/utils/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { LocaleObject } from '@nuxtjs/i18n'

type ConfigWithLocales = {
i18n?: { locales?: Array<string | LocaleObject> }
docus?: { filteredLocales?: LocaleObject<string>[] }
}

export function getAvailableLocales(config: ConfigWithLocales): string[] {
if (config.docus?.filteredLocales) {
return config.docus.filteredLocales.map(locale => locale.code)
}

return config.i18n?.locales
? config.i18n.locales.map(locale => typeof locale === 'string' ? locale : locale.code)
: []
}

export function getCollectionsToQuery(locale: string | undefined, availableLocales: string[]): string[] {
if (locale && availableLocales.includes(locale)) {
return [`docs_${locale}`]
}

return availableLocales.length > 0
? availableLocales.map(l => `docs_${l}`)
: ['docs']
}

export function getCollectionFromPath(path: string, availableLocales: string[]): string {
const pathSegments = path.split('/').filter(Boolean)
const firstSegment = pathSegments[0]

if (firstSegment && availableLocales.includes(firstSegment)) {
return `docs_${firstSegment}`
}

return 'docs'
}
Loading
Loading