anubhavg-icpl/ocsf_mcp
If you are the rightful owner of ocsf_mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A Rust-based Model Context Protocol (MCP) server for implementing OCSF-based logging in applications.
OCSF MCP Server
A fully-fledged Rust-based Model Context Protocol (MCP) server that enables AI coding assistants to implement OCSF (Open Cybersecurity Schema Framework) based logging in any application.
🚀 Features
This MCP server provides comprehensive OCSF tooling:
- 🔍 Schema Browsing: Explore OCSF categories, event classes, and attributes interactively
- ⚡ Event Generation: Generate valid OCSF-compliant events with proper structure
- ✅ Validation: Validate existing events against OCSF schema
- 🛠️ Code Generation: Generate logging code in multiple languages (Rust, Python, JavaScript)
- 🔄 Custom Mapping: Map proprietary log formats to OCSF event classes
- 📚 Learning: Access example events for different scenarios
- 🔧 Version Management: Support for multiple OCSF schema versions (1.0.0 - 1.7.0-dev)
🏗️ Architecture
AI Assistant (Claude, etc.)
↓ MCP Protocol (stdio)
OCSF MCP Server (Rust)
├── 🛠️ Tools Layer (7 MCP tools)
├── 🧠 OCSF Core Engine (schema, validation, events)
├── 📝 Code Templates (multi-language support)
└── 📊 Schema Data (embedded JSON schemas)
🔧 Available MCP Tools
1. browse_ocsf_schema
Browse OCSF schema categories, event classes, and attributes.
Parameters:
category(optional): Category name (e.g., "network", "iam", "system")event_class(optional): Event class name (e.g., "authentication", "file_activity")show_attributes: Boolean - Show detailed attribute information
Examples:
# Browse all categories
browse_ocsf_schema(show_attributes=false)
# Browse specific category
browse_ocsf_schema(category="network", show_attributes=true)
# Browse specific event class
browse_ocsf_schema(event_class="authentication", show_attributes=true)
2. generate_ocsf_event
Generate valid OCSF event JSON from parameters.
Parameters:
event_class: Event class namerequired_fields: Comma-separated field names OR JSON object with field valuesoptional_fields: Comma-separated field names OR JSON object with field values
Examples:
# Using comma-separated field names (auto-generates values)
generate_ocsf_event(
event_class="authentication",
required_fields="activity_id, category_uid, class_uid, severity_id, time, type_uid",
optional_fields="message, user"
)
# Using JSON objects with specific values
generate_ocsf_event(
event_class="authentication",
required_fields='{"activity_id": 1, "time": "2025-01-15T10:30:00Z"}',
optional_fields='{"user": {"name": "john.doe", "uid": "1001"}}'
)
3. validate_ocsf_event
Validate an OCSF event against the schema.
Parameters:
event_json: The OCSF event JSON string to validate
Example:
validate_ocsf_event(
event_json='{"metadata": {"version": "1.7.0-dev", "event_class": "authentication"}, "time": "2025-01-15T10:30:00Z"}'
)
4. generate_logging_code
Generate OCSF logging code for a specific language/framework.
Parameters:
language: Target language (rust, python, javascript)event_classes: Comma-separated class names OR JSON array of event classesframework(optional): Logging frameworkinclude_helpers: Boolean - Include builder patterns and helpers
Examples:
# Using comma-separated class names
generate_logging_code(
language="python",
event_classes="authentication,file_activity",
include_helpers=true
)
# Using JSON array
generate_logging_code(
language="rust",
event_classes='["authentication", "process_activity"]',
include_helpers=true
)
5. map_custom_to_ocsf
Help map custom log format to OCSF event class.
Parameters:
sample_log: User's existing log entrysuggested_class(optional): Suggested event class
Example:
map_custom_to_ocsf(
sample_log="2025-01-15 10:30:00 INFO [auth] User john.doe successfully logged in from IP 192.168.1.100",
suggested_class="authentication"
)
6. list_event_examples
Get example OCSF events for learning.
Parameters:
event_class: Event class namescenario(optional): Specific scenario (e.g., "failed_login", "successful_login")
Example:
list_event_examples(
event_class="authentication",
scenario="failed_login"
)
7. list_ocsf_versions & get_newest_ocsf_version
Version management tools for OCSF schema versions.
Examples:
# List all available versions
list_ocsf_versions()
# Get newest stable version
get_newest_ocsf_version()
🐳 Quick Start with Docker (Recommended)
Using Docker Hub (Easiest)
# Pull the latest image
docker pull anubhavgicpl/ocsf-mcp:latest
# Run interactively
docker run -i anubhavgicpl/ocsf-mcp:latest
Using Docker MCP Toolkit (Docker Desktop 4.42+)
- Enable MCP Toolkit in Docker Desktop settings
- Add OCSF server:
docker mcp server add ocsf --image anubhavgicpl/ocsf-mcp:latest - Connect to Claude Desktop:
docker mcp client connect claude-desktop --global
Using Makefile (Development)
# Build and test locally
make build
make test
# Run with Docker Compose
make compose-up
# Build multi-arch and publish
make publish
See make help for all available commands.
🏗️ Building from Source
Prerequisites
- Rust 1.85+ (with 2024 edition support)
- Cargo
Build
cargo build --release
Run
cargo run --bin ocsf-mcp-server
The server runs on stdio transport and communicates via JSON-RPC 2.0.
📋 Configuration for Claude Desktop
Option 1: Using Docker (Recommended)
Add to your Claude Desktop MCP configuration (claude_desktop_config.json):
{
"mcpServers": {
"ocsf": {
"command": "docker",
"args": ["run", "-i", "anubhavgicpl/ocsf-mcp:latest"]
}
}
}
Option 2: Using Local Binary
{
"mcpServers": {
"ocsf": {
"command": "/path/to/ocsf_mcp/target/release/ocsf-mcp-server",
"args": []
}
}
}
Option 3: Using Docker MCP Toolkit
No configuration needed! Just use:
docker mcp client connect claude-desktop --global
📊 OCSF Schema Support
Supports OCSF v1.7.0-dev (latest) with comprehensive coverage:
🏷️ Categories (8 total)
- System Activity (UID: 1) - OS and device-level events (14 classes)
- Findings (UID: 2) - Security findings (8 classes)
- Identity & Access Management (UID: 3) - Auth and account events (6 classes)
- Network Activity (UID: 4) - Network connections (14 classes)
- Discovery (UID: 5) - Asset discovery (26 classes)
- Application Activity (UID: 6) - Application events (8 classes)
- Remediation (UID: 7) - Security remediation (4 classes)
- Unmanned Systems (UID: 8) - Drone and autonomous systems (2 classes)
📈 Schema Statistics
- 82+ Event Classes - Comprehensive coverage of security events
- Multiple Versions - Support for OCSF 1.0.0 through 1.7.0-dev
- Rich Metadata - Detailed object definitions and type system
🎯 Popular Event Classes
authentication(UID: 3002) - Login, logout, auth failuresprocess_activity(UID: 1007) - Process lifecycle eventsfile_activity(UID: 1001) - File operations and accessnetwork_activity(UID: 4001) - Network connections and traffichttp_activity(UID: 4002) - HTTP requests and responsesdns_activity(UID: 4003) - DNS queries and responsessecurity_finding(UID: 2001) - Security scan resultsvulnerability_finding(UID: 2006) - Vulnerability assessments
💡 Use Cases
For AI Coding Assistants
- 🔍 Understanding OCSF: "Show me all event classes in the IAM category"
- ⚡ Implementing Logging: "Generate Python code for logging authentication events"
- 🔄 Migration: "Help me map this Splunk log to OCSF format"
- ✅ Validation: "Check if my event JSON is valid OCSF"
- 📚 Learning: "Show me examples of failed login events"
For Developers
- 🚀 Quickly bootstrap OCSF logging in new applications
- ✅ Validate existing security logs against OCSF standards
- 🔄 Migrate from proprietary formats to OCSF
- 📖 Learn OCSF schema through interactive exploration
🎯 Practical Examples
Example 1: Implementing Authentication Logging
Step 1: Explore the schema
browse_ocsf_schema(category="iam", show_attributes=true)
Step 2: Generate example events
list_event_examples(event_class="authentication")
Step 3: Generate logging code
generate_logging_code(
language="python",
event_classes="authentication",
include_helpers=true
)
Result: Complete Python module with OCSF authentication logging!
Example 2: Migrating Existing Logs
Your current log:
2025-01-15 10:30:00 ERROR [auth] Failed login attempt for user 'admin' from 192.168.1.100
Step 1: Map to OCSF
map_custom_to_ocsf(
sample_log="2025-01-15 10:30:00 ERROR [auth] Failed login attempt for user 'admin' from 192.168.1.100",
suggested_class="authentication"
)
Step 2: Generate OCSF event
generate_ocsf_event(
event_class="authentication",
required_fields="activity_id, time, type_uid",
optional_fields='{"user": {"name": "admin"}, "src_endpoint": {"ip": "192.168.1.100"}, "status": "failure"}'
)
Result: Standards-compliant OCSF authentication event!
Architecture Details
Core Components
OCSF Engine (src/ocsf/):
schema.rs- Schema parser and registryevent.rs- Event models and builderscategories.rs- OCSF category definitionsvalidation.rs- Event validation logic
Tools (src/tools/):
- MCP tool implementations using
#[tool]macros - Bridge between AI requests and OCSF engine
Templates (src/templates/):
- Multi-language code generation
- Support for Rust, Python, JavaScript, Go, Java
Performance
- Async/await with Tokio runtime
- Achieves 4,700+ QPS (following rmcp SDK benchmarks)
- Memory-safe with Rust ownership system
- Zero-copy JSON parsing where possible
Extending the Server
Adding New Event Classes
- Update
src/ocsf/schema.rswith new event class definitions - Add examples in
src/ocsf/event.rs - Server automatically exposes via existing tools
Adding Language Support
- Create new template file in
src/templates/ - Implement code generator in
src/tools/mod.rs::generate_logging_code - Add language-specific examples
Custom OCSF Schema
Replace OcsfSchema::default_schema() with:
// Fetch from schema.ocsf.io
let client = reqwest::Client::new();
let schema = client
.get("https://schema.ocsf.io/api/schema")
.send()
.await?
.json::<OcsfSchema>()
.await?;
🧪 Testing
Run Tests
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Test specific module
cargo test schema_tests
# Integration tests only
cargo test --test integration_tests
Test Coverage
- ✅ Schema loading and validation
- ✅ Event generation and validation
- ✅ Tool parameter parsing
- ✅ Version management
- ✅ Multi-version compatibility
🚀 Development
Project Structure
src/
├── main.rs # MCP server entry point
├── lib.rs # Library exports
├── ocsf/ # Core OCSF engine
│ ├── schema.rs # Schema parser and registry
│ ├── event.rs # Event models and builders
│ ├── categories.rs # Category definitions
│ └── validation.rs # Event validation
├── tools/ # MCP tool implementations
│ ├── mod.rs # Tool router and handlers
│ ├── schema_browser.rs
│ ├── event_generator.rs
│ ├── validator.rs
│ ├── code_generator.rs
│ ├── mapper.rs
│ └── version_tools.rs
└── templates/ # Code generation templates
├── python.rs
├── javascript.rs
└── rust.rs
Adding New Languages
- Create new template file in
src/templates/ - Implement generator function
- Add to
code_generator.rsmatch statement - Add tests
Adding New Event Classes
- Update schema JSON files in
data/ocsf-schema/ - Add examples in
event.rs - Update integration tests
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Add tests for new functionality
- Ensure all tests pass (
cargo test) - Update documentation
- Submit a pull request
Contributions welcome! Areas for improvement:
- Full OCSF v1.3.0 schema integration (all event classes)
- Additional language templates (Go, Java, C#)
- Advanced validation with JSONSchema
- OCSF profile support
- Custom extension support
👨💻 Maintainer & Author
Anubhav Gain (anubhavg-cipl)
📧 anubhavg@infopercept.com | 🏢 InfoPercept | 🐙 GitHub
🐳 Docker Deployment
Production-Ready Features
- ✅ Multi-stage builds for minimal image size (~30MB)
- ✅ Multi-architecture support (linux/amd64, linux/arm64)
- ✅ Non-root user execution
- ✅ Read-only filesystem
- ✅ Health checks included
- ✅ Security scanning with Trivy
- ✅ Automated CI/CD with GitHub Actions
Docker Hub
docker pull anubhavgicpl/ocsf-mcp:latest
Registry: hub.docker.com/r/anubhavgicpl/ocsf-mcp
Build Your Own
# Quick build
make build
# Production multi-arch build
make production-deploy
# Local testing
make compose-up
📄 License
MIT License - see LICENSE file for details.
🔗 Related Projects
- OCSF Schema - Official OCSF schema and documentation
- MCP SDK - Rust MCP SDK
- Claude Desktop - AI assistant with MCP support
- OCSF GitHub - OCSF schema repository
📚 Resources
🙏 Credits
Built with:
- rmcp - Official Rust MCP SDK
- tokio - Async runtime
- OCSF Schema v1.7.0-dev - Latest OCSF schema (83 classes, 168 objects)
Made with ❤️ for the cybersecurity community
Enabling standardized security logging across all applications through AI-assisted development.