mrapids 0.1.31

Your OpenAPI, but executable
Documentation
# MicroRapid Future Features & AI-Agent Design

## Overview

This document outlines future features for MicroRapid CLI, with a focus on making it valuable for both human users and AI agents. These features align with our core philosophy: "Boring is good, One thing well, Fail loudly."

## Core Philosophy Alignment

Every feature should:
- ✅ Work offline when possible (using spec data)
- ✅ Provide immediate value without configuration
- ✅ Fail with clear, actionable error messages
- ✅ Use smart defaults but allow customization
- ✅ Integrate seamlessly with existing commands

---

## Priority Feature List

### High Priority (Maximum value, minimal complexity)

#### 1. **Smart API Exploration** 🔍
```bash
mrapids explore <keyword>
# Searches across operation names, descriptions, paths
# Shows relevant operations grouped by similarity
```
**Value**: Users often don't know exact operation names. Help them discover what they need quickly.

#### 2. **Authentication Helper** 🔐
```bash
mrapids auth setup
# Interactive auth configuration
# Detects auth type from spec and guides setup
# Saves credentials securely in .env or keychain
```
**Value**: Authentication is often the first hurdle. Make it dead simple.

#### 3. **Response Formatter** 📊
```bash
mrapids run <operation> --format table
mrapids run <operation> --extract data.items[0].id
# Smart response formatting and extraction
```
**Value**: APIs often return nested JSON. Help users get what they need quickly.

### Medium Priority (Good value, moderate complexity)

#### 4. **Request Builder with Validation**
```bash
mrapids build <operation>
# Interactive request builder
# Shows required fields with validation
# Saves as reusable template
```
**Value**: Building valid requests manually is error-prone. Guide users through it.

#### 5. **Test Data Generation** 🎲
```bash
mrapids generate <operation> --realistic
# Generates realistic test data based on field names/types
# Respects constraints and formats
```
**Value**: Testing with "string", "string", "string" is not realistic. Generate meaningful test data.

#### 6. **Quick Validation**
```bash
mrapids validate request.json --operation createUser
# Validate request/response against schema
# Clear error messages with fixes
```
**Value**: Debugging "400 Bad Request" with no details is painful.

### Lower Priority (Nice to have, higher complexity)

#### 7. **Diff & Change Detection** 📝
```bash
mrapids diff api-v1.yaml api-v2.yaml
# Shows breaking changes, new endpoints, deprecated operations
# Highlights what affects existing integrations
```
**Value**: API changes break integrations. Help users understand impact.

#### 8. **Rate Limit Awareness** ⏱️
```bash
mrapids run <operation> --respect-limits
# Reads rate limit headers
# Automatically throttles requests
# Shows remaining quota
```
**Value**: Getting rate-limited during testing is frustrating. Handle it gracefully.

#### 9. **Batch Operations** 📦
```bash
mrapids batch create-users.csv
# Run same operation with different data
# Progress bar, error handling, retry logic
```
**Value**: Real-world usage often involves bulk operations.

#### 10. **Environment Sync** 🔄
```bash
mrapids sync dev staging
# Compare API behavior across environments
# Detect configuration differences
```
**Value**: "Works in dev, fails in prod" - help users catch environment issues.

---

## AI Agent-Friendly Design 🤖

### Core AI Features

#### 1. **Structured Output Modes**
```bash
mrapids run <operation> --output json-structured
```
Returns predictable, parseable JSON:
```json
{
  "operation": "createUser",
  "status": "success",
  "response_code": 201,
  "data": {...},
  "metadata": {
    "duration_ms": 245,
    "rate_limit_remaining": 99
  }
}
```

#### 2. **Machine-Readable Errors**
```json
{
  "error": "validation_failed",
  "field": "email",
  "constraint": "format",
  "expected": "email",
  "received": "not-an-email",
  "suggestion": "Provide valid email format: user@example.com"
}
```

#### 3. **Operation Discovery API**
```bash
mrapids discover --capabilities
```
Returns AI-friendly capability mapping:
```json
{
  "capabilities": [
    {
      "category": "user_management",
      "operations": ["createUser", "updateUser", "deleteUser"],
      "description": "Manage user accounts"
    }
  ]
}
```

#### 4. **Schema Export for AI Understanding**
```bash
mrapids schema <operation> --format ai
```
Simplified schema format:
```json
{
  "operation": "createUser",
  "requires": {
    "email": "string:email",
    "name": "string:1-100"
  },
  "optional": {
    "age": "integer:0-150"
  },
  "returns": {
    "id": "string:uuid",
    "created_at": "string:datetime"
  }
}
```

#### 5. **Chainable Operations**
```yaml
# chain.yaml
operations:
  - id: create_user
    operation: createUser
    data:
      email: test@example.com
  - id: get_user  
    operation: getUserById
    data:
      id: $create_user.response.id
```

#### 6. **Dry-Run with Explanation**
```bash
mrapids run <operation> --dry-run --explain
```
Returns effect prediction:
```json
{
  "operation": "deleteUser",
  "would_send": {
    "method": "DELETE",
    "url": "https://api.example.com/users/123"
  },
  "effects": [
    "User with id=123 would be permanently deleted",
    "Associated data would be removed"
  ],
  "reversible": false
}
```

#### 7. **Intent-Based Commands**
```bash
mrapids intent "create a new user named John"
```
AI-friendly intent parsing:
```json
{
  "interpreted_as": "createUser",
  "extracted_params": {
    "name": "John"
  },
  "missing_required": ["email"],
  "suggestion": "mrapids run createUser --name John --email <email>"
}
```

### Advanced AI Features

#### 8. **Batch Result Streaming**
```bash
mrapids batch operations.jsonl --stream
```
JSONL output for streaming:
```
{"line":1,"status":"success","operation":"createUser","id":"user1"}
{"line":2,"status":"failed","operation":"createUser","error":"duplicate_email"}
```

#### 9. **State Management**
```bash
mrapids state save checkpoint1
mrapids state restore checkpoint1
```

#### 10. **Semantic Search**
```bash
mrapids search "operations that modify user data"
```
Returns semantically relevant operations:
```json
{
  "matches": [
    {"operation": "updateUser", "relevance": 0.95},
    {"operation": "deleteUser", "relevance": 0.90},
    {"operation": "createUser", "relevance": 0.85}
  ]
}
```

### AI-Specific Modes

#### **Tool Calling Format**
```bash
mrapids --tool-mode
```
Outputs in OpenAI/Anthropic tool format:
```json
{
  "name": "mrapids_run",
  "description": "Execute API operation",
  "parameters": {
    "type": "object",
    "properties": {
      "operation": {"type": "string"},
      "data": {"type": "object"}
    }
  }
}
```

#### **Context Awareness**
```bash
mrapids context set user_id=123
mrapids run getOrders  # Automatically uses context
```

---

## Implementation Roadmap

### Phase 1: Foundation (Essential for AI)
1. Structured JSON output for all commands
2. Machine-readable errors with error codes
3. Schema export in simplified format
4. Dry-run with effect prediction

### Phase 2: Intelligence (Enhanced AI capabilities)
5. Intent-based command parsing
6. Semantic operation search
7. Operation chaining/workflows
8. Context management

### Phase 3: Advanced (Sophisticated AI features)
9. State checkpointing
10. Tool calling format
11. Batch streaming operations
12. AI-specific optimizations

---

## Design Principles for AI Compatibility

1. **Predictable Output**: Every command returns consistent, structured output
2. **Self-Describing**: APIs should explain their capabilities
3. **Safe Exploration**: Dry-run everything, explain effects
4. **Stateless by Default**: But support state when needed
5. **Streaming-Friendly**: Support for long-running operations
6. **Error Recovery**: Clear guidance on how to fix issues

---

## Example AI Agent Usage

```python
# AI agent using mrapids
import subprocess
import json

class APIAgent:
    def execute_intent(self, intent):
        # Discover what's possible
        result = subprocess.run(
            ["mrapids", "intent", intent, "--output", "json"],
            capture_output=True
        )
        
        plan = json.loads(result.stdout)
        
        if plan["missing_required"]:
            # AI figures out missing data
            missing_data = self.infer_missing_data(plan["missing_required"])
            
        # Execute with dry-run first
        dry_run = subprocess.run(
            ["mrapids", "run", plan["operation"], "--dry-run", "--explain"],
            capture_output=True
        )
        
        if self.confirm_effects(dry_run):
            # Actually execute
            return self.execute_operation(plan["operation"], data)
```

---

## Success Metrics

- **Human Users**: "Why wasn't it always this easy?"
- **AI Agents**: Predictable, self-describing, safe to explore
- **Both**: Zero configuration to start, powerful when needed

This design ensures MicroRapid is not just a CLI tool but a powerful API interaction layer that both humans and AI agents can use effectively.