Model Context Protocol (MCP)
Relevant source files
The following files were used as context for generating this wiki page:
The Model Context Protocol (MCP) within Olive Studio is a specialized server architecture designed to enable AI agents to query, configure, and troubleshoot Microsoft Olive model optimization workflows. It acts as an authoritative knowledge base that bridges the gap between raw optimization toolkits and AI-driven development, providing agents with the necessary context to build GUI applications, CLI tools, or backend services for model compression across various hardware targets like NVIDIA GPUs, Intel CPUs, and Qualcomm NPUs.
Sources: OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:9-14, ABOUT.md:7-10
Architecture Overview
The MCP server is structured as a toolkit providing multiple specialized tools that interface with a comprehensive knowledge base. It is designed to be implemented using Python (FastMCP) or TypeScript (MCP SDK) to leverage Olive's Python-first ecosystem.
Component Structure
The system is divided into four main functional areas:
- Core Toolkit: Basic tools for retrieving passes, templates, and strategies.
- Knowledge Base: Embedded JSON data containing catalogs for optimization passes, hardware profiles, and compatibility matrices.
- Smart Logic: Validators for pass ordering (pass chains) and tradeoff analyzers.
- Integration Layer: Fetchers that keep the knowledge base updated from official Microsoft Olive documentation and GitHub repositories.
Sources: OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:154-177, OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:196-200
System Workflow
The following diagram illustrates the interaction between an AI Agent and the MCP Server tools to generate a valid optimization configuration:
The MCP Server mediates access to the Olive knowledge base, ensuring the Agent receives validated, hardware-aware information.
Sources: OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:19-75, OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:179-194
Tool Definitions
The MCP implementation includes a suite of 8-12 specialized tools. These tools allow agents to interact with the Olive optimization engine programmatically.
Optimization & Discovery Tools
| Tool Name | Purpose | Key Inputs |
|---|---|---|
get_olive_passes | Lists available optimization passes (quantization, pruning, etc.) | Filter category |
get_pass_config_template | Generates JSON scaffolds for specific optimization passes | Pass name, framework |
get_quantization_strategy | Recommends algorithms (AWQ, GPTQ, etc.) based on hardware | Model type, hardware target |
get_pass_chain | Validates the ordering of multiple optimization passes | List of pass names |
Sources: OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:19-61
Troubleshooting & Compatibility Tools
| Tool Name | Purpose | Key Inputs |
|---|---|---|
troubleshoot_olive_error | Diagnoses common implementation issues and provides workarounds | Error message, context |
get_model_compatibility | Checks if a specific model/framework is supported by Olive | Model name, framework |
evaluate_optimization_tradeoff | Predicts outcomes for accuracy vs. latency vs. size | Pass sequence, metrics |
Sources: OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:62-95
Knowledge Base & Data Models
The MCP server relies on a deep reference library encompassing optimization passes, hardware execution providers, and implementation "quirks."
Pass Catalog
The catalog covers over 40 optimization passes. Each entry includes:
- Class Name: (e.g.,
OnnxQuantization,IncPruning). - Supported Formats: ONNX, PyTorch, TensorFlow, etc.
- Configuration Schema: Detailed parameter definitions and requirements.
- Hardware Compatibility: Specific Execution Provider requirements.
Sources: OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:103-113, OLIVE_COMPREHENSIVE_API_REFERENCE.md:37-65
Hardware Target Profiles
The system maintains profiles for major hardware vendors to ensure optimizations are hardware-aware.
Diagram shows relationship between hardware targets and the specific execution providers used by optimization passes.
Sources: OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:133-141, OLIVE_COMPREHENSIVE_API_REFERENCE.md:198-212
Implementation Quirks Database
A critical component of the MCP is the Quirks Database, which documents non-obvious behaviors:
- Calibration: Differences between symmetric and asymmetric quantization requirements for Qualcomm NPUs vs NVIDIA GPUs.
- Pass Ordering: Requirement to convert to ONNX before attempting quantization.
- Hardware Fallback: Silent fallback to CPU when operators are unsupported on the target GPU/NPU.
Sources: OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:115-125, OLIVE_COMPREHENSIVE_API_REFERENCE.md:236-258
Workspace Context Integration
Olive Studio utilizes aiWorkspaceContext.ts to provide the MCP server and other AI components with the current UI state. This ensures that the "Olive AI Assistant" or any MCP-enabled agent has access to the user's specific selections as "ground truth."
Context Data Structure
export interface AiWorkspaceContext {
modelSource: "huggingface" | "local" | "azure";
model: {
displayName: string;
huggingFaceId: string;
localFileNames: string[];
};
hardware: {
executionProvider: string;
cudaVersion: string;
};
passes: UIState["passes"];
validation: {
isBlocked: boolean;
criticalCount: number;
};
}
Sources: src/lib/aiWorkspaceContext.ts:4-31
AI Communication Flow
The server facilitates the exchange between the UI state and the AI models (Gemini, OpenAI, etc.) via specialized endpoints that utilize this context.
Conclusion
The Model Context Protocol implementation serves as the intelligence layer for Olive Studio. By codifying over 40 optimization passes and complex hardware compatibility rules into a tool-accessible format, it enables AI agents to function as expert optimization engineers, reducing the barrier to entry for complex model compression tasks on specialized hardware.
Sources: OLIVE_MCP_PROMPT_FOR_DEVELOPER.md:268-275, ABOUT.md:7-14