进阶主题
在 llms.txt 中公开服务器
让 agent 通过 llms.txt 发现你的 MCP 服务器。
只有 agent 知道 MCP 端点存在,它才有用。大多数客户端都需要用户将 URL 手动粘贴到配置文件中,因此自行发现你的网站的 agent 无法看到你的服务器。
llms.txt 是 agent 已会主动获取、用于了解网站的约定文件。在注册本模块的同时注册 nuxt-llms 后,工具包会在 /llms.txt 中添加 ## MCP Server 部分来介绍你的端点,无需额外配置。
设置
将 nuxt-llms 与工具包一同添加:
Terminal
npx nuxi module add nuxt-llms
nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxtjs/mcp-toolkit', 'nuxt-llms'],
llms: {
domain: 'https://example.com',
title: 'Example',
description: 'Everything about Example.',
},
mcp: {
name: 'Example MCP',
description: 'Query Example data from your agent.',
browserRedirect: '/docs/mcp',
},
})
此时 /llms.txt 会包含:
llms.txt
# Example
> Everything about Example.
## MCP Server
Query Example data from your agent.
- [Example MCP](https://example.com/mcp): Streamable HTTP endpoint — connect an MCP client to this URL to call the tools, resources and prompts exposed by this site.
- [MCP documentation](https://example.com/docs/mcp): How to connect to this MCP server.
部分内容来源
| 来源 | 用途 |
|---|---|
llms.domain + mcp.route | The absolute endpoint URL |
mcp.name | The endpoint link label |
mcp.description | The section description (falls back to a generated sentence) |
mcp.browserRedirect | An extra documentation link, when set to something other than / |
此部分基于已解析的配置构建,使用
nuxt-llms 渲染文件时调用的 llms:generate hook。注意,nuxt-llms 会预渲染 /llms.txt,因此文件内容(包括 llms.domain)会在构建时确定。关闭此功能
将 mcp.llms 设为 false,即可不修改 /llms.txt:
nuxt.config.ts
export default defineNuxtConfig({
mcp: {
llms: false,
},
})
如果 llms.sections 中已经包含标题为 MCP Server 的部分,工具包也会自动跳过添加操作,这样你就可以自行编写端点说明而不会产生重复内容:
nuxt.config.ts
export default defineNuxtConfig({
llms: {
domain: 'https://example.com',
sections: [
{
title: 'MCP Server',
description: 'Our own wording wins.',
links: [{ title: 'Endpoint', href: 'https://example.com/mcp' }],
},
],
},
})
nuxt-llms 不是本模块的依赖项。未安装时,不会注册任何内容,也不会产生运行时开销。