> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Lifecycle CLI

> CLI commands for MCP connection management

# MCP Lifecycle CLI

Commands for managing MCP (Model Context Protocol) connections and lifecycle.

## Commands

### Start MCP Server

Start an MCP server for testing:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai mcp start "uvx mcp-server-time"
```

### Test MCP Connection

Test connectivity to an MCP server:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai mcp test "uvx mcp-server-time"
```

**Output:**

```
Testing MCP connection...
✓ Connection established
✓ Tools discovered: get_current_time
✓ Connection closed cleanly
```

### List MCP Tools

List available tools from an MCP server:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai mcp tools "uvx mcp-server-time"
```

**Output:**

```
Available MCP Tools:
  - get_current_time: Get the current time in a timezone
```

## Using MCP with Agents

### Basic Usage

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "What time is it?" --mcp "uvx mcp-server-time"
```

### Multiple MCP Servers

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Get time and search" \
  --mcp "uvx mcp-server-time" \
  --mcp "uvx mcp-server-fetch"
```

### With Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export BRAVE_API_KEY="your-key"
praisonai "Search for Python" --mcp "npx -y @modelcontextprotocol/server-brave-search"
```

## Connection Types

### Stdio (Command)

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Task" --mcp "uvx mcp-server-time"
```

### SSE URL

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Task" --mcp "http://localhost:8080/sse"
```

### HTTP Stream

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Task" --mcp "http://localhost:8080"
```

### WebSocket

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Task" --mcp "ws://localhost:8080"
```

## Lifecycle Management

### Automatic Cleanup

The CLI automatically handles cleanup:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Connection opened, used, and closed automatically
praisonai "What time is it?" --mcp "uvx mcp-server-time"
```

### Timeout Configuration

Set connection timeout:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Task" --mcp "uvx mcp-server-time" --mcp-timeout 30
```

## Debugging

### Verbose Mode

Enable verbose output for debugging:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Task" --mcp "uvx mcp-server-time" --verbose
```

### Check MCP Status

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
python -c "
from praisonaiagents import MCP

with MCP('uvx mcp-server-time') as mcp:
    print('Connection: OK')
    tools = mcp.get_tools()
    print(f'Tools: {len(tools)}')
print('Cleanup: OK')
"
```

## Environment Variables

| Variable      | Description                |
| ------------- | -------------------------- |
| `MCP_TIMEOUT` | Default timeout in seconds |
| `MCP_DEBUG`   | Enable debug logging       |

## Error Handling

### Connection Errors

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# If MCP server fails to start
praisonai "Task" --mcp "invalid-server"
# Error: Failed to connect to MCP server
```

### Timeout Errors

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# If operation times out
praisonai "Task" --mcp "slow-server" --mcp-timeout 5
# Error: MCP operation timed out after 5 seconds
```

## Related

* [MCP Lifecycle (Code)](/docs/features/mcp-lifecycle)
* [MCP Module](/docs/sdk/praisonaiagents/mcp/mcp)
* [MCP Transports](/docs/mcp/transports)
