
Security News
US Government Forces Anthropic to Pull Claude Fable Days After Launch
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.
mastra-browser-mcp
Advanced tools
Model Context Protocol (MCP) client implementation for Mastra, providing seamless integration with MCP-compatible AI models and tools.
Model Context Protocol (MCP) client implementation for Mastra, providing seamless integration with MCP-compatible AI models and tools.
npm install @mastra/mcp
The @mastra/mcp package provides a client implementation for the Model Context Protocol (MCP), enabling Mastra to communicate with MCP-compatible AI models and tools. It wraps the official @modelcontextprotocol/sdk and provides Mastra-specific functionality.
import { MastraMCPClient } from '@mastra/mcp';
// Create a client with stdio server
const stdioClient = new MastraMCPClient({
name: 'my-stdio-client',
version: '1.0.0', // optional
server: {
command: 'your-mcp-server-command',
args: ['--your', 'args'],
},
capabilities: {}, // optional ClientCapabilities
});
// Or create a client with SSE server
const sseClient = new MastraMCPClient({
name: 'my-sse-client',
version: '1.0.0',
server: {
url: new URL('https://your-mcp-server.com/sse'),
requestInit: {
headers: { Authorization: 'Bearer your-token' },
},
},
timeout: 60000, // optional timeout for tool calls in milliseconds
});
// Connect to the MCP server
await client.connect();
// List available resources
const resources = await client.resources();
// Get available tools
const tools = await client.tools();
// Disconnect when done
await client.disconnect();
For applications that need to interact with multiple MCP servers, the MCPConfiguration class provides a convenient way to manage multiple server connections and their tools:
import { MCPConfiguration } from '@mastra/mcp';
const mcp = new MCPConfiguration({
servers: {
// Stdio-based server
stockPrice: {
command: 'npx',
args: ['tsx', 'stock-price.ts'],
env: {
API_KEY: 'your-api-key',
},
},
// SSE-based server
weather: {
url: new URL('http://localhost:8080/sse'),
},
},
});
// Get all tools from all configured servers namespaced with the server name
const tools = await mcp.getTools();
// Get tools grouped into a toolset object per-server
const toolsets = await mcp.getToolsets();
The MCPConfiguration class provides two ways to access MCP tools:
getTools())Use this when:
const agent = new Agent({
name: 'CLI Assistant',
instructions: 'You help users with CLI tasks',
model: openai('gpt-4'),
tools: await mcp.getTools(), // Tools are fixed at agent creation
});
getToolsets())Use this when:
import { MCPConfiguration } from '@mastra/mcp';
import { Agent } from '@mastra/core/agent';
import { openai } from '@ai-sdk/openai';
// Configure MCP servers with user-specific settings before getting toolsets
const mcp = new MCPConfiguration({
servers: {
stockPrice: {
command: 'npx',
args: ['tsx', 'weather-mcp.ts'],
env: {
// These would be different per user
API_KEY: 'user-1-api-key',
},
},
weather: {
url: new URL('http://localhost:8080/sse'),
requestInit: {
headers: {
// These would be different per user
Authorization: 'Bearer user-1-token',
},
},
},
},
});
// Get the current toolsets configured for this user
const toolsets = await mcp.getToolsets();
// Use the agent with user-specific tool configurations
const response = await agent.generate('What is the weather in London?', {
toolsets,
});
console.log(response.text);
The MCPConfiguration class automatically:
name: Name of the MCP client instance
server: Either a StdioServerParameters or SSEClientParameters object:
command: Command to start the MCP serverargs: Array of command argumentsurl: URL instance pointing to the SSE serverrequestInit: Optional fetch request configurationeventSourceInit: Optional EventSource configurationversion: Client version (default: '1.0.0')capabilities: ClientCapabilities object for specifying supported featuresconnect()Establishes connection with the MCP server.
disconnect()Closes the connection with the MCP server.
resources()Lists available resources from the MCP server.
tools()Retrieves and converts MCP tools to Mastra-compatible format.
The package automatically converts MCP tools to Mastra's format:
const tools = await client.tools();
// Returns: { [toolName: string]: MastraTool }
// Each tool includes:
// - Converted JSON schema
// - Mastra-compatible execution wrapper
// - Error handling
// - Automatic context passing
The client includes comprehensive error handling:
FAQs
Model Context Protocol (MCP) client implementation for Mastra, providing seamless integration with MCP-compatible AI models and tools.
We found that mastra-browser-mcp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.