Overview
LuaMCPServer allows you to connect external MCP (Model Context Protocol) servers to your agent. MCP servers provide additional tools that your agent can use at runtime, enabling integration with file systems, databases, APIs, and more.
What is MCP? The Model Context Protocol (MCP) is an open standard for connecting AI models to external tools and data sources. Learn more at modelcontextprotocol.io.
Why MCP Servers?
Extend Capabilities
Add tools without writing code - use existing MCP servers
Standard Protocol
Compatible with any MCP-compliant server
Local or Remote
Run servers locally (stdio) or connect to remote endpoints (SSE)
Community Ecosystem
Access growing library of community MCP servers
Transport Types
MCP servers support two transport methods:- stdio (Local)
- sse (Remote)
Best for: Local execution, npm packages, CLI toolsThe server runs as a local process. Your agent communicates via stdin/stdout.
Constructor
new LuaMCPServer(config)
Creates a new MCP server configuration.MCP server configuration object
Configuration Parameters
Required Fields
Unique identifier for the MCP serverFormat: lowercase, hyphens allowedExamples:
'filesystem', 'github-server', 'database'Transport protocol for communication
'stdio'- Local process via stdin/stdout'sse'- Remote server via Server-Sent Events
stdio Transport Fields
Command to execute the MCP serverRequired when:
transport: 'stdio'Examples: 'npx', 'node', 'python'Arguments to pass to the commandExample:
['-y', '@modelcontextprotocol/server-filesystem', '/data']Environment variables for the server processExample:
{ 'API_KEY': 'secret123' }SSE Transport Fields
URL of the remote MCP serverRequired when:
transport: 'sse'Example: 'https://mcp.example.com/sse'HTTP headers to send with requestsExample:
{ 'Authorization': 'Bearer token' }Optional Fields
Timeout in milliseconds for server operationsDefault:
60000 (60 seconds)Examples
Filesystem Access
GitHub Integration
Remote Database Server
Brave Search
Using with LuaAgent
MCP servers are added to your agent configuration:Lifecycle Management
Compile
Duringlua compile, MCP servers are:
- Detected from your source code
- Registered with the server (if new)
- Assigned an ID stored in
lua.skill.yaml - Configuration written to
dist/mcp-servers.json
Push
Push individual MCP server:Activate / Deactivate
MCP servers start inactive. Activate to make tools available:List / Delete
YAML Configuration
After compilation,lua.skill.yaml tracks MCP servers:
The YAML only stores
name and mcpServerId. The full configuration (command, args, url, etc.) lives in your source code.Best Practices
✅ Use Environment Variables for Secrets
✅ Use Environment Variables for Secrets
Never hardcode API keys or tokens
✅ Set Appropriate Timeouts
✅ Set Appropriate Timeouts
Adjust timeout based on expected operation duration
✅ Restrict Paths for Filesystem Access
✅ Restrict Paths for Filesystem Access
Only expose necessary directories
✅ Activate Only What You Need
✅ Activate Only What You Need
Keep unused servers deactivated to reduce overhead
Popular MCP Servers
| Server | Description | Install |
|---|---|---|
| Filesystem | Read/write local files | @modelcontextprotocol/server-filesystem |
| GitHub | GitHub API integration | @modelcontextprotocol/server-github |
| Brave Search | Web search via Brave | @anthropic/mcp-server-brave-search |
| SQLite | SQLite database access | @modelcontextprotocol/server-sqlite |
| Postgres | PostgreSQL database | @modelcontextprotocol/server-postgres |
| Google Drive | Google Drive files | @anthropic/mcp-server-gdrive |
Check modelcontextprotocol.io/servers for the full list of available MCP servers.
Troubleshooting
Server not found after push
Server not found after push
Make sure the server is activated:
Command not found (stdio)
Command not found (stdio)
Ensure the command is installed and in PATH:
Connection timeout (sse)
Connection timeout (sse)
Check the URL is accessible and increase timeout:
Authentication failed
Authentication failed
Verify your API key or token is correct:
Related APIs
LuaAgent
Agent configuration with MCP servers
LuaSkill
Custom tool collections
Environment
Managing environment variables
MCP Command
CLI management commands
See Also
- MCP Servers Overview - Conceptual introduction
- MCP Command - CLI management
- LuaAgent - Adding MCP servers to your agent

