The Model Context Protocol (MCP) server from Mastra.ai provides AI assistants with direct access to Mastra's knowledge base, including documentation, code examples, blog posts, and package changelogs. This server integrates with AI development environments like Cursor and Windsurf, enabling you to build documentation-aware AI assistants.
Create or update the .cursor/mcp.json
file in your project root:
For MacOS/Linux:
{
"mcpServers": {
"mastra": {
"command": "npx",
"args": ["-y", "@mastra/mcp-docs-server"]
}
}
}
For Windows:
{
"mcpServers": {
"mastra": {
"command": "cmd",
"args": ["/c", "npx", "-y", "@mastra/mcp-docs-server"]
}
}
}
After configuration, you'll need to enable the MCP server by going to Cursor settings → MCP settings and clicking "enable" on the Mastra MCP server.
Create or update ~/.codeium/windsurf/mcp_config.json
:
For MacOS/Linux:
{
"mcpServers": {
"mastra": {
"command": "npx",
"args": ["-y", "@mastra/mcp-docs-server"]
}
}
}
For Windows:
{
"mcpServers": {
"mastra": {
"command": "cmd",
"args": ["/c", "npx", "-y", "@mastra/mcp-docs-server"]
}
}
}
Note: For Windsurf, you'll need to fully quit and re-open the application after adding this configuration. If a tool call fails, go into Windsurf MCP settings and restart the MCP server.
import { MCPClient } from '@mastra/mcp';
import { Agent } from '@mastra/core/agent';
import { openai } from '@ai-sdk/openai';
// Configure MCP with the docs server
const mcp = new MCPClient({
servers: {
mastra: {
command: 'npx',
args: ['-y', '@mastra/mcp-docs-server'],
},
},
});
// Create an agent with access to all documentation tools
const agent = new Agent({
name: 'Documentation Assistant',
instructions: 'You help users find and understand Mastra.ai documentation.',
model: openai('gpt-4'),
tools: await mcp.getTools(),
});
// Or use toolsets dynamically in generate/stream
const response = await agent.stream('Show me the quick start example', {
toolsets: await mcp.getToolsets(),
});
mastraDocs
)This tool allows you to:
mastraExamples
)With this tool, you can:
mastraBlog
)The blog tool enables you to:
mastraChanges
)This tool provides:
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.