MCP Integration
cli4ai automatically wraps CLI tools as MCP (Model Context Protocol) servers, allowing AI agents to discover and use your tools without any protocol implementation.
How It Works
When you run cli4ai start slack, cli4ai creates an MCP server that bridges your CLI tool to any MCP-compatible AI agent:
AI Agent (Claude, Cursor, etc.)
│
│ JSON-RPC over stdio
▼
┌─────────────┐
│ MCP Server │ ← cli4ai start slack
│ (cli4ai) │
└─────────────┘
│
│ Spawns subprocess
▼
┌─────────────┐
│ CLI Tool │ ← bun run run.ts command
│ (slack) │
└─────────────┘
│
│ JSON output
▼
Returns to AI Agent The MCP Adapter
The adapter handles all the protocol complexity for you:
- Reads commands from
cli4ai.json - Converts each command to an MCP tool definition
- When the AI calls a tool, executes the corresponding CLI command
- Returns the JSON output to the AI
Tool Naming Convention
MCP tools are named using the pattern package_command:
| MCP Tool | CLI Equivalent |
|---|---|
slack_channels | cli4ai run slack channels |
slack_post | cli4ai run slack post |
github_notifs | cli4ai run github notifs |
Generating MCP Configuration
To connect your installed tools to an AI agent, generate the MCP configuration:
cli4ai mcp-config This outputs configuration for various AI clients:
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"slack": {
"command": "cli4ai",
"args": ["start", "slack"]
}
}
} Cursor
Add to your Cursor MCP settings:
{
"slack": {
"command": "cli4ai",
"args": ["start", "slack"]
}
} Running Multiple Tools
Generate MCP configuration for all your installed packages:
# Generate config for all installed packages
cli4ai mcp-config
# Generate config for global packages only
cli4ai mcp-config --global
# Generate config for a specific package
cli4ai mcp-config --package slack --snippet Manifest MCP Settings
Packages can customize their MCP behavior in cli4ai.json:
{
"mcp": {
"enabled": true,
"transport": "stdio"
}
} Options:
enabled- Whether to expose this package via MCP (default: true)transport- Communication method, currently only "stdio" supported
Alternative: Direct CLI Usage
MCP isn't required to use cli4ai tools. You can also document tools in your CLAUDE.md or AGENTS.md file and AI agents will use them directly via the terminal. See Getting Started for this approach.
Next Steps
- MCP vs CLI - Understand the CLI-first philosophy
- Creating Packages - Build your own tools