Skip to main content

Basic Usage

This guide covers the essential patterns for working with the MCI Python adapter, from client initialization to tool execution and error handling.

Importing the Client

Creating Tool Schema Files

MCI supports both JSON and YAML formats for schema files. Choose the format that best suits your preferences.

JSON Format

Create a file named my-tools.mci.json:

YAML Format

Create a file named my-tools.mci.yaml:
Note: MCI supports both JSON (.json) and YAML (.yaml, .yml) formats interchangeably.

Initializing the Client

Basic Initialization

With Environment Variables

Backward Compatibility


Working with Tools

Listing Tools

Get a list of all available tool names:
Get full tool objects with metadata:

Executing Tools

Execute a tool with properties:
Execute without properties (if not required):

Filtering Tools

By Tool Names (Include Only)

By Tool Names (Exclude)

By Tags

By Toolsets

Getting Tool Schemas

Retrieve the input schema for a tool:

Execution Types

MCI supports four execution types: Text, File, CLI, and HTTP. Each type is designed for different use cases.

Text Execution

Return static or templated text directly. Perfect for simple messages, templates, or computed strings. Schema Example:
Python Usage:

File Execution

Read and return file contents with optional template substitution. Useful for loading configuration files, templates, or documentation. Schema Example:
File Content (configs/database.conf):
Python Usage:

CLI Execution

Execute command-line programs and capture their output. Great for running system commands, scripts, or CLI tools. Schema Example:
Python Usage:
CLI Configuration Options:
  • command: The command to execute (e.g., “grep”, “python”, “node”)
  • args: Fixed arguments passed to the command
  • flags: Dynamic flags based on input properties
    • type: "boolean": Include flag only if property is true
    • type: "value": Include flag with property value (e.g., --file value)
  • cwd: Working directory for command execution
  • timeout_ms: Maximum execution time in milliseconds

HTTP Execution

Make HTTP requests to APIs with full support for authentication, headers, query parameters, and request bodies.

Basic GET Request

POST Request with JSON Body

Authentication Types

API Key (Header):
API Key (Query Parameter):
Bearer Token:
Basic Authentication:
OAuth2:

Python Usage Example


Advanced Features

Toolsets

Toolsets allow you to organize tools into reusable, modular collections. See the Toolsets Concept Guide for detailed information. Quick Example:

Error Handling

Always check the isError property of execution results:

Multiple Clients

You can create multiple client instances for different schema files:

Environment Variables

Environment variables are the recommended way to handle secrets and configuration:

Security: Path Restrictions

Important Security Feature: By default, MCI restricts file and directory access to protect against arbitrary file access vulnerabilities.

Default Behavior

When executing file-based tools or CLI tools with a working directory (cwd), MCI validates that all paths are within the directory containing the schema file:

Allowing Specific Directories

You can allow additional directories using directoryAllowList:

Per-Tool Configuration

Override security settings for individual tools:
Important Notes:
  1. Tool-level settings override schema-level settings
  2. Relative paths are resolved relative to the schema directory
  3. enableAnyPaths disables all path validation - Use with extreme caution
  4. Subdirectories are automatically allowed

Complete Example

Here’s a complete example putting it all together: