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 APIs, databases, documentation services, 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
Remote Integration
Connect to hosted MCP services via HTTP
Community Ecosystem
Access growing library of hosted MCP servers
Transport Types
MCP servers support two HTTP-based transport methods:- Streamable HTTP (Recommended)
- SSE (Legacy)
Best for: Modern MCP servers, most use casesThe modern MCP standard (spec 2025-03-26) with bidirectional communication.
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:
'docs-server', 'api-gateway', 'database'Transport protocol for communication
'streamable-http'- Modern MCP standard (recommended)'sse'- Legacy Server-Sent Events transport
URL of the remote MCP serverCan be a static string or a function that returns the URL at runtime using
env().Examples:'https://mcp.example.com/mcp'() => env("MCP_SERVER_URL")
Optional Fields
HTTP headers to send with requestsCan be a static object or a function that returns headers at runtime using
env().Example (static): { 'X-Custom-Header': 'value' }Example (dynamic): () => ({ 'Authorization': \Bearer $` })`Timeout in milliseconds for server operationsDefault:
60000 (60 seconds)Examples
Documentation Server
API Gateway
Database Service
Dynamic URL with env()
Legacy SSE Server
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 (url, headers, etc.) lives in your source code.Best Practices
Use env() for Secrets
Use env() for Secrets
Always use
env() for API keys and tokensSet Appropriate Timeouts
Set Appropriate Timeouts
Adjust timeout based on expected operation duration
Use Streamable HTTP for New Integrations
Use Streamable HTTP for New Integrations
Prefer
streamable-http transport for new MCP server integrationsActivate Only What You Need
Activate Only What You Need
Keep unused servers deactivated to reduce overhead
Troubleshooting
Server not found after push
Server not found after push
Make sure the server is activated:
Connection timeout
Connection timeout
Check the URL is accessible and increase timeout:
Authentication failed
Authentication failed
Verify your API key is correct and set in environment:
stdio transport error
stdio transport error
Local MCP servers (stdio) are no longer supported. Migrate to remote servers:
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

