Skip to main content

MCI Structure

This document explains the structural organization of MCI projects, including entry files, toolsets, MCP server caching, and basic templating patterns.

Entry Files

MCI projects start with one or more entry files located in the root of your project directory. These are the main schema files that define your tool collections.

Single Entry File

The simplest structure uses a single entry file:
Example: mci.json

Multiple Entry Files

You can have multiple entry files, each creating a specific set of tools for different purposes:
Example: Multiple contexts for different environments api-tools.mci.json:
dev-tools.mci.json:
Key Points:
  • Each entry file is independent and creates its own set of tools
  • Entry files can share toolsets from the ./mci directory
  • Use multiple entry files to organize tools by environment, team, or purpose
  • No limit on the number of entry files (1, 3, 10, or more)
  • Each entry file must be loaded separately by the client; multiple entry files are not automatically merged and each requires its own MCIClient instance.

Automatic .env File Loading

MCI automatically loads environment variables from .env and .env.mci files when loading your MCI schema. This provides a convenient way to manage environment-specific configuration without manually setting variables. Automatic Detection:
  • When you run any MCI command (run, list, validate, etc.), MCI looks for environment files in:
    1. The project root directory (same location as your mci.json or mci.yaml)
    2. The ./mci directory
File Priority:
  • MCI prioritizes .env.mci files (MCI-specific configs) over .env files (general configs)
  • Important: When .env.mci files exist, .env files are not loaded at all
  • This allows you to keep MCI-specific environment variables separate from general project variables
Loading Behavior:
  • If .env.mci files exist: Only .env.mci files are loaded
    1. ./mci/.env.mci - Library MCI-specific configs
    2. Project root .env.mci - Project MCI-specific configs (higher priority)
  • If no .env.mci files exist: .env files are loaded instead
    1. ./mci/.env - Library general defaults
    2. Project root .env - Project-level configs (higher priority)
  • Then: System environment variables and explicit env_vars override all file-based configs
Full Precedence Order (lowest to highest):
  1. File-based configs (.env.mci files if they exist, otherwise .env files)
    • From ./mci/ directory first
    • Then from project root
  2. System environment variables (set via export or shell config)
  3. Environment variables passed via CLI or code (highest priority)
Example .env file:
Example directory structure:
Example: Using .env.mci files
Example: Using .env files (no .env.mci)
Notes:
  • .env files are completely optional - MCI works fine without them
  • No error if .env files are missing
  • Use .env.mci for MCI-specific configurations to keep them completely separate from general project configs
  • When .env.mci exists, .env is ignored (not merged)
  • You can disable auto-loading by setting auto_load_dotenv=False when using the MCI library programmatically
  • .env files should NOT be committed to version control if they contain secrets

Toolsets Directory

Toolsets are stored in the ./mci directory by default. This can be customized using the libraryDir field.

Default Structure

Custom Library Directory

You can use a different directory name:

Nested Toolset Organization

Organize toolsets in subdirectories:
Loading nested toolsets:

MCP Tools Cache

When you register MCP servers in your schema, MCI automatically caches the tools in a special mcp subdirectory within your toolsets directory.

Cache Location

How It Works

  1. Register MCP Server in your entry file:
  1. First Load: MCI connects to the MCP server, fetches all tools, and saves them to ./mci/mcp/filesystem.mci.json
  2. Subsequent Loads: MCI uses the cached file instead of connecting to the server (much faster)
  3. Cache File Example (./mci/mcp/filesystem.mci.json):

Cache Management

Expiration: Caches expire after a configurable number of days (default: 30):
Manual Refresh: Delete cache files to force re-fetch:
Git Ignore: Add MCP cache to .gitignore:

Basic Templating

MCI supports templating in all schema files using the {{}} syntax. This allows dynamic values from environment variables and provides default fallbacks.

Environment Variable Templating

Syntax: {{env.VARIABLE_NAME}}

Default Values with Pipe Operator

Syntax: {{env.VARIABLE_NAME|'default_value'}} The pipe operator (|) allows you to specify a default value if the environment variable is not set:
Without environment variables:
  • {{env.DB_HOST|'localhost'}}"localhost"
  • {{env.DB_PORT|'5432'}}"5432"
  • {{env.DB_USER|'postgres'}}"postgres"
With environment variables set:
  • {{env.DB_HOST|'localhost'}}"production.db.example.com"
  • {{env.DB_PORT|'5432'}}"3306"
Note: This allows any amount of vars (but keep it under 5, please): {{env.DB_HOST|env.EXTERNAL_DB_HOST|'localhost'}}

MCI File Templating Examples

Example 1: API Configuration with Defaults

Example 2: CLI Tools with Environment Defaults

Example 3: MCP Server with Template Defaults

Example 4: Toolset Reference with Filtering

Template Usage in Different Contexts

1. Entry Files - Use templates in the main schema:
2. Toolset Files - Cannot use libraryDir or top-level config, but can use templates in tool definitions:
3. MCP Servers - Use templates for credentials and paths:

Best Practices

1. Use Descriptive Entry File Names

2. Organize Toolsets by Domain

3. Use Environment Variables for Secrets

4. Provide Sensible Defaults

5. Document Your Entry Files

Summary

  • Entry Files: Main schema files in your project root that define tool collections
  • Multiple Entry Files: Use as many as needed for different environments or purposes
  • Toolsets Directory: Default is ./mci, customizable via libraryDir
  • MCP Cache: Auto-generated in ./mci/mcp/ when MCP servers are registered
  • Templating: Use {{env.VAR}} for environment variables, {{env.VAR|default}} for defaults
  • Organization: Group toolsets by domain, use descriptive names, and document your schemas