4.5 KiB
4.5 KiB
Multi-Interface Plugin Example
This example demonstrates a plugin that implements all plugin interfaces:
HTTPTransportPluginLLMPluginMCPPluginObservabilityPlugin
Features
HTTPTransportPlugin
- Tracks request count across all requests
- Adds request number header
- Calculates HTTP request duration
- Stores HTTP metadata in context for other hooks
LLMPlugin
- Accesses HTTP context metadata
- Adds dynamic system prompts
- Tracks LLM call duration
- Logs request/response details
MCPPlugin
- Accesses HTTP context metadata
- Logs all MCP tool/resource calls
- Tracks MCP call duration
- Implements governance for MCP calls
ObservabilityPlugin
- Receives completed traces asynchronously
- Formats traces as JSON
- Ready for integration with OTEL, Datadog, Jaeger, etc.
- Demonstrates end-to-end request tracking
Context Flow
This plugin demonstrates how context flows through different hooks:
- HTTPTransportPreHook → Stores HTTP metadata
- PreLLMHook/PreMCPHook → Accesses HTTP metadata, stores LLM/MCP metadata
- PostLLMHook/PostMCPHook → Accesses stored timing data
- HTTPTransportPostHook → Adds final headers
- Inject → Receives complete trace asynchronously
Use Cases
- Full-stack observability - Track requests from HTTP to LLM/MCP and back
- Unified governance - Apply policies at multiple layers
- Performance monitoring - Measure duration at each layer
- Audit trails - Complete request/response logging
- Custom analytics - Correlate HTTP, LLM, and MCP metrics
Building
make build
This creates build/multi-interface.so
Configuration
Add to your Bifrost config:
{
"plugins": [
{
"path": "/path/to/multi-interface.so",
"name": "multi-interface",
"display_name": "Full-Stack Observability",
"enabled": true,
"type": "auto",
"config": {
"enable_http_hooks": true,
"enable_llm_hooks": true,
"enable_mcp_hooks": true,
"enable_observability": true,
"enable_logging": true,
"track_requests": true,
"inject_uptime": true,
"custom_header_prefix": "X-Multi-Plugin"
}
}
]
}
Note:
nameis the system identifier (fromGetName()) and is not editabledisplay_nameis shown in the UI and is editable by users
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
enable_http_hooks |
boolean | true |
Enable HTTP transport layer hooks |
enable_llm_hooks |
boolean | true |
Enable LLM request/response hooks |
enable_mcp_hooks |
boolean | true |
Enable MCP request/response hooks |
enable_observability |
boolean | true |
Enable observability/trace injection |
enable_logging |
boolean | true |
Enable detailed logging |
track_requests |
boolean | true |
Track and count requests |
inject_uptime |
boolean | true |
Inject server uptime in LLM system messages |
custom_header_prefix |
string | "X-Multi-Plugin" |
Custom prefix for HTTP response headers |
Example Configurations
LLM-only mode:
{
"config": {
"enable_http_hooks": false,
"enable_llm_hooks": true,
"enable_mcp_hooks": false,
"enable_observability": false
}
}
Observability-focused:
{
"config": {
"enable_http_hooks": true,
"enable_llm_hooks": true,
"enable_mcp_hooks": true,
"enable_observability": true,
"enable_logging": false,
"track_requests": true
}
}
Minimal overhead:
{
"config": {
"enable_logging": false,
"track_requests": false,
"inject_uptime": false
}
}
Custom headers:
{
"config": {
"custom_header_prefix": "X-Custom-Plugin"
}
}
Hook Execution Order
For a typical LLM request:
HTTPTransportPreHook(HTTP layer entry)PreLLMHook(Before LLM provider)- LLM Provider Call
PostLLMHook(After LLM provider)HTTPTransportPostHook(HTTP layer exit)Inject(Asynchronous trace delivery)
For an MCP request:
HTTPTransportPreHook(HTTP layer entry)PreMCPHook(Before MCP server)- MCP Server Call
PostMCPHook(After MCP server)HTTPTransportPostHook(HTTP layer exit)Inject(Asynchronous trace delivery)
Notes
- This plugin tracks state across requests (request count, start time)
- Context metadata flows from HTTP → LLM/MCP hooks
Injectis called asynchronously after response is sent- Perfect template for building comprehensive observability solutions