MCP server APIs
The Model Context Protocol (MCP) server APIs provide endpoints for managing and interacting with MCP tools in Lucenia. These APIs allow you to register tools, establish streaming connections, and communicate with the MCP server through Server-Sent Events (SSE).
This is an experimental feature and is not recommended for use in a production environment. For updates on its progress, see the Lucenia version history.
Prerequisites
Before using MCP server APIs, ensure that:
- The default HTTP transport method does not support streaming. You must install the
transport-reactor-netty4
HTTP transport plugin and use it as the default HTTP transport layer:# Install the transport plugin
./bin/lucenia-plugin install transport-reactor-netty4
# Configure as default transport in lucenia.yml
http.type: reactor-netty4 - You have appropriate permissions to manage ML Commons resources
API overview
The MCP server APIs provide the following functionality:
Tool management APIs
- Register MCP tools: Register one or more MCP-based tools with the server
- Update MCP tools: Update existing MCP tool configurations
- List MCP tools: Retrieve information about registered MCP tools
- Remove MCP tools: Unregister MCP tools from the server
Streaming communication APIs
- MCP SSE session: Create and manage Server-Sent Events sessions
- MCP SSE message: Send and receive messages through the SSE interface
Base endpoint
All MCP server APIs are accessed through the following base endpoint:
/_plugins/_ml/mcp/
Authentication and security
MCP server APIs require authentication. Include appropriate authentication headers based on your Lucenia security configuration:
# Example with basic authentication
curl -X GET "https://localhost:9200/_plugins/_ml/mcp/tools" \
-H "Authorization: Basic $(echo -n 'username:password' | base64)" \
-H "Content-Type: application/json"
Common parameters
Standard request headers
Content-Type
:application/json
for most requestsAccept
:text/event-stream
for SSE endpointsAuthorization
: Authentication credentials
Common response fields
All MCP API responses include standard fields:
{
"success": true,
"message": "Operation completed successfully",
"data": {
// API-specific response data
},
"timestamp": "2024-01-01T12:00:00Z"
}
Error handling
MCP server APIs return standard HTTP status codes and error responses:
Success responses
200 OK
: Successful operation201 Created
: Resource created successfully204 No Content
: Successful operation with no response body
Error responses
400 Bad Request
: Invalid request parameters401 Unauthorized
: Authentication required403 Forbidden
: Insufficient permissions404 Not Found
: Resource not found409 Conflict
: Resource already exists500 Internal Server Error
: Server error
Error response format
{
"success": false,
"error": {
"type": "ValidationError",
"message": "Invalid tool configuration",
"details": {
"field": "tool_name",
"reason": "Tool name cannot be empty"
}
},
"timestamp": "2024-01-01T12:00:00Z"
}
Rate limiting
MCP server APIs are subject to rate limiting to ensure system stability:
- Default limit: 100 requests per minute per client
- Burst limit: 10 requests per second
- Rate limit headers: Responses include rate limit information
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1609459200
Usage patterns
1. Tool discovery and registration
# Register tools with the MCP server
POST /_plugins/_ml/mcp/tools
{
"tools": [
{
"name": "search_documents",
"description": "Search through document collection",
"parameters": {
"query": {
"type": "string",
"description": "Search query"
}
}
}
]
}
2. Streaming communication
# Establish SSE session
GET /_plugins/_ml/mcp/sse
Accept: text/event-stream
# Send messages through the session
POST /_plugins/_ml/mcp/sse/message
{
"session_id": "session-123",
"message": {
"type": "tool_call",
"tool": "search_documents",
"parameters": {
"query": "machine learning"
}
}
}
Monitoring and debugging
Server status
Check the MCP server status:
GET /_plugins/_ml/mcp/status
Active sessions
List active SSE sessions:
GET /_plugins/_ml/mcp/sessions
Logs
Monitor MCP server logs for debugging:
tail -f logs/lucenia.log | grep "MCP"
Best practices
- Connection management: Properly close SSE connections when no longer needed
- Error handling: Implement robust error handling for network issues
- Tool naming: Use descriptive, unique names for MCP tools
- Security: Always use HTTPS in production environments
- Rate limiting: Implement client-side rate limiting to avoid hitting server limits
Validation rules
Tool name validation
- Must be unique across all tools
- Can contain alphanumeric characters and underscores only
- Must be between 3 and 50 characters
- Cannot start with a number
Parameter schema validation
- Must follow JSON Schema Draft 7 specification
- Required parameters cannot have default values
- Enum values must match the parameter type
- Nested objects must have proper schema definitions
Version management
- Version strings should follow semantic versioning (semver)
- Major version changes require explicit confirmation
- Breaking changes should be documented in metadata