Resources
Static resources & structure
File-backed resources, naming, and the shape of defineMcpResource.
Static Resources
Static resources have a fixed URI that doesn't change.
Simple File Resources
The easiest way to expose a local file is using the file property. This automatically handles the URI generation, MIME type detection, and file reading.
server/mcp/resources/readme.ts
import { defineMcpResource } from '@nuxtjs/mcp-toolkit/server'
export default defineMcpResource({
name: 'readme',
description: 'Project README file',
file: 'README.md', // Relative to project root
})
This generates:
- URI:
file:///path/to/project/README.md - Handler: Automatically reads the file content
- MIME Type: Automatically detected (e.g.,
text/markdown)
Custom Static Resources
For more control, you can define the uri and handler manually:
server/mcp/resources/custom-readme.ts
import { readFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import { defineMcpResource } from '@nuxtjs/mcp-toolkit/server'
export default defineMcpResource({
name: 'custom-readme',
title: 'README',
description: 'Project README file',
uri: 'file:///README.md',
metadata: {
mimeType: 'text/markdown',
},
handler: async (uri: URL) => {
const filePath = fileURLToPath(uri)
const content = await readFile(filePath, 'utf-8')
return {
contents: [{
uri: uri.toString(),
mimeType: 'text/markdown',
text: content,
}],
}
},
})
Auto-Generated Name and Title
You can omit name and title - they will be automatically generated from the filename:
server/mcp/resources/project-readme.ts
import { defineMcpResource } from '@nuxtjs/mcp-toolkit/server'
export default defineMcpResource({
// name and title are auto-generated from filename:
// name: 'project-readme'
// title: 'Project Readme'
file: 'README.md'
})
The filename project-readme.ts automatically becomes:
name:project-readme(kebab-case)title:Project Readme(title case)
You can still provide name or title explicitly to override the auto-generated values.
Resource Structure
A resource definition consists of:
import { defineMcpResource } from '@nuxtjs/mcp-toolkit/server'
export default defineMcpResource({
name: 'resource-name',
file: 'path/to/file.txt', // Local file path
metadata: { ... }
})
import { defineMcpResource } from '@nuxtjs/mcp-toolkit/server'
export default defineMcpResource({
name: 'resource-name', // Unique identifier
uri: 'uri://...', // Static URI or ResourceTemplate
handler: async (uri) => { // Handler function
return { contents: [...] }
},
})