Skip to main content

What are MCP Servers?

MCP Servers are remote services that provide additional tools to your agent using the Model Context Protocol (MCP). Instead of building every tool from scratch, you can connect to existing MCP servers that provide database queries, web searches, documentation access, and more.

Think of it as:

Plug-and-play extensions for your agent - connect to pre-built tools without writing code
What is MCP? The Model Context Protocol is an open standard developed by Anthropic for connecting AI models to external tools and data sources. Learn more at modelcontextprotocol.io.

Why MCP Servers?

No Code Required

Use existing MCP servers - just configure and connect

Open Standard

MCP is an open protocol with a growing ecosystem

Extend Capabilities

Add databases, web search, documentation access, and more

Mix & Match

Combine MCP servers with your custom LuaSkills

How MCP Servers Work

1

Configure Server

Define the MCP server in your code with transport and connection details
2

Compile & Push

Run lua compile and lua push mcp to register with the platform
3

Activate

Activate the server to make its tools available to your agent
4

Agent Uses Tools

Your agent automatically discovers and uses the MCP server’s tools

Transport Types

MCP servers connect via HTTP-based transports:
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.

Simple Example

import { LuaAgent, LuaMCPServer, LuaSkill, env } from 'lua-cli';

// Connect to a remote MCP server
const docsServer = new LuaMCPServer({
  name: 'docs',
  transport: 'streamable-http',
  url: 'https://docs.example.com/mcp',
  headers: () => ({
    'Authorization': `Bearer ${env("DOCS_API_KEY")}`
  })
});

// Your custom skill
const coreSkill = new LuaSkill({
  name: 'core-skill',
  description: 'Core tools',
  tools: [...]
});

export const agent = new LuaAgent({
  name: 'docs-assistant',
  persona: 'You are a helpful assistant with access to documentation.',
  skills: [coreSkill],
  
  // Add MCP server
  mcpServers: [docsServer]
});

Common Use Cases

Access documentation and knowledge bases
import { LuaMCPServer, env } from 'lua-cli';

const docsServer = new LuaMCPServer({
  name: 'docs',
  transport: 'streamable-http',
  url: 'https://docs.example.com/mcp',
  headers: () => ({
    'Authorization': `Bearer ${env("DOCS_API_KEY")}`
  })
});
Tools provided vary by server:
  • search_docs - Search documentation
  • get_page - Get specific page content
  • list_sections - Browse documentation structure

Environment Variables

MCP servers often need API keys or connection strings. Use the env() function to securely access environment variables at runtime:
Setting Environment Variables: Use lua env production to manage your agent’s environment variables. These are securely stored and made available to the env() function at runtime.

Dynamic URL with env()

You can also use env() to resolve the URL at runtime:
import { LuaMCPServer, env } from 'lua-cli';

const apiServer = new LuaMCPServer({
  name: 'my-api',
  transport: 'streamable-http',
  url: () => env("MCP_SERVER_URL"),
  headers: () => ({
    'Authorization': `Bearer ${env("API_TOKEN")}`
  })
});

MCP vs Custom Skills

AspectMCP ServersLuaSkill
Code RequiredNone (just config)Yes (TypeScript)
CustomizationLimited to server optionsFull control
AvailabilityGrowing ecosystemUnlimited
Best ForStandard integrationsCustom business logic
Best practice: Use MCP servers for standard integrations (docs, APIs, databases) and LuaSkill for custom business logic. They work great together!

Lifecycle

MCP servers have a simple lifecycle:
Define → Compile → Push → Activate → Use → Deactivate
Create LuaMCPServer in your source code
Run lua compile - registers server and gets ID
Run lua push mcp or lua push all --force - syncs configuration
Run lua mcp activate - makes tools available to agent
Agent discovers and uses MCP server tools at runtime
Run lua mcp deactivate - removes tools from agent

Managing MCP Servers

Use the lua mcp command to manage servers:
lua mcp list        # List all MCP servers and their status
lua mcp activate    # Activate a server (make tools available)
lua mcp deactivate  # Deactivate a server (remove tools)
lua mcp delete      # Delete a server from the platform

Next Steps