For the complete documentation index, see llms.txt. This page is also available as Markdown.

Server Configuration

Configure authentication, CORS, request limits, and other security settings for your MCP server.

Configure authentication, CORS, request limits, and other security settings for your MCP server.

Creating a Server

// Get or create a server instance (singleton by name)
server = MCPServer( "myApp" )

// Multiple servers for different purposes
apiServer = MCPServer( "api" )
adminServer = MCPServer( "admin" )

Server Info

server = MCPServer( "myApp" )
    .setDescription( "My Application MCP Server" )
    .setVersion( "2.0.0" )

// Get server info
info = server.getServerInfo()
// { name: "myApp", version: "2.0.0", description: "..." }

Basic Authentication πŸ”’

Protect your server with HTTP Basic Authentication:

How it works:

  • Credentials verified before any request processing

  • Returns 401 Unauthorized if invalid

  • Uses standard HTTP Basic Authentication (base64-encoded username:password)

  • Zero overhead when not configured

Making authenticated requests:

Check if enabled:

Best Practices:

  • βœ… Always use HTTPS in production

  • βœ… Store passwords in environment variables

  • βœ… Use strong, unique passwords

  • βœ… Combine with CORS settings

  • βœ… Log authentication failures

Example with environment variables:

CORS Configuration 🌐

Control which origins can access your server:

Wildcard Patterns:

  • *.example.com β€” Matches any subdomain

  • * β€” Matches all origins

  • Exact matches β€” Only specific origins

Dynamic Management:

Security:

  • βœ… Avoid * in production

  • βœ… Use HTTPS origins

  • βœ… Combine with authentication

  • βœ… Review periodically

IP Allow Lists 🌍

Restrict access to specific client IPs and CIDR ranges.

How it works:

  • If no allow list is configured, all IPs are allowed

  • Exact IP matches are supported (for example 203.0.113.10)

  • CIDR ranges are supported (for example 203.0.113.0/24)

  • Non-matching requests are rejected with 403 Forbidden

Request extraction order for client IP:

  1. x-forwarded-for

  2. cf-connecting-ip

  3. true-client-ip

  4. x-real-ip

  5. Fallback to connection remote address

Proxy deployment tip:

  • Ensure your proxy/load balancer forwards the expected client IP headers

  • Keep trusted proxy infrastructure under your control to avoid spoofed headers

Built-in BoxLang MCP server configuration:

Request Body Size Limits πŸ“

Protect against large payloads:

How it works:

  • Checks body size before processing

  • Returns 413 Payload Too Large if exceeded

  • Default is 0 (unlimited)

  • Applies to entire JSON-RPC request

Get current limit:

Use Cases:

  • Public APIs β€” Prevent abuse

  • Resource constraints β€” Match server limits

  • Tool-specific limits β€” Different servers, different limits

  • DoS prevention β€” Basic protection

Example β€” Tiered Limits:

Custom API Key Validation πŸ”‘

Implement custom authentication logic:

Provider Function Signature:

API Key Extraction: The server automatically extracts keys from:

  1. X-API-Key header

  2. Authorization: Bearer <token> header

Making requests:

Multi-Tenant Example:

Combining Security Features

Use multiple layers together:

Security Processing Order πŸ”

When a request arrives, checks execute in this order:

  1. Body Size Check β€” Reject oversized payloads first

  2. IP Allow List Check β€” Reject disallowed client addresses

  3. CORS Validation β€” Check origin header

  4. Basic Authentication β€” Verify credentials

  5. API Key Validation β€” Call custom provider

  6. Request Processing β€” Only after all checks pass

Short-Circuit Behavior:

  • Each layer can immediately reject the request

  • Failed checks return error responses

  • Security headers always included in responses

  • Events fired for all security failures

  • IP allow list failures return 403 Forbidden

Security Headers πŸ›‘οΈ

All HTTP responses automatically include industry-standard security headers:

Header
Value
Purpose

X-Content-Type-Options

nosniff

Prevents MIME type sniffing

X-Frame-Options

DENY

Blocks iframe embedding

X-XSS-Protection

1; mode=block

Enables XSS filtering

Referrer-Policy

strict-origin-when-cross-origin

Controls referrer leaking

Content-Security-Policy

default-src 'none'

Restricts resource loading

Strict-Transport-Security

max-age=31536000

Forces HTTPS (HTTPS only)

Permissions-Policy

Disables geo/mic/camera

Disables sensitive APIs

No configuration needed β€” Headers applied automatically!

Next Steps

Last updated