MCPClient class. By connecting Context7 as an MCP server, your Mastra agents can access up-to-date library documentation, enabling them to generate accurate code and answer technical questions with current API references.
For more details on how Mastra handles MCP, see the Mastra MCP documentation.
Setup
1
Install the MCP Package
Add the Mastra MCP package to your project:
2
Create an MCP Client
Configure an Set
MCPClient that connects to Context7:CONTEXT7_API_KEY in your environment with your API key from the Context7 dashboard.3
Connect to Your Agent
Pass the Context7 tools to your Mastra agent:
How It Works
Once connected, your Mastra agents will query Context7 for relevant library documentation. This helps agents:- Answer technical questions with accurate, up-to-date API references
- Generate code that follows current library patterns and best practices
- Avoid hallucinating outdated or incorrect API usage
- Provide version-specific guidance for any supported library