MCP Integration
Luna connects to Model Context Protocol (MCP) servers to extend the agent’s capabilities beyond built-in tools. MCP servers provide additional tools, resources, and prompt templates through a standardized JSON-RPC protocol.
Overview
Luna Agent
|
+-- Built-in tools (bash, read_file, write_file, ...)
|
+-- MCP Manager
+-- MCP Server 1 (stdio) -> filesystem tools
+-- MCP Server 2 (stdio) -> GitHub tools
+-- MCP Server 3 (stdio) -> database tools
MCP tools are discovered automatically on connection and merged with built-in tools. The LLM sees all tools (built-in + MCP) in its tool list, prefixed with mcp__.
Protocol Version
Luna implements the Model Context Protocol specification (2025-03-26), supporting:
initialize handshake with capability negotiation
tools/list for tool discovery
tools/call for tool execution
resources/read for resource access
prompts/get for prompt template retrieval
Transport
stdio Transport
Communication via stdin/stdout JSON-RPC. Each server runs as a separate subprocess.
Content-Length header support for framing
Multi-server support – connect to multiple MCP servers simultaneously
Best-effort connection model
HTTP Transport
Luna also supports HTTP-based MCP servers for remote tool access. HTTP transport enables connections to MCP servers that are not local processes.
Configuration
Global Config: ~/.luna/mcp.json
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..."
}
}
}
}
Project-local Config: .luna/mcp.json
Same format as global config. Project-local config is merged with global config. Global configuration takes precedence on conflicts; project-local HTTP/SSE servers require a hash-keyed approval, and project-local credential families are stripped without consent.
Config Structure
| Field | Type | Required | Description |
|---|---|---|---|
command | string | Yes | Command to start the MCP server |
args | array | No | Arguments to pass to the command |
env | object | No | Environment variables for the server process |
Tool Discovery
When Luna starts:
- Reads MCP config (global + project-local, merged)
- Starts each configured server as a subprocess
- Sends
initializeandtools/listJSON-RPC requests - Merges discovered tools into the agent’s tool registry
- The LLM sees all tools (built-in + MCP) in its system prompt
Discovered MCP tools are prefixed with mcp__ in the tool registry (e.g., mcp__github_create_issue).
Multi-Server Management
Luna can connect to multiple MCP servers simultaneously. Each server runs as an independent subprocess with its own lifecycle:
Servers are started in parallel during initialization
Each server’s tools are namespaced by server name
If one server fails, others continue operating normally
Use mcp_read_resource and mcp_get_prompt with the optional server parameter to target a specific server
OAuth PKCE
Luna supports OAuth 2.0 with PKCE (Proof Key for Code Exchange) for MCP servers that require authentication:
- Luna generates a code verifier and challenge
- Starts a local callback server via FFI raw socket
- Opens the authorization URL in the user’s browser
- Receives the authorization code at the callback URL
- Exchanges the code for an access token using the code verifier
- Stores the token for subsequent API calls
OAuth configuration is specified per-server in the MCP config.
Luna as MCP Server
Luna can also act as an MCP server, exposing its built-in tools to external MCP clients. This enables other applications to use Luna’s file operations, code intelligence, and other capabilities through the standard MCP protocol.
When running as an MCP server, Luna:
Responds to initialize and tools/list requests
Executes tools via tools/call and returns results
Supports the same JSON-RPC message format
Example MCP Servers
Filesystem Access
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
}
}
}
GitHub Integration
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..."
}
}
}
}
PostgreSQL Queries
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user:pass@localhost/db"]
}
}
}
Custom MCP Server
Any MCP-compatible server can be used. The server must:
- Accept JSON-RPC requests on stdin
- Respond with JSON-RPC responses on stdout
- Support
initializeandtools/listmethods - Follow the MCP specification
Best-Effort Connection
MCP connections are best-effort:
| Scenario | Behavior |
|---|---|
| Server fails to start | Luna logs a warning and continues without its tools |
| Server crashes mid-session | Luna logs the error and continues with remaining tools |
| Server restarts | Manual restart required |
Troubleshooting
MCP server not connecting:
Check the command path is correct and the binary exists
Check args are properly formatted
Check environment variables (especially API keys)
Look for errors in ~/.luna/logs/
MCP tools not appearing:
Ensure the server supports tools/list method
Check that the server starts without errors
Verify the server responds to initialize request
Use /tools-reload to rescan after fixing configuration
Enterprise: Microsoft MCP Gateway
For organizations managing fleets of MCP servers, WILDZERG Enterprise integrates with Microsoft MCP Gateway (MIT license — a separate Microsoft component, licensed/distributed independently, integrated at the MCP protocol layer). The gateway provides:
Reverse proxy with session-aware stateful routing to MCP server pods
Lifecycle management — deploy, update, delete MCP servers via REST API
Tool Gateway Router — dynamic routing of tool calls to registered tool servers by name
Management portal — React SPA at /portal/ for browsing and testing adapters in-browser
RBAC — mcp.admin and mcp.engineer roles, bridged to GLAuth/Dex identity
MCP Gateway runs on Kubernetes (k0s on blue for dev; customer’s own k8s cluster for Enterprise). See:
corp/docs/mcp-gateway-integration-strategy.md — three-layer MCP architecture (Luna client + Luna server + MCP Gateway management)
corp/docs/k0s-evaluation.md — k0s deployment analysis and root cause resolution
wild/k0s/mcp-gateway.yaml — Kubernetes manifest (Deployment + Service + RBAC)
ZERG is the agent runtime. MCP Gateway’s built-in Foundry agent runtime is always disabled (FoundrySettings:Endpoint=""). Luna provides the agent execution; MCP Gateway provides the management plane.