一个模型上下文协议(MCP)服务器,提供AI助手直接访问Mastra.ai的完整知识库。这包括支持MDX的综合文档、一系列生产就绪的代码示例、技术博客文章以及详细的包更改日志。该服务器与流行的AI开发环境如Cursor和Windsurf以及Mastra代理集成,使得构建了解文档的AI助手变得容易,这些助手可以提供关于Mastra.ai生态系统准确且最新的信息。
在项目根目录创建或更新.cursor/mcp.json:
MacOS/Linux
{
"mcpServers": {
"mastra": {
"command": "npx",
"args": ["-y", "@mastra/mcp-docs-server"]
}
}
}
Windows
{
"mcpServers": {
"mastra": {
"command": "cmd",
"args": ["/c", "npx", "-y", "@mastra/mcp-docs-server"]
}
}
}
这将使所有Mastra文档工具在你的Cursor工作区中可用。请注意,MCP服务器默认情况下不会启用。你需要进入Cursor设置 -> MCP设置,并点击“启用”Mastra MCP服务器。
创建或更新~/.codeium/windsurf/mcp_config.json:
MacOS/Linux
{
"mcpServers": {
"mastra": {
"command": "npx",
"args": ["-y", "@mastra/mcp-docs-server"]
}
}
}
Windows
{
"mcpServers": {
"mastra": {
"command": "cmd",
"args": ["/c", "npx", "-y", "@mastra/mcp-docs-server"]
}
}
}
这将使所有Mastra文档工具在你的Windsurf工作区中可用。请注意,Windsurf调用MCP工具的效果不佳。添加后,你需要完全退出并重新打开Windsurf。如果工具调用失败,你需要进入Windsurf MCP设置并重新启动MCP服务器。
安装Claude Code后运行:
claude mcp add mastra-docs -- npx -y @mastra/mcp-docs-server
import { MCPClient } from '@mastra/mcp';
import { Agent } from '@mastra/core/agent';
import { openai } from '@ai-sdk/openai';
// 使用文档服务器配置MCP
const mcp = new MCPClient({
servers: {
mastra: {
command: 'npx',
args: ['-y', '@mastra/mcp-docs-server'],
},
},
});
// 创建一个具有访问所有文档工具权限的代理
const agent = new Agent({
id: 'doc-assistant',
name: '文档助手',
instructions: '你帮助用户查找和理解Mastra.ai文档。',
model: openai('gpt-4'),
tools: await mcp.listTools(),
});
// 或者在generate/stream中动态使用工具集
const response = await agent.stream('给我看快速入门示例', {
toolsets: await mcp.listToolsets(),
});
mastraDocs)mastraExamples)mastraBlog)mastraChanges)mastraMigration)