MCP Server Architecture
server/utils/boot/index.js.
MCP Server Configuration
Servers are defined instorage/plugins/anythingllm_mcp_servers.json:
After modifying this file, restart AnythingLLM:
pm2 restart anything-llmAdding 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
- 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:MCP Server Templates
Basic HTTP API Server
Database Connection Server
Existing MCP Server Tools
Directus MCP (17 tools)
Collections:list-collections— List all custom collectionsget-collection-schema— Get field schema for a collection
read-items— Read items with filtering, sorting, paginationread-item— Read single item by IDcreate-item— Create new itemupdate-item— Update existing itemdelete-item— Delete itemsearch-items— Full-text search
trigger-flow— Trigger Directus Flow by UUIDlist-flows— List all flows
get-me— Get current user infolist-users— List all usersget-user— Get user by IDcreate-user— Create new userupdate-user— Update user
list-files— List uploaded filesget-file— Get file metadata
scripts/directus-mcp-server.mjs
Ollama MCP (3 tools)
list-models— List locally available modelsgenerate— Single-turn completionchat— Multi-turn chat with history
scripts/ollama-mcp-server.mjs
Stagehand MCP (9 tools)
start-session— Create browser sessionnavigate— Navigate to URLact— Perform action (click, type, etc.)extract— Extract data using AIobserve— Observe page elementsclose-session— End browser sessionset-cookies— Inject cookiesget-cookies— Retrieve cookiesscreenshot— Capture screenshot
scripts/stagehand-mcp-server.mjs
Best Practices
Tool Naming
- Use kebab-case:
get-user,create-payment-link - Be descriptive:
bulk-delete-itemsnotdelete-many - Group by resource:
user-create,user-update,user-delete
Parameter Descriptions
Always use.describe() for Zod schemas:
Error Handling
Caching
For expensive operations, use caching: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
- Set in
envblock of MCP config, not in shell - Use absolute paths for any file references
- Check
pm2 logs anything-llmfor 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
Next Steps
Custom Actions
Use MCP tools in Action Runner flows
Project Structure
Understand where MCP servers fit
