MCIClient Class
TheMCIClient
class is the main entry point for the MCI Python adapter. It provides methods for loading, filtering, and executing MCI tools from a JSON schema file.
Initialization
MCIClient(json_file_path, env_vars=None)
Initialize the MCI client with a schema file and optional environment variables.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
json_file_path | str | Yes | Path to the MCI JSON schema file |
env_vars | dict[str, Any] | No | Environment variables for template substitution (default: {} ) |
MCIClientError
- If the schema file cannot be loaded or parsed
MCIClient
instance ready to use.
Error Response:
Methods
tools()
Get all available tools from the loaded schema.
Method Signature:
Type | Description |
---|---|
list[Tool] | List of all Tool objects in the schema |
only()
Filter tools to include only specified tools by name.
Method Signature:
Name | Type | Required | Description |
---|---|---|---|
tool_names | list[str] | Yes | List of tool names to include |
Type | Description |
---|---|
list[Tool] | Filtered list of Tool objects matching the specified names |
without()
Filter tools to exclude specified tools by name.
Method Signature:
Name | Type | Required | Description |
---|---|---|---|
tool_names | list[str] | Yes | List of tool names to exclude |
Type | Description |
---|---|
list[Tool] | Filtered list of Tool objects excluding the specified names |
execute()
Execute a tool by name with the provided properties.
Method Signature:
Name | Type | Required | Description |
---|---|---|---|
tool_name | str | Yes | Name of the tool to execute |
properties | dict[str, Any] | No | Properties/parameters to pass to the tool (default: {} ) |
Type | Description |
---|---|
ExecutionResult | Result object with success/error status and content |
MCIClientError
- If tool not found or execution fails with validation error
list_tools()
List available tool names as strings.
Method Signature:
Type | Description |
---|---|
list[str] | List of tool names (strings) |
get_tool_schema()
Get a tool’s input schema (JSON Schema format).
Method Signature:
Name | Type | Required | Description |
---|---|---|---|
tool_name | str | Yes | Name of the tool |
Type | Description |
---|---|
dict[str, Any] | Tool’s input schema as a dictionary (or empty dict if no schema) |
MCIClientError
- If tool not found
Data Models
MCISchema
Top-level MCI schema representing the complete MCI context file. Fields:Field | Type | Required | Description |
---|---|---|---|
schemaVersion | str | Yes | Schema version (e.g., “1.0”) |
metadata | Metadata | No | Optional metadata about the tool collection |
tools | list[Tool] | Yes | List of tool definitions |
Tool
Individual tool definition with name, description, input schema, and execution configuration. Fields:Field | Type | Required | Description |
---|---|---|---|
name | str | Yes | Unique identifier for the tool |
title | str | No | Human-readable title |
description | str | No | Description of what the tool does |
inputSchema | dict[str, Any] | No | JSON Schema defining expected input properties |
execution | HTTPExecutionConfig | CLIExecutionConfig | FileExecutionConfig | TextExecutionConfig | Yes | Execution configuration (determines how tool is executed) |
ExecutionResult
Result format returned from tool execution. Fields:Field | Type | Required | Description |
---|---|---|---|
isError | bool | Yes | Whether an error occurred during execution |
content | Any | No | Result content (None if error) |
error | str | No | Error message (None if success) |
metadata | dict[str, Any] | No | Additional metadata (e.g., status_code, execution_time_ms) |
Metadata
Optional metadata about the MCI tool collection. Fields:Field | Type | Required | Description |
---|---|---|---|
name | str | No | Name of the tool collection |
description | str | No | Description of the collection |
version | str | No | Version number (e.g., “1.0.0”) |
license | str | No | License type (e.g., “MIT”) |
authors | list[str] | No | List of author names |
Execution Configurations
HTTPExecutionConfig
Configuration for HTTP-based tool execution. Fields:Field | Type | Required | Default | Description |
---|---|---|---|---|
type | ExecutionType | Yes | "http" | Execution type identifier |
method | str | No | "GET" | HTTP method (GET, POST, PUT, DELETE, etc.) |
url | str | Yes | - | URL endpoint for the request |
headers | dict[str, str] | No | None | HTTP headers |
auth | AuthConfig | No | None | Authentication configuration |
params | dict[str, Any] | No | None | Query parameters |
body | HTTPBodyConfig | No | None | Request body configuration |
timeout_ms | int | No | 30000 | Request timeout in milliseconds |
retries | RetryConfig | No | None | Retry configuration |
CLIExecutionConfig
Configuration for command-line tool execution. Fields:Field | Type | Required | Default | Description |
---|---|---|---|---|
type | ExecutionType | Yes | "cli" | Execution type identifier |
command | str | Yes | - | Command to execute |
args | list[str] | No | None | Command arguments |
flags | dict[str, FlagConfig] | No | None | Command flags configuration |
cwd | str | No | None | Working directory for command execution |
timeout_ms | int | No | 30000 | Execution timeout in milliseconds |
FileExecutionConfig
Configuration for file reading and templating. Fields:Field | Type | Required | Default | Description |
---|---|---|---|---|
type | ExecutionType | Yes | "file" | Execution type identifier |
path | str | Yes | - | Path to the file to read |
enableTemplating | bool | No | True | Whether to process template placeholders in file content |
TextExecutionConfig
Configuration for simple text template execution. Fields:Field | Type | Required | Default | Description |
---|---|---|---|---|
type | ExecutionType | Yes | "text" | Execution type identifier |
text | str | Yes | - | Text template with placeholder support |
Authentication Models
ApiKeyAuth
API Key authentication configuration. Fields:Field | Type | Required | Default | Description |
---|---|---|---|---|
type | str | Yes | "apiKey" | Authentication type |
in | str | Yes | - | Where to place the key: “header” or “query” |
name | str | Yes | - | Name of the header or query parameter |
value | str | Yes | - | API key value (supports templates) |
BearerAuth
Bearer token authentication configuration. Fields:Field | Type | Required | Default | Description |
---|---|---|---|---|
type | str | Yes | "bearer" | Authentication type |
token | str | Yes | - | Bearer token value (supports templates) |
BasicAuth
Basic authentication (username/password) configuration. Fields:Field | Type | Required | Default | Description |
---|---|---|---|---|
type | str | Yes | "basic" | Authentication type |
username | str | Yes | - | Username (supports templates) |
password | str | Yes | - | Password (supports templates) |
OAuth2Auth
OAuth2 authentication configuration. Fields:Field | Type | Required | Default | Description |
---|---|---|---|---|
type | str | Yes | "oauth2" | Authentication type |
flow | str | Yes | - | OAuth2 flow type (e.g., “clientCredentials”) |
tokenUrl | str | Yes | - | Token endpoint URL |
clientId | str | Yes | - | OAuth2 client ID |
clientSecret | str | Yes | - | OAuth2 client secret (supports templates) |
scopes | list[str] | No | None | Optional OAuth2 scopes |
Error Handling
The MCI Python adapter provides consistent error handling across all operations.Exception Types
MCIClientError
Raised byMCIClient
methods for client-level errors.
Common Causes:
- Schema file not found or invalid
- Tool not found
- Invalid tool execution
ExecutionResult Error Format
Execution errors are returned asExecutionResult
objects with isError=True
.
Error Fields:
Field | Description |
---|---|
isError | Always True for errors |
content | Always None for errors |
error | Human-readable error message |
metadata | Optional additional error context |
Error Handling Best Practices
Check isError Flag:Complete Usage Example
Here’s a comprehensive example demonstrating all major features:Template Syntax
MCI supports template placeholders for dynamic value substitution:{{props.fieldName}}
- Access properties passed to execute(){{env.VARIABLE_NAME}}
- Access environment variables{{input.fieldName}}
- Deprecated alias for props (useprops
instead)
Note:{{input.fieldName}}
is supported for backward compatibility but is deprecated. Use{{props.fieldName}}
in all new code. Example:
Notes
- All methods are synchronous (blocking) - execution waits for completion
- Environment variables should be provided during initialization, not at execution time
- Templates are processed before execution using a simple
{{}}
placeholder substitution system (not full Jinja2 syntax) - HTTP responses are automatically parsed as JSON when possible
- CLI commands capture both stdout and stderr
- File paths can be relative or absolute
- Timeout values are in milliseconds
- All string fields support template substitution unless explicitly disabled
See Also
- Quickstart Guide - Getting started with MCI
- Schema Reference - Complete JSON schema documentation
- Examples - Example tool definitions and usage patterns