text stringlengths 0 59.1k |
|---|
// and communicate with it via standard input/output. |
type: "stdio", |
command: "npx", |
args: ["-y", "@modelcontextprotocol/server-filesystem", path.resolve("./data")], |
}, |
}, |
}); |
const mcpAgent = new Agent({ |
name: "MCP Filesystem Agent", |
instructions: "You can interact with the local filesystem. List files, read files, write files.", |
llm: new VercelAIProvider(), |
model: openai("gpt-4o-mini"), |
tools: await mcpConfig.getTools(), |
}); |
new VoltAgent({ |
agents: { |
fsAgent: mcpAgent, |
}, |
}); |
``` |
**Code Breakdown (My Understanding):** |
- **`MCPConfiguration`:** This is where I defined the `filesystem` server connection. |
- `type: "stdio"` tells VoltAgent it's a local command to run. |
- `command: "npx"` specifies _how_ to run it. |
- `args: [...]` provides the details: the MCP server package (`@modelcontextprotocol/server-filesystem`) and, crucially, `path.resolve("./data")`. This locks the server down, only allowing it to see inside a `./data` folder within my project. **I had to remember to actually create this `data` folder later (`mkdir dat... |
- **`Agent` Definition:** I created my `Agent` instance. The key part is `tools: await mcpConfig.getTools()`. This line tells VoltAgent: "Go connect to all the servers I defined in `mcpConfig`, find out what tools they offer (like `readFile`, `writeFile` from the filesystem server), and make those tools available for t... |
- **`VoltAgent` Initialization:** I started the main VoltAgent server and registered my `mcpAgent` under the key `fsAgent`. This key is how I'll select it in the VoltOps LLM Observability Platform. |
#### Running the Agent |
Before running, we need two things: an API key for the LLM and the `data` directory we restricted the MCP server to. |
1. **Create `.env` file:** In the root of the `mcp-filesystem-agent` project, I created a file named `.env`. |
2. **Add API Key:** Inside `.env`, I added my OpenAI key: |
```bash title=".env" |
OPENAI_API_KEY=your_openai_api_key_here |
``` |
(Obviously, replace `your_openai_api_key_here` with your actual key). |
3. **Create `data` Directory and Test File:** In the terminal, still in the project root: |
```bash |
mkdir data |
echo "Hello from the MCP agent's accessible file!" > data/test.txt |
``` |
4. **Install Dependencies:** Make sure all packages are installed: |
<Tabs> |
<TabItem value="npm" label="npm" default> |
```bash |
npm install |
``` |
</TabItem> |
<TabItem value="yarn" label="yarn"> |
```bash |
yarn install |
``` |
</TabItem> |
<TabItem value="pnpm" label="pnpm"> |
```bash |
pnpm install |
``` |
</TabItem> |
</Tabs> |
5. **Start the Agent:** Run the development server: |
<Tabs> |
<TabItem value="npm" label="npm" default> |
```bash |
npm run dev |
``` |
</TabItem> |
<TabItem value="yarn" label="yarn"> |
```bash |
yarn dev |
``` |
</TabItem> |
<TabItem value="pnpm" label="pnpm"> |
```bash |
pnpm dev |
``` |
</TabItem> |
</Tabs> |
I saw the VoltAgent server startup message, including the link to the VoltOps Platform: |
```bash |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.