MCP Server - Model Context Protocol Server
📋 Table of Contents
🎯 What is an MCP Server?
🏗️ MCP Architecture
🚀 Transport Types
🔄 Transport Flow Comparison
🌐 HTTP Transport (Web)
🖥️ STDIO Transport (Command-Line)
🎯 Choosing a Transport
Scenario
Recommended Transport
Quick Start
1. Register Tools
2. Access the MCP Endpoint
Custom URL Entry Points
Server Configuration
Creating a Server
Configure Description and Version
Get Server Info
Basic Authentication 🔒
CORS Configuration 🌐
Request Body Size Limits 📏
Custom API Key Validation 🔑
Security Headers 🛡️
Tool Registration
Register a Single Tool
Register Multiple Tools
Check and Retrieve Tools
List Tools (MCP Format)
Unregister Tools
Annotation-Based Discovery
Scan for Annotations
@mcpTool Annotation
@mcpResource Annotation
@mcpPrompt Annotation
Resource Registration
Register a Resource
Register Dynamic Resources
List and Read Resources
Manage Resources
Prompt Registration
Register a Prompt
List and Get Prompts
Handling MCP Requests
Direct Request Handling
Handle JSON String
Supported Methods
Method
Description
HTTP Endpoint (mcp.bxm)
Discovery (GET)
JSON-RPC Requests (POST)
Multiple Servers
CORS Support
Static Server Management
Check Server Existence
Get All Server Names
Remove a Server
Clear All Servers
Complete Example
Application Setup
Connecting from AI Client
Events & Interception 🎯
Available Events
onMCPServerCreate
onMCPServerCreateonMCPServerRemove
onMCPServerRemoveonMCPRequest
onMCPRequestonMCPResponse
onMCPResponseonMCPError ⚠️
onMCPError ⚠️Registering Event Listeners
For BoxLang Module Registration
For Application/Script Registration
Event Use Cases
Custom Logging
Metrics & Monitoring
Rate Limiting
Error Alerting
Statistics & Monitoring 📊
Enabling Statistics
Retrieving Statistics
Get Summary Statistics
Get Detailed Statistics
Managing Statistics
Check if Stats are Enabled
Enable/Disable Tracking
Reset Statistics
Dashboard Example
Using Stats with Events
Performance Notes
API Integration Example
Best Practices
1. Use Descriptive Names
2. Register at Application Start
3. Clean Up on Shutdown
4. Use Separate Servers for Different Purposes
5. Secure Sensitive Servers
6. Document Your Tools
7. Monitor Performance with Statistics
Related Documentation
External Resources
Last updated