-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(docs): add x-mcp-tools header to specify available tools #6788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -28,33 +28,47 @@ The Nuxt UI MCP server provides the following tools organized by category: | |||
|
|
||||
| ### Search Tools | ||||
|
|
||||
| - **`search_components`**: Search components by name, description, or category. With no params, lists all components | ||||
| - **`search_composables`**: Search composables by name or description. With no params, lists all composables | ||||
| - **`search_icons`**: Search for icons across Iconify collections (defaults to `lucide`). Returns icon names in the `i-{prefix}-{name}` format used by Nuxt UI | ||||
| - **`search-components`**: Search components by name, description, or category. With no params, lists all components | ||||
| - **`search-composables`**: Search composables by name or description. With no params, lists all composables | ||||
| - **`search-icons`**: Search for icons across Iconify collections (defaults to `lucide`). Returns icon names in the `i-{prefix}-{name}` format used by Nuxt UI | ||||
|
|
||||
| ### Component Tools | ||||
|
|
||||
| - **`get_component`**: Retrieves component documentation and details. Supports a `sections` parameter (`usage`, `examples`, `api`, `theme`, `changelog`) to fetch only specific parts and reduce response size | ||||
| - **`get_component_metadata`**: Retrieves detailed metadata for a component including props, slots, and events (lightweight, no documentation content) | ||||
| - **`get-component`**: Retrieves component documentation and details. Supports a `sections` parameter (`usage`, `examples`, `api`, `theme`, `changelog`) to fetch only specific parts and reduce response size | ||||
| - **`get-component-metadata`**: Retrieves detailed metadata for a component including props, slots, and events (lightweight, no documentation content) | ||||
|
|
||||
| ### Documentation Tools | ||||
|
|
||||
| - **`search_documentation`**: Search documentation pages by title, description, or section. With no params, lists all pages. Use `section` to filter (e.g., `"getting-started"`, `"components"`) | ||||
| - **`get_documentation_page`**: Retrieves documentation page content by URL path. Supports a `headings` parameter to fetch only specific h2 sections (e.g., `["Usage", "API"]`) and reduce response size | ||||
| - **`search-documentation`**: Search documentation pages by title, description, or section. With no params, lists all pages. Use `section` to filter (e.g., `"getting-started"`, `"components"`) | ||||
| - **`get-documentation-page`**: Retrieves documentation page content by URL path. Supports a `headings` parameter to fetch only specific h2 sections (e.g., `["Usage", "API"]`) and reduce response size | ||||
|
|
||||
| ### Template Tools | ||||
|
|
||||
| - **`list_templates`**: Lists all available Nuxt UI templates with optional framework filtering | ||||
| - **`get_template`**: Retrieves template details and setup instructions | ||||
| - **`list-templates`**: Lists all available Nuxt UI templates with optional framework filtering | ||||
| - **`get-template`**: Retrieves template details and setup instructions | ||||
|
|
||||
| ### Example Tools | ||||
|
|
||||
| - **`list_examples`**: Lists all available UI examples and code demonstrations | ||||
| - **`get_example`**: Retrieves specific UI example implementation code and details | ||||
| - **`list-examples`**: Lists all available UI examples and code demonstrations | ||||
| - **`get-example`**: Retrieves specific UI example implementation code and details | ||||
|
|
||||
| ### Migration Tools | ||||
|
|
||||
| - **`get_migration_guide`**: Retrieves version-specific migration guides and upgrade instructions | ||||
| - **`get-migration-guide`**: Retrieves version-specific migration guides and upgrade instructions | ||||
|
|
||||
| ## Limit available tools | ||||
|
|
||||
| Set the optional `X-MCP-Tools` HTTP header to a comma-separated list of tool names to expose only the tools your assistant needs. This helps to reduce the context defined in your assistant. | ||||
|
|
||||
| Use the exact kebab-case MCP tool names, for example: | ||||
|
|
||||
| ``` | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ Maintainability & Code Quality | ๐ก Minor | โก Quick win Add a language tag to the code fence. Use Proposed fix-```
+```json๐ Committable suggestion
Suggested change
๐งฐ Tools๐ช markdownlint-cli2 (0.23.1)[warning] 65-65: Fenced code blocks should have a language specified (MD040, fenced-code-language) ๐ค Prompt for AI AgentsSource: Linters/SAST tools |
||||
| { | ||||
| "X-MCP-Tools": "search-components,get-component" | ||||
| } | ||||
| ``` | ||||
|
|
||||
| No header exposes all tools, an empty header exposes no tools, and an unknown tool name returns a configuration error. | ||||
|
|
||||
| ## Available Prompts | ||||
|
|
||||
|
|
@@ -319,12 +333,17 @@ For more details, see [Adding MCP servers for GitHub Copilot CLI](https://docs.g | |||
| "servers": { | ||||
| "nuxt-ui": { | ||||
| "type": "http", | ||||
| "url": "https://ui.nuxt.com/mcp" | ||||
| "url": "https://ui.nuxt.com/mcp", | ||||
| "headers": { | ||||
| "X-MCP-Tools": "search-components,get-component" // Optional: Limit available tools to reduce context | ||||
| } | ||||
| } | ||||
| } | ||||
| } | ||||
| ``` | ||||
|
|
||||
| Remove the `headers` entry to make all Nuxt UI MCP tools available. | ||||
|
|
||||
| ### Windsurf | ||||
|
|
||||
| #### Setup Instructions: | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { defineMcpHandler, getMcpTools } from '@nuxtjs/mcp-toolkit/server' | ||
|
|
||
| export default defineMcpHandler({ | ||
| async tools(event) { | ||
| const tools = await getMcpTools({ event }) | ||
| const requestedTools = getHeader(event, 'x-mcp-tools') | ||
|
|
||
| if (requestedTools === undefined) { | ||
| return tools | ||
| } | ||
|
|
||
| const requestedToolNames = getRequestedToolNames(requestedTools) | ||
| const availableToolNames = getAvailableToolNames(tools) | ||
|
|
||
| const unknownNames = requestedToolNames.filter(requestedToolName => !availableToolNames.has(requestedToolName)) | ||
| if (unknownNames.length) { | ||
| throw createError({ | ||
| statusCode: 400, | ||
| statusMessage: `Unknown MCP tool${unknownNames.length > 1 ? 's' : ''}: ${unknownNames.join(', ')}` | ||
| }) | ||
| } | ||
|
|
||
| return tools.filter(tool => requestedToolNames.includes(getToolName(tool) || '')) | ||
| } | ||
| }) | ||
|
|
||
| function getAvailableToolNames(tools: Awaited<ReturnType<typeof getMcpTools>>) { | ||
| const names = new Set<string>() | ||
|
|
||
| for (const tool of tools) { | ||
| const name = getToolName(tool) | ||
| if (name) { | ||
| names.add(name) | ||
| } | ||
| } | ||
|
|
||
| return names | ||
| } | ||
|
Comment on lines
+27
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐๏ธ Data Integrity & Integration | ๐ก Minor | โก Quick win ๐งฉ Analysis chain๐ Script executed: #!/usr/bin/env bash
set -euo pipefail
rg -n -C 8 'defineMcpTool|name\s*:' --glob '*.ts' --glob '*.vue' .
rg -n -C 3 'search-components|search-composables|search-icons|get-component|get-component-metadata|search-documentation|get-documentation-page|list-templates|get-template|list-examples|get-example|get-migration-guide|getToolName|_meta.*filename' .Repository: nuxt/ui Length of output: 50364 ๐ Script executed: #!/bin/bash
set -euo pipefail
# Focus only on the MCP docs file and the surrounding implementation.
printf '--- docs/server/mcp/index.ts ---\n'
wc -l docs/server/mcp/index.ts
cat -n docs/server/mcp/index.ts
printf '\n--- exact getToolName definitions/usages ---\n'
rg -n -C 4 'function getToolName|const getToolName|getToolName|defineMcpTool|_meta.*filename|filename' docs/server/mcp src docs --glob '!**/node_modules/**' --glob '!**/.nuxt/**' | m
printf '\n--- target tool names ---\n'
rg -n -C 3 'search-icons|search-components|search-composables|get-component|get-component-metadata|search-documentation|get-documentation-page|list-templates|get-template|list-examples|get-example|get-migration-guide' docs/src src docs --glob '!**/node_modules/**' --glob '!**/.nuxt/**' | head -n 300
printf '\n--- package/toolkit references ---\n'
rg -n -C 3 '`@nuxt`[\S]*mcp|mcp-tool|defineMcpTool|mcp' package.json pnpm-lock.yaml yarn.lock package-lock.json --glob '!**/node_modules/**' | head -n 200Repository: nuxt/ui Length of output: 236 ๐ Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- docs/server/mcp/index.ts ---'
wc -l docs/server/mcp/index.ts
cat -n docs/server/mcp/index.ts
printf '%s\n' ''
printf '%s\n' '--- exact getToolName definitions/usages ---'
rg -n -C 4 'function getToolName|const getToolName|getToolName|defineMcpTool|_meta.*filename|filename' docs/server/mcp src docs --glob '!**/node_modules/**' --glob '!**/.nuxt/**' | m || true
printf '%s\n' ''
printf '%s\n' '--- target tool names ---'
rg -n -C 3 'search-icons|search-components|search-composables|get-component|get-component-metadata|search-documentation|get-documentation-page|list-templates|get-template|list-examples|get-example|get-migration-guide' docs/src src docs --glob '!**/node_modules/**' --glob '!**/.nuxt/**' | head -n 300 || true
printf '%s\n' ''
printf '%s\n' '--- package/toolkit references ---'
rg -n -C 3 '`@nuxt`[\S]*mcp|mcp-tool|defineMcpTool|mcp' package.json pnpm-lock.yaml yarn.lock package-lock.json --glob '!**/node_modules/**' | head -n 200 || trueRepository: nuxt/ui Length of output: 13606 ๐ Web query:
๐ก Result: In Citations: ๐ Web query:
๐ก Result: In the Citations:
๐ Web query:
๐ก Result: In the Citations:
Use the MCP toolkitโs filename-to-name conversion in the fallback.
๐ค Prompt for AI Agents |
||
|
|
||
| function getToolName(tool: Awaited<ReturnType<typeof getMcpTools>>[number]) { | ||
| if (tool.name) { | ||
| return tool.name | ||
| } | ||
|
|
||
| const filename = tool._meta?.filename | ||
|
|
||
| if (typeof filename !== 'string') { | ||
| return | ||
| } | ||
|
|
||
| return filename.replace('.ts', '').toLowerCase() | ||
| } | ||
|
|
||
| function getRequestedToolNames(requestedTools: string) { | ||
| return Array.from( | ||
| new Set<string>(requestedTools.split(',').map((name: string) => name.trim()).filter((name: string) => Boolean(name))) | ||
| ) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ Maintainability & Code Quality | ๐ก Minor | โก Quick win
Clarify the context reduction.
context defined in your assistantdoes not describe the behavior. The handler reduces the tool context sent to the assistant.Proposed wording
๐ Committable suggestion
๐ค Prompt for AI Agents