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 Unauthorizedif invalidUses 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 originsExact 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:
x-forwarded-forcf-connecting-iptrue-client-ipx-real-ipFallback 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 Largeif exceededDefault 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:
X-API-KeyheaderAuthorization: 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:
Body Size Check β Reject oversized payloads first
IP Allow List Check β Reject disallowed client addresses
CORS Validation β Check origin header
Basic Authentication β Verify credentials
API Key Validation β Call custom provider
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:
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
π§© Registering Tools β Add functionality
π Observability β Monitor requests
ποΈ Class-Based Servers β Organize complex servers
β Best Practices β Production setup
Last updated