@mastra/mcp-docs-server 0.10.1-alpha.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +7 -7
  2. package/.docs/organized/changelogs/mastra.md +7 -7
  3. package/.docs/raw/course/01-first-agent/01-introduction-to-mastra.md +21 -0
  4. package/.docs/raw/course/01-first-agent/02-what-is-mastra.md +11 -0
  5. package/.docs/raw/course/01-first-agent/03-verifying-installation.md +18 -0
  6. package/.docs/raw/course/01-first-agent/04-project-structure.md +12 -0
  7. package/.docs/raw/course/01-first-agent/05-running-playground.md +19 -0
  8. package/.docs/raw/course/01-first-agent/06-understanding-system-prompts.md +13 -0
  9. package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +49 -0
  10. package/.docs/raw/course/01-first-agent/08-exporting-your-agent.md +18 -0
  11. package/.docs/raw/course/01-first-agent/09-testing-your-agent.md +12 -0
  12. package/.docs/raw/course/01-first-agent/10-understanding-tools.md +14 -0
  13. package/.docs/raw/course/01-first-agent/11-creating-transactions-tool.md +39 -0
  14. package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +29 -0
  15. package/.docs/raw/course/01-first-agent/13-testing-your-tool.md +15 -0
  16. package/.docs/raw/course/01-first-agent/14-understanding-memory.md +14 -0
  17. package/.docs/raw/course/01-first-agent/15-installing-memory.md +11 -0
  18. package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +28 -0
  19. package/.docs/raw/course/01-first-agent/17-testing-memory.md +15 -0
  20. package/.docs/raw/course/01-first-agent/18-conclusion.md +20 -0
  21. package/.docs/raw/course/02-agent-tools-mcp/01-introduction-to-mcp.md +15 -0
  22. package/.docs/raw/course/02-agent-tools-mcp/02-installing-mcp.md +11 -0
  23. package/.docs/raw/course/02-agent-tools-mcp/03-setting-up-mcp-configuration.md +21 -0
  24. package/.docs/raw/course/02-agent-tools-mcp/04-initializing-mcp-tools.md +11 -0
  25. package/.docs/raw/course/02-agent-tools-mcp/05-updating-your-agent.md +20 -0
  26. package/.docs/raw/course/02-agent-tools-mcp/06-testing-mcp-setup.md +12 -0
  27. package/.docs/raw/course/02-agent-tools-mcp/07-what-is-zapier-mcp.md +14 -0
  28. package/.docs/raw/course/02-agent-tools-mcp/08-getting-zapier-mcp-url.md +16 -0
  29. package/.docs/raw/course/02-agent-tools-mcp/09-updating-mcp-config-zapier.md +17 -0
  30. package/.docs/raw/course/02-agent-tools-mcp/10-updating-agent-instructions-zapier.md +29 -0
  31. package/.docs/raw/course/02-agent-tools-mcp/11-testing-zapier-integration.md +13 -0
  32. package/.docs/raw/course/02-agent-tools-mcp/12-troubleshooting-zapier.md +17 -0
  33. package/.docs/raw/course/02-agent-tools-mcp/13-what-is-github-mcp.md +14 -0
  34. package/.docs/raw/course/02-agent-tools-mcp/14-getting-github-mcp-url.md +16 -0
  35. package/.docs/raw/course/02-agent-tools-mcp/15-updating-mcp-config-github.md +20 -0
  36. package/.docs/raw/course/02-agent-tools-mcp/16-updating-agent-instructions-github.md +33 -0
  37. package/.docs/raw/course/02-agent-tools-mcp/17-testing-github-integration.md +15 -0
  38. package/.docs/raw/course/02-agent-tools-mcp/18-troubleshooting-github.md +17 -0
  39. package/.docs/raw/course/02-agent-tools-mcp/19-what-is-hackernews-mcp.md +13 -0
  40. package/.docs/raw/course/02-agent-tools-mcp/20-updating-mcp-config-hackernews.md +26 -0
  41. package/.docs/raw/course/02-agent-tools-mcp/21-updating-agent-instructions-hackernews.md +38 -0
  42. package/.docs/raw/course/02-agent-tools-mcp/22-testing-hackernews-integration.md +15 -0
  43. package/.docs/raw/course/02-agent-tools-mcp/23-troubleshooting-hackernews.md +23 -0
  44. package/.docs/raw/course/02-agent-tools-mcp/24-what-is-filesystem-mcp.md +15 -0
  45. package/.docs/raw/course/02-agent-tools-mcp/25-creating-notes-directory.md +17 -0
  46. package/.docs/raw/course/02-agent-tools-mcp/26-updating-mcp-config-filesystem.md +33 -0
  47. package/.docs/raw/course/02-agent-tools-mcp/27-updating-agent-instructions-filesystem.md +45 -0
  48. package/.docs/raw/course/02-agent-tools-mcp/28-testing-filesystem-integration.md +16 -0
  49. package/.docs/raw/course/02-agent-tools-mcp/29-troubleshooting-filesystem.md +21 -0
  50. package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +67 -0
  51. package/.docs/raw/course/02-agent-tools-mcp/32-conclusion.md +17 -0
  52. package/.docs/raw/course/03-agent-memory/01-understanding-memory.md +13 -0
  53. package/.docs/raw/course/03-agent-memory/02-why-memory-matters.md +11 -0
  54. package/.docs/raw/course/03-agent-memory/03-installing-memory.md +11 -0
  55. package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +31 -0
  56. package/.docs/raw/course/03-agent-memory/05-updating-mastra-export.md +18 -0
  57. package/.docs/raw/course/03-agent-memory/06-testing-memory-agent.md +18 -0
  58. package/.docs/raw/course/03-agent-memory/07-understanding-memory-threads.md +14 -0
  59. package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +33 -0
  60. package/.docs/raw/course/03-agent-memory/09-using-memory-in-application.md +19 -0
  61. package/.docs/raw/course/03-agent-memory/10-storage-configuration.md +30 -0
  62. package/.docs/raw/course/03-agent-memory/11-testing-conversation-history.md +20 -0
  63. package/.docs/raw/course/03-agent-memory/12-handling-memory-frontend.md +62 -0
  64. package/.docs/raw/course/03-agent-memory/13-what-is-semantic-recall.md +11 -0
  65. package/.docs/raw/course/03-agent-memory/14-how-semantic-recall-works.md +14 -0
  66. package/.docs/raw/course/03-agent-memory/15-configuring-semantic-recall.md +46 -0
  67. package/.docs/raw/course/03-agent-memory/16-vector-store-configuration.md +37 -0
  68. package/.docs/raw/course/03-agent-memory/17-testing-semantic-recall.md +24 -0
  69. package/.docs/raw/course/03-agent-memory/18-disabling-semantic-recall.md +24 -0
  70. package/.docs/raw/course/03-agent-memory/19-what-is-working-memory.md +15 -0
  71. package/.docs/raw/course/03-agent-memory/20-how-working-memory-works.md +9 -0
  72. package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +63 -0
  73. package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +81 -0
  74. package/.docs/raw/course/03-agent-memory/23-testing-working-memory.md +25 -0
  75. package/.docs/raw/course/03-agent-memory/24-working-memory-in-practice.md +34 -0
  76. package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +73 -0
  77. package/.docs/raw/course/03-agent-memory/26-updating-mastra-export-comprehensive.md +32 -0
  78. package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +96 -0
  79. package/.docs/raw/course/03-agent-memory/28-testing-memory-enhanced-agents.md +37 -0
  80. package/.docs/raw/course/03-agent-memory/29-memory-best-practices.md +40 -0
  81. package/.docs/raw/course/03-agent-memory/30-conclusion.md +21 -0
  82. package/dist/_tsup-dts-rollup.d.ts +92 -0
  83. package/dist/{chunk-JWLYN5OI.js → chunk-WMDELKUG.js} +4 -1
  84. package/dist/prepare-docs/prepare.js +1 -1
  85. package/dist/stdio.js +641 -8
  86. package/package.json +4 -4
@@ -1,5 +1,11 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 0.11.0-alpha.2
4
+
5
+ ### Minor Changes
6
+
7
+ - 3240a80: feat: add mastra interactive course
8
+
3
9
  ## 0.10.1-alpha.1
4
10
 
5
11
  ### Patch Changes
@@ -293,10 +299,4 @@
293
299
  - @mastra/core@0.9.2-alpha.2
294
300
  - @mastra/mcp@0.4.2-alpha.2
295
301
 
296
- ## 0.0.12-alpha.1
297
-
298
- ### Patch Changes
299
-
300
- - Updated dependencies [b804723]
301
-
302
- ... 599 more lines hidden. See full changelog in package directory.
302
+ ... 605 more lines hidden. See full changelog in package directory.
@@ -1,5 +1,11 @@
1
1
  # mastra
2
2
 
3
+ ## 0.10.1-alpha.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 3240a80: feat: add vscode as option to interactive prompt
8
+
3
9
  ## 0.10.1-alpha.5
4
10
 
5
11
  ### Patch Changes
@@ -293,10 +299,4 @@
293
299
 
294
300
  ### Patch Changes
295
301
 
296
- - 0db0992: - add new --mcp option to cli
297
- - add support for mcp in vscode
298
- - include examples with --default flag
299
- - b5d2de0: In vNext workflow serializedStepGraph, return only serializedStepFlow for steps created from a workflow
300
- allow viewing inner nested workflows in a multi-layered nested vnext workflow on the playground
301
-
302
- ... 3351 more lines hidden. See full changelog in package directory.
302
+ ... 3357 more lines hidden. See full changelog in package directory.
@@ -0,0 +1,21 @@
1
+ # Getting Started with Mastra
2
+
3
+ Welcome to the first step of building your first Mastra agent! In this lesson, you'll learn how to create a simple agent that can read data from a public Google Sheet using a custom tool function.
4
+
5
+ ## What is an Agent?
6
+
7
+ An agent is software with non-deterministic code that can make autonomous decisions based on inputs and environment rather than following fixed, predictable instructions every time.
8
+
9
+ Agents are AI systems that can:
10
+
11
+ - Perceive their environment through various inputs
12
+ - Make decisions based on those inputs
13
+ - Take actions to accomplish specific goals
14
+ - Learn and adapt their behavior over time
15
+
16
+ The best agents use several important features:
17
+
18
+ 1. **Memory**: They remember past interactions and learn from them
19
+ 2. **Planning**: They can break down complex tasks into smaller steps
20
+ 3. **Tool use**: They can leverage external tools and APIs to expand their capabilities
21
+ 4. **Feedback loops**: They can evaluate their own performance and adjust accordingly
@@ -0,0 +1,11 @@
1
+ # What is Mastra?
2
+
3
+ [Mastra](https://github.com/mastra-ai/mastra) is an open-source AI Agent Framework for TypeScript that includes all the basic primitives for AI engineering right out of the box:
4
+
5
+ - Agents with tools, memory, and tracing
6
+ - State-machine based workflows
7
+ - Evals for tracking and measuring AI output
8
+ - Storage for RAG pipelines
9
+ - Local development playground
10
+
11
+ With Mastra, you can quickly build, test, and deploy AI agents that can perform a wide variety of tasks. The framework is designed to be modular and extensible, allowing you to add new capabilities as needed.
@@ -0,0 +1,18 @@
1
+ # Verifying Your Mastra Installation
2
+
3
+ Before we begin building our agent, let's make sure you have Mastra properly installed. First, let's check if @mastra/core is in the package.json and there is a src/mastra directory. If so, you can skip this step.
4
+
5
+ If you haven't installed Mastra yet, you can do so by running:
6
+
7
+ ```bash
8
+ npm create mastra@latest
9
+ ```
10
+
11
+ If you do need to install mastra, follow the on-screen prompts and make sure to:
12
+
13
+ - Opt-in to installing both Agents and Workflows
14
+ - Say yes to installing tools
15
+ - Select OpenAI, Anthropic, or Google for your model
16
+ - Say yes to adding an example
17
+
18
+ You'll also need to add your OpenAI, Anthropic, or Google API key to the project.
@@ -0,0 +1,12 @@
1
+ # Verifying Project Structure
2
+
3
+ Let's check that your project has the correct structure. You should have:
4
+
5
+ 1. A `src/mastra` directory that contains:
6
+ - `index.ts` - The main entry point for your Mastra project
7
+ - `agents/index.ts` - Where your agents are defined
8
+ - `tools/index.ts` - Where your tools are defined
9
+
10
+ If these files exist, you're ready to start building your agent!
11
+
12
+ This structure is important because it follows the Mastra convention for organizing your code. The `index.ts` file is the main entry point for your Mastra project, while the `agents` and `tools` directories contain the definitions for your agents and tools, respectively.
@@ -0,0 +1,19 @@
1
+ # Running the Playground
2
+
3
+ To test your agent as you build it, you'll need to run the Mastra playground:
4
+
5
+ ```bash
6
+ npm run dev
7
+ ```
8
+
9
+ This will start the playground at `http://localhost:4111/`, where you can interact with your agent and test its capabilities.
10
+
11
+ The playground provides a user-friendly interface for testing your agent, allowing you to:
12
+
13
+ - Send messages to your agent
14
+ - See the agent's responses
15
+ - View the agent's thought process
16
+ - Test tools directly
17
+ - Debug any issues that arise
18
+
19
+ In the next step, we'll create our first agent with a simple system prompt and test it in the playground.
@@ -0,0 +1,13 @@
1
+ # Understanding System Prompts
2
+
3
+ A good system prompt is crucial as it defines your agent's purpose, capabilities, and behavioral guidelines. It's the foundation that shapes how your agent will interact with users.
4
+
5
+ A well-crafted system prompt should include:
6
+
7
+ - **Role definition**: What the agent is and what it does
8
+ - **Core capabilities**: What tasks the agent can perform
9
+ - **Behavioral guidelines**: How the agent should respond and interact
10
+ - **Constraints**: What the agent should not do or discuss
11
+ - **Success criteria**: What makes the agent's responses good
12
+
13
+ The system prompt acts as a set of instructions that guide the agent's behavior. It helps the agent understand its purpose and how it should interact with users. A clear and comprehensive system prompt will result in more consistent and helpful agent responses.
@@ -0,0 +1,49 @@
1
+ # Creating Your Agent
2
+
3
+ Let's create a simple agent that will help users analyze financial transaction data. We'll start by modifying the `agents/index.ts` file.
4
+
5
+ First, make sure you have the necessary imports at the top of your file:
6
+
7
+ ```typescript
8
+ import { Agent } from "@mastra/core";
9
+ import { openai } from "@ai-sdk/openai";
10
+ // We'll import our tool in a later step
11
+ ```
12
+
13
+ Now, let's create our agent:
14
+
15
+ ```typescript
16
+ export const financialAgent = new Agent({
17
+ name: "Financial Assistant Agent",
18
+ instructions: `ROLE DEFINITION
19
+ - You are a financial assistant that helps users analyze their transaction data.
20
+ - Your key responsibility is to provide insights about financial transactions.
21
+ - Primary stakeholders are individual users seeking to understand their spending.
22
+
23
+ CORE CAPABILITIES
24
+ - Analyze transaction data to identify spending patterns.
25
+ - Answer questions about specific transactions or vendors.
26
+ - Provide basic summaries of spending by category or time period.
27
+
28
+ BEHAVIORAL GUIDELINES
29
+ - Maintain a professional and friendly communication style.
30
+ - Keep responses concise but informative.
31
+ - Always clarify if you need more information to answer a question.
32
+ - Format currency values appropriately.
33
+ - Ensure user privacy and data security.
34
+
35
+ CONSTRAINTS & BOUNDARIES
36
+ - Do not provide financial investment advice.
37
+ - Avoid discussing topics outside of the transaction data provided.
38
+ - Never make assumptions about the user's financial situation beyond what's in the data.
39
+
40
+ SUCCESS CRITERIA
41
+ - Deliver accurate and helpful analysis of transaction data.
42
+ - Achieve high user satisfaction through clear and helpful responses.
43
+ - Maintain user trust by ensuring data privacy and security.`,
44
+ model: openai("gpt-4o"), // You can use "gpt-3.5-turbo" if you prefer
45
+ tools: {}, // We'll add tools in a later step
46
+ });
47
+ ```
48
+
49
+ This creates a financial assistant agent with a well-defined system prompt that outlines its role, capabilities, behavioral guidelines, constraints, and success criteria.
@@ -0,0 +1,18 @@
1
+ # Exporting Your Agent
2
+
3
+ To make your agent available to the playground, you need to export it through the Mastra class in your `src/mastra/index.ts` file:
4
+
5
+ ```typescript
6
+ import { Mastra } from "@mastra/core";
7
+ import { financialAgent } from "./agents";
8
+
9
+ export const mastra: Mastra = new Mastra({
10
+ agents: {
11
+ financialAgent,
12
+ },
13
+ });
14
+ ```
15
+
16
+ This creates a new Mastra instance that includes your financial agent, making it available to the playground and any other parts of your application.
17
+
18
+ The Mastra class is the main entry point for your Mastra project. It's responsible for registering your agents and making them available to the rest of your application. By adding your agent to the Mastra instance, you're telling Mastra that this agent should be available for use.
@@ -0,0 +1,12 @@
1
+ # Testing Your Agent
2
+
3
+ Now let's test our agent in the playground:
4
+
5
+ 1. Make sure your development server is running with `npm run dev`
6
+ 2. Open the playground at http://localhost:4111/
7
+ 3. You should see your "Financial Assistant Agent" in the list of agents
8
+ 4. Try sending a message like "Hello, can you help me analyze my spending?"
9
+
10
+ At this point, your agent can respond to basic questions but doesn't have access to any transaction data. In the next step, we'll create a custom tool to fetch transaction data from a Google Sheet.
11
+
12
+ Testing your agent in the playground is an important step in the development process. It allows you to see how your agent responds to different inputs and identify any issues that need to be addressed before deploying it to production.
@@ -0,0 +1,14 @@
1
+ # Understanding Tools in Mastra
2
+
3
+ Tools in Mastra are functions that your agent can call to perform specific tasks. They extend your agent's capabilities by giving it access to external data sources, APIs, and functionality beyond what's available in the language model itself.
4
+
5
+ Each tool has:
6
+
7
+ - A unique ID that the agent uses to reference it
8
+ - A clear description of what it does, which helps the agent understand when to use it
9
+ - Input and output schemas that define the expected parameters and return values
10
+ - An execute function that performs the actual work
11
+
12
+ Tools are a powerful way to enhance your agent's abilities. They allow your agent to interact with the outside world, access specific data sources, and perform actions that would otherwise be impossible for a language model alone.
13
+
14
+ In the next step, we'll create a custom tool that fetches transaction data from a Google Sheet.
@@ -0,0 +1,39 @@
1
+ # Creating the getTransactions Tool
2
+
3
+ Let's create a tool that fetches transaction data from a Google Sheet. We'll add this to your `tools/index.ts` file.
4
+
5
+ First, make sure you have the necessary imports:
6
+
7
+ ```typescript
8
+ import { createTool } from "@mastra/core";
9
+ import { z } from "zod";
10
+ ```
11
+
12
+ Now, let's create our tool:
13
+
14
+ ```typescript
15
+ export const getTransactionsTool = createTool({
16
+ id: "get-transactions",
17
+ description: "Get transaction data from Google Sheets",
18
+ inputSchema: z.object({}), // No input parameters needed
19
+ outputSchema: z.object({
20
+ csvData: z.string(),
21
+ }),
22
+ execute: async () => {
23
+ return await getTransactions();
24
+ },
25
+ });
26
+
27
+ const getTransactions = async () => {
28
+ // This URL points to a public Google Sheet with transaction data
29
+ const url =
30
+ "https://docs.google.com/spreadsheets/d/e/2PACX-1vTQWaCzJAFsF4owWRHQRLo4G0-ERv31c74OOZFnqLiTLaP7NweoiX7IXvzQud2H6bdUPnIqZEA485Ux/pubhtml?gid=0&single=true";
31
+ const response = await fetch(url);
32
+ const data = await response.text();
33
+ return {
34
+ csvData: data,
35
+ };
36
+ };
37
+ ```
38
+
39
+ This tool fetches transaction data from a public Google Sheet and returns it as a string. The `createTool` function from Mastra makes it easy to define the tool's ID, description, input and output schemas, and execution logic.
@@ -0,0 +1,29 @@
1
+ # Connecting the Tool to Your Agent
2
+
3
+ Now that we've created our tool, we need to connect it to our agent. Go back to your `agents/index.ts` file and update it:
4
+
5
+ 1. Import the tool:
6
+
7
+ ```typescript
8
+ import { getTransactionsTool } from "../tools";
9
+ ```
10
+
11
+ 2. Add the tool to your agent:
12
+
13
+ ```typescript
14
+ export const financialAgent = new Agent({
15
+ name: "Financial Assistant Agent",
16
+ instructions: `ROLE DEFINITION
17
+ // ... existing instructions ...
18
+
19
+ TOOLS
20
+ - Use the getTransactions tool to fetch financial transaction data.
21
+ - Analyze the transaction data to answer user questions about their spending.`,
22
+ model: openai("gpt-4o"),
23
+ tools: { getTransactionsTool }, // Add our tool here
24
+ });
25
+ ```
26
+
27
+ By adding the tool to your agent's configuration, you're making it available for the agent to use. The agent will now be able to call the `getTransactions` tool when it needs to access transaction data.
28
+
29
+ It's also important to update the agent's instructions to include information about the tool. This helps the agent understand when and how to use the tool to fulfill user requests.
@@ -0,0 +1,15 @@
1
+ # Testing Your Tool
2
+
3
+ Let's test our tool and agent in the playground:
4
+
5
+ 1. Make sure your development server is running with `npm run dev`
6
+ 2. Open the playground at http://localhost:4111/
7
+ 3. You can test the tool directly in the Tools tab to make sure it's working
8
+ 4. Then, try asking your agent questions like:
9
+ - "Can you show me my recent transactions?"
10
+ - "How much did I spend on Amazon?"
11
+ - "What was my largest transaction this month?"
12
+
13
+ Your agent should now be able to fetch the transaction data and answer questions about it. However, it doesn't yet have memory, so it won't remember previous conversations. We'll add that in the next step.
14
+
15
+ Testing your tool directly in the playground is a great way to verify that it's working correctly before integrating it with your agent. This helps you identify and fix any issues with the tool itself before troubleshooting potential issues with the agent's use of the tool.
@@ -0,0 +1,14 @@
1
+ # Understanding Memory in Agents
2
+
3
+ Memory is a crucial component for creating more natural and context-aware agents. It allows your agent to maintain context across multiple interactions with users.
4
+
5
+ Memory allows your agent to:
6
+
7
+ - Remember previous user questions and its own responses
8
+ - Maintain context across multiple interactions
9
+ - Provide more personalized and relevant responses
10
+ - Avoid asking for the same information repeatedly
11
+
12
+ Without memory, your agent would treat each interaction as if it were the first, leading to a disjointed and frustrating user experience. With memory, your agent can build on previous conversations, creating a more natural and helpful interaction.
13
+
14
+ In the following steps, we'll add memory to our financial assistant agent to make it more context-aware and capable of providing better responses over time.
@@ -0,0 +1,11 @@
1
+ # Installing Memory
2
+
3
+ First, we need to install the Mastra memory package to add memory capabilities to our agent. Run the following command in your terminal:
4
+
5
+ ```bash
6
+ npm install @mastra/memory
7
+ ```
8
+
9
+ The `@mastra/memory` package provides a simple yet powerful memory system for your Mastra agents. It allows your agent to remember previous conversations and maintain context across multiple interactions.
10
+
11
+ This package is separate from the core Mastra package to keep the framework modular and allow you to only include the features you need in your project.
@@ -0,0 +1,28 @@
1
+ # Adding Memory to Your Agent
2
+
3
+ Now, let's update our agent to include memory. Open your `agents/index.ts` file and make the following changes:
4
+
5
+ 1. Import the Memory class:
6
+
7
+ ```typescript
8
+ import { Agent } from "@mastra/core";
9
+ import { openai } from "@ai-sdk/openai";
10
+ import { Memory } from "@mastra/memory";
11
+ import { getTransactionsTool } from "../tools";
12
+ ```
13
+
14
+ 2. Add memory to your agent:
15
+
16
+ ```typescript
17
+ export const financialAgent = new Agent({
18
+ name: "Financial Assistant Agent",
19
+ instructions: `ROLE DEFINITION
20
+ // ... existing instructions ...
21
+ `,
22
+ model: openai("gpt-4o"),
23
+ tools: { getTransactionsTool },
24
+ memory: new Memory(), // Add memory here
25
+ });
26
+ ```
27
+
28
+ By adding the `memory` property to your agent configuration, you're enabling it to remember previous conversations. The `Memory` class from the `@mastra/memory` package provides a simple way to add memory capabilities to your agent.
@@ -0,0 +1,15 @@
1
+ # Testing Your Agent with Memory
2
+
3
+ Let's test our agent's memory capabilities in the playground:
4
+
5
+ 1. Make sure your development server is running with `npm run dev`
6
+ 2. Open the playground at http://localhost:4111/
7
+ 3. Start a conversation with your agent by asking about transactions
8
+ 4. Then, ask a follow-up question that references the previous conversation, like:
9
+ - "What was that largest transaction again?"
10
+ - "Can you categorize those Amazon purchases we talked about?"
11
+ - "How does my spending this month compare to what you showed me earlier?"
12
+
13
+ Your agent should now be able to remember previous conversations and provide more contextual responses.
14
+
15
+ With memory enabled, your agent can now maintain context across multiple interactions, creating a more natural and helpful user experience. This is especially important for financial assistants, where users may want to refer back to previous information or build on earlier conversations.
@@ -0,0 +1,20 @@
1
+ # Congratulations!
2
+
3
+ You've successfully built your first Mastra agent with:
4
+
5
+ - A well-defined system prompt
6
+ - A custom tool for fetching transaction data
7
+ - Memory for maintaining context across conversations
8
+
9
+ This is just the beginning of what you can do with Mastra. Here are some ways you could extend your agent:
10
+
11
+ - Add more tools or use MCP to expand its capabilities (we will cover this in the next lesson)
12
+ - Implement more sophisticated memory storage
13
+ - Create a workflow that combines multiple agents
14
+ - Deploy your agent to a production environment
15
+
16
+ For more information and advanced features, check out the [Mastra documentation](https://mastra.ai/docs).
17
+
18
+ ## Next Steps
19
+
20
+ In the next lesson, you'll learn how to integrate MCP (Model Context Protocol) servers with your Mastra agent to expand its capabilities even further. MCP servers allow your agent to access external data sources and APIs, making it even more powerful and versatile.
@@ -0,0 +1,15 @@
1
+ # Installing and Setting Up MCP
2
+
3
+ In this lesson, we'll learn how to enhance your Mastra agent with MCP (Model Context Protocol) servers. MCP allows your agent to access a wide range of external tools and services without having to write custom tool functions for each one.
4
+
5
+ ## What is MCP?
6
+
7
+ MCP (Model Context Protocol) is a standard that allows AI models to access external tools and services through a consistent interface. By integrating MCP servers with your Mastra agent, you can give it access to:
8
+
9
+ - Email services like Gmail
10
+ - Code repositories like GitHub
11
+ - Social media platforms
12
+ - Weather information
13
+ - News sources
14
+ - File systems
15
+ - And many more services
@@ -0,0 +1,11 @@
1
+ # Installing MCP
2
+
3
+ First, let's install the Mastra MCP package:
4
+
5
+ ```bash
6
+ npm install @mastra/mcp
7
+ ```
8
+
9
+ The `@mastra/mcp` package provides the necessary infrastructure to connect your Mastra agent to various MCP servers. This package handles the communication between your agent and the MCP servers, allowing your agent to access the tools and services provided by those servers.
10
+
11
+ Installing this package is the first step in enhancing your agent with MCP capabilities. Once installed, you'll need to configure it to connect to specific MCP servers, which we'll cover in the next steps.
@@ -0,0 +1,21 @@
1
+ # Setting Up MCP Configuration
2
+
3
+ Now, let's create a basic MCP configuration in your agent file. Open your `src/mastra/agents/index.ts` file and add the following imports:
4
+
5
+ ```typescript
6
+ import { MCPConfiguration } from "@mastra/mcp";
7
+ ```
8
+
9
+ Then, create a basic MCP configuration object:
10
+
11
+ ```typescript
12
+ const mcp = new MCPConfiguration({
13
+ servers: {
14
+ // We'll add servers in the next steps
15
+ },
16
+ });
17
+ ```
18
+
19
+ This configuration object will be used to specify which MCP servers your agent should connect to. The `servers` property is an object where each key is a unique identifier for a server, and the value contains the configuration for that server.
20
+
21
+ In the upcoming steps, we'll add various MCP servers to this configuration, giving your agent access to a wide range of tools and services.
@@ -0,0 +1,11 @@
1
+ # Initializing MCP Tools
2
+
3
+ Once you have the configuration set up, you need to initialize the MCP tools:
4
+
5
+ ```typescript
6
+ const mcpTools = await mcp.getTools();
7
+ ```
8
+
9
+ This asynchronous call fetches all the available tools from the configured MCP servers. The `getTools()` method connects to each server specified in your configuration, retrieves the available tools, and returns them in a format that can be used by your Mastra agent.
10
+
11
+ The `mcpTools` object will contain all the tools provided by the MCP servers you've configured. We'll add these tools to our agent in the next step.
@@ -0,0 +1,20 @@
1
+ # Updating Your Agent
2
+
3
+ Let's update your agent to use the MCP tools. Modify your agent definition to include the MCP tools:
4
+
5
+ ```typescript
6
+ export const personalAssistantAgent = new Agent({
7
+ name: "Personal Assistant",
8
+ instructions: `
9
+ You are a helpful personal assistant that can help with various tasks.
10
+
11
+ Keep your responses concise and friendly.
12
+ `,
13
+ model: openai("gpt-4o"),
14
+ tools: { ...mcpTools }, // Add MCP tools to your agent
15
+ });
16
+ ```
17
+
18
+ By spreading the `mcpTools` object into your agent's `tools` property, you're making all the tools from your configured MCP servers available to your agent. This allows your agent to access and use these tools when responding to user requests.
19
+
20
+ As we add more MCP servers in the upcoming steps, the `mcpTools` object will automatically include tools from those servers as well, giving your agent an expanding set of capabilities.
@@ -0,0 +1,12 @@
1
+ # Testing Your Setup
2
+
3
+ At this point, your agent doesn't have any MCP servers configured yet, but the basic setup is in place. Let's test that everything is working:
4
+
5
+ 1. Make sure your development server is running with `npm run dev`
6
+ 2. Open the playground at http://localhost:4111/
7
+ 3. You should see your "Personal Assistant" agent in the list of agents
8
+ 4. Try sending a message like "Hello, what can you help me with?"
9
+
10
+ The agent should respond, but it won't have any special capabilities yet. In the next steps, we'll add various MCP servers to give your agent powerful new abilities.
11
+
12
+ In the next step, we'll add the Zapier MCP server to give your agent access to email and social media tools.
@@ -0,0 +1,14 @@
1
+ # Adding the Zapier MCP Server
2
+
3
+ In this step, we'll add the Zapier MCP server to our agent, which will give it access to email, social media, and many other integrations available through Zapier.
4
+
5
+ ## What is Zapier MCP?
6
+
7
+ Zapier MCP is a server that provides access to thousands of apps and services through the Zapier platform. This includes:
8
+
9
+ - Email services (Gmail, Outlook, etc.)
10
+ - Social media platforms (Twitter/X, LinkedIn, etc.)
11
+ - Project management tools (Trello, Asana, etc.)
12
+ - And many more
13
+
14
+ By integrating the Zapier MCP server with your Mastra agent, you can give it access to all these services without having to write custom tool functions for each one. This significantly expands your agent's capabilities and makes it more useful for a wide range of tasks.
@@ -0,0 +1,16 @@
1
+ # Getting a Zapier MCP URL
2
+
3
+ First, you'll need to get a Zapier MCP URL. This typically requires:
4
+
5
+ 1. Creating a Zapier account if you don't have one
6
+ 2. Setting up the Zapier MCP integration by adding some tools (we will use Gmail in this example)
7
+ 3. Getting your unique MCP URL
8
+
9
+ For this example, we'll use an environment variable to store the URL:
10
+
11
+ ```bash
12
+ # Add this to your .env file
13
+ ZAPIER_MCP_URL=https://your-zapier-mcp-url.zapier.app
14
+ ```
15
+
16
+ Using an environment variable is a good practice for storing sensitive information like API URLs. It keeps the URL out of your code, making it easier to manage and more secure. It also allows you to use different URLs for different environments (development, staging, production) without changing your code.
@@ -0,0 +1,17 @@
1
+ # Updating Your MCP Configuration
2
+
3
+ Now, let's update your MCP configuration in `src/mastra/agents/index.ts` to include the Zapier server:
4
+
5
+ ```typescript
6
+ const mcp = new MCPConfiguration({
7
+ servers: {
8
+ zapier: {
9
+ url: new URL(process.env.ZAPIER_MCP_URL || ""),
10
+ },
11
+ },
12
+ });
13
+ ```
14
+
15
+ This configuration tells your agent how to connect to the Zapier MCP server. The `zapier` key is a unique identifier for this server in your configuration, and the `url` property specifies the URL of the Zapier MCP server.
16
+
17
+ The `new URL()` constructor creates a URL object from the string provided by the environment variable. The `|| ""` part provides a default empty string in case the environment variable is not set, which prevents your application from crashing if the environment variable is missing.
@@ -0,0 +1,29 @@
1
+ # Updating Your Agent's Instructions
2
+
3
+ Next, let's update your agent's instructions to include information about the Zapier tools:
4
+
5
+ ```typescript
6
+ export const personalAssistantAgent = new Agent({
7
+ name: "Personal Assistant",
8
+ instructions: `
9
+ You are a helpful personal assistant that can help with various tasks such as email
10
+ and scheduling social media posts.
11
+
12
+ You have access to the following tools:
13
+
14
+ 1. Gmail:
15
+ - Use these tools for reading and categorizing emails from Gmail
16
+ - You can categorize emails by priority, identify action items, and summarize content
17
+ - You can also use this tool to send emails
18
+
19
+ Keep your responses concise and friendly.
20
+ `,
21
+ model: openai("gpt-4o"),
22
+ tools: { ...mcpTools },
23
+ memory,
24
+ });
25
+ ```
26
+
27
+ Updating your agent's instructions is crucial for helping it understand when and how to use the tools available to it. By explicitly mentioning the Gmail tools in the instructions, you're giving your agent context about what these tools do and when to use them.
28
+
29
+ This helps the agent make better decisions about which tools to use when responding to user requests, resulting in more helpful and accurate responses.
@@ -0,0 +1,13 @@
1
+ # Testing the Zapier Integration
2
+
3
+ Let's test the Zapier integration:
4
+
5
+ 1. Make sure your development server is running with `npm run dev`
6
+ 2. Open the playground at http://localhost:4111/
7
+ 3. Try asking your agent to perform tasks that use Zapier, such as:
8
+ - "Get my last email"
9
+ - "Send an email to youremail@gmail.com with the subject 'Test' and body 'Hello, this is a test email'"
10
+
11
+ If everything is set up correctly, your agent should be able to use the Zapier tools to perform these tasks.
12
+
13
+ Testing your integration is an important step to ensure that your agent can properly access and use the Zapier tools. When you ask your agent to perform a task that requires Zapier, it should recognize the need to use the appropriate Zapier tool and make the necessary API calls to complete the task.
@@ -0,0 +1,17 @@
1
+ # Troubleshooting
2
+
3
+ If your agent can't access the Zapier tools, check:
4
+
5
+ 1. That your Zapier MCP URL is correct in your environment variables
6
+ 2. That you've properly set up the Zapier MCP integration
7
+ 3. That the tools are properly loaded by checking the Tools tab in the playground
8
+
9
+ Common issues include:
10
+
11
+ - Incorrect or missing environment variables
12
+ - Network connectivity problems
13
+ - Authentication issues with the Zapier MCP server
14
+
15
+ If you're having trouble, try restarting your development server after making changes to your environment variables or configuration. This ensures that the changes are properly loaded.
16
+
17
+ In the next step, we'll add the GitHub MCP server to give your agent the ability to monitor and interact with GitHub repositories.