Skip to main content

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:
stdio transport not supported yet: Local MCP servers (using npx, node, etc.) are not supported yet. Please use remote MCP servers with streamable-http or sse transport instead.

Constructor

new LuaMCPServer(config)

Creates a new MCP server configuration.
LuaMCPServerConfig
required
MCP server configuration object

Configuration Parameters

Required Fields

string
required
Unique identifier for the MCP serverFormat: lowercase, hyphens allowedExamples: 'docs-server', 'api-gateway', 'database'
'streamable-http' | 'sse'
required
Transport protocol for communication
  • 'streamable-http' - Modern MCP standard (recommended)
  • 'sse' - Legacy Server-Sent Events transport
string | (() => string)
required
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

Record<string, string> | (() => Record<string, string>)
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 $` })`
number
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

During lua compile, MCP servers are:
  1. Detected from your source code
  2. Registered with the server (if new)
  3. Assigned an ID stored in lua.skill.yaml
  4. Configuration written to dist/mcp-servers.json

Push

Push individual MCP server:
Or push all components:

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

Always use env() for API keys and tokens
Adjust timeout based on expected operation duration
Prefer streamable-http transport for new MCP server integrations
Keep unused servers deactivated to reduce overhead

Troubleshooting

Make sure the server is activated:
Check the URL is accessible and increase timeout:
Verify your API key is correct and set in environment:
Local MCP servers (stdio) are no longer supported. Migrate to remote servers:

LuaAgent

Agent configuration with MCP servers

LuaSkill

Custom tool collections

Environment

Managing environment variables

MCP Command

CLI management commands

See Also