Skip to main content

MCI Python Adapter - Quickstart Guide

Welcome to the MCI Python Adapter! This guide will help you get started quickly with installing, configuring, and using the MCI (Model Context Interface) adapter to define and execute tools in your Python applications.

Installation

Prerequisites

  • Python 3.11 or higher
  • uv package manager (recommended) or pip
First, install uv if you haven’t already:
  • macOS/Linux
  • macOS (Homebrew)
  • Windows
curl -LsSf https://astral.sh/uv/install.sh | sh
Then install the MCI Python adapter:
uv pip install mci-py

Option 2: Using pip

pip install mci-py

Verify Installation

import mcipy
print("MCI Python Adapter installed successfully!")

Your First Tool

Let’s create a simple tool to get you started.
1

Create a Tool Schema File

Create a file named my-tools.mci.json with your tool definitions:
my-tools.mci.json
{
  "schemaVersion": "1.0",
  "metadata": {
    "name": "My Tools",
    "description": "A collection of useful tools"
  },
  "tools": [
    {
      "name": "greet_user",
      "title": "User Greeting",
      "description": "Generate a personalized greeting message",
      "inputSchema": {
        "type": "object",
        "properties": {
          "username": {
            "type": "string",
            "description": "The user's name"
          }
        },
        "required": ["username"]
      },
      "execution": {
        "type": "text",
        "text": "Hello, {{props.username}}! Welcome to MCI."
      }
    }
  ]
}
2

Create a Python Script

Create a Python file to use your tools:
main.py
from mcipy import MCIClient

# Initialize with your schema file
client = MCIClient(
    json_file_path="my-tools.mci.json",
    env_vars={
        "USERNAME": "demo_user"
    }
)

# Execute the tool
result = client.execute(
    tool_name="greet_user",
    properties={"username": "Alice"}
)

# Check the result
if result.isError:
    print(f"Error: {result.error}")
else:
    print(f"Success: {result.content}")
3

Run Your Tool

Execute your Python script:
python main.py
You should see: Success: Hello, Alice! Welcome to MCI.

Quick Examples

List Available Tools

# Get all tool names
tool_names = client.list_tools()
print(f"Available tools: {tool_names}")

# Get full tool objects
tools = client.tools()
for tool in tools:
    print(f"- {tool.name}: {tool.title}")

Filter Tools

# Include only specific tools
weather_tools = client.only(["get_weather", "get_forecast"])

# Exclude specific tools
safe_tools = client.without(["delete_data", "admin_tools"])

Get Tool Schema

# Retrieve input schema for a tool
schema = client.get_tool_schema("greet_user")
print(f"Required properties: {schema.get('required', [])}")
print(f"Properties: {list(schema.get('properties', {}).keys())}")

Template Placeholders

MCI supports powerful templating with placeholders:
  • {{props.propertyName}} - Access input properties
  • {{env.VARIABLE_NAME}} - Access environment variables
  • {{input.fieldName}} - Alias for {{props.fieldName}}
Environment variables are the recommended way to handle secrets and configuration values.

Next Steps

Common Use Cases

  • API Integration: Use HTTP execution to integrate with REST APIs
  • Prompts management: Use File execution to process complex Markdown or XML prompts
  • Reporting: Use Text execution to generate formatted reports
  • Data Processing: Combine multiple execution types for complex workflows
I