Skip to main content
Model Context Protocol (MCP) servers expose external services as tools that the AI agent can call. Genie Helper uses three MCP servers: Directus (data layer), Ollama (LLM inference), and Stagehand (browser automation).

MCP Server Architecture

Servers are auto-booted on AnythingLLM startup via patched server/utils/boot/index.js.

MCP Server Configuration

Servers are defined in storage/plugins/anythingllm_mcp_servers.json:
After modifying this file, restart AnythingLLM: pm2 restart anything-llm

Adding a Tool to Existing Server

Let’s add a new tool to the Directus MCP server.

Example: Add bulk-delete-items Tool

File: scripts/directus-mcp-server.mjs

Tool Definition Anatomy

Key points:
  • Tool names use kebab-case
  • Descriptions help the AI understand when to use the tool
  • Zod schemas validate and document parameters
  • Always include .describe() for parameters
  • Return format: { content: [{ type: "text", text: "..." }] }

Creating a New MCP Server

Let’s create a new MCP server for Stripe payment integration.

1. Create Server Script

File: scripts/stripe-mcp-server.mjs

2. Make Script Executable

3. Add to MCP Config

File: storage/plugins/anythingllm_mcp_servers.json

4. Install Dependencies

5. Restart AnythingLLM

6. Verify Tools Loaded

Check AnythingLLM logs:
You should see:

MCP Server Templates

Basic HTTP API Server

Database Connection Server

Existing MCP Server Tools

Directus MCP (17 tools)

Collections:
  • list-collections — List all custom collections
  • get-collection-schema — Get field schema for a collection
Items CRUD:
  • read-items — Read items with filtering, sorting, pagination
  • read-item — Read single item by ID
  • create-item — Create new item
  • update-item — Update existing item
  • delete-item — Delete item
  • search-items — Full-text search
Flows:
  • trigger-flow — Trigger Directus Flow by UUID
  • list-flows — List all flows
Users:
  • get-me — Get current user info
  • list-users — List all users
  • get-user — Get user by ID
  • create-user — Create new user
  • update-user — Update user
Files:
  • list-files — List uploaded files
  • get-file — Get file metadata
See: scripts/directus-mcp-server.mjs

Ollama MCP (3 tools)

  • list-models — List locally available models
  • generate — Single-turn completion
  • chat — Multi-turn chat with history
See: scripts/ollama-mcp-server.mjs

Stagehand MCP (9 tools)

  • start-session — Create browser session
  • navigate — Navigate to URL
  • act — Perform action (click, type, etc.)
  • extract — Extract data using AI
  • observe — Observe page elements
  • close-session — End browser session
  • set-cookies — Inject cookies
  • get-cookies — Retrieve cookies
  • screenshot — Capture screenshot
See: scripts/stagehand-mcp-server.mjs

Best Practices

Tool Naming

  • Use kebab-case: get-user, create-payment-link
  • Be descriptive: bulk-delete-items not delete-many
  • Group by resource: user-create, user-update, user-delete

Parameter Descriptions

Always use .describe() for Zod schemas:
Descriptions are shown to the AI agent and improve tool selection accuracy.

Error Handling

Caching

For expensive operations, use caching:
See: server/utils/cache/extractCache.js for cache implementation pattern.

Debugging MCP Servers

View Server Logs

Test Tool Directly

MCP servers use stdio transport. Test with:

Common Issues

Tool not appearing in agent:
  • Check MCP config syntax in anythingllm_mcp_servers.json
  • Verify script path is absolute
  • Restart AnythingLLM: pm2 restart anything-llm
Environment variables not loaded:
  • Set in env block of MCP config, not in shell
  • Use absolute paths for any file references
Server crashes on startup:
  • Check pm2 logs anything-llm for stack trace
  • Verify all dependencies installed: npm install
  • Test script directly: node scripts/my-mcp-server.mjs

Auto-boot Implementation

MCP servers are automatically started by patched AnythingLLM boot sequence. File: server/utils/boot/index.js
This ensures MCP servers are available when the agent starts.

Next Steps

Custom Actions

Use MCP tools in Action Runner flows

Project Structure

Understand where MCP servers fit