| name | repl-interaction |
| description | Patterns for controlling REPL sessions (Python, IPython, Node.js, Ruby, etc.) via terminalcp |
REPL Interaction with terminalcp
This skill provides comprehensive patterns for managing and automating REPL (Read-Eval-Print Loop) sessions using terminalcp MCP. It enables AI agents to execute code interactively, explore APIs, and prototype solutions in real-time.
Overview
terminalcp enables:
- Interactive code execution in multiple languages
- Real-time output capture and parsing
- Persistent REPL sessions for stateful exploration
- Parallel REPL management for multi-language projects
- History and context preservation
The MCP server runs via npx @mariozechner/terminalcp@latest --mcp and provides full terminal emulation for REPL interaction.
Python REPL
Starting Python REPL
{
"action": "start",
"command": "python3 -i",
"name": "python-repl"
}
Starting IPython (Enhanced REPL)
{
"action": "start",
"command": "ipython",
"name": "ipython-repl"
}
Basic Code Execution
{
"action": "stdin",
"id": "python-repl",
"data": "2 + 2\r"
}
{
"action": "stdin",
"id": "python-repl",
"data": "x = 42\r"
}
{
"action": "stdin",
"id": "python-repl",
"data": "import math\r"
}
{
"action": "stdin",
"id": "python-repl",
"data": "math.sqrt(16)\r"
}
Multi-Line Code Execution
{
"action": "stdin",
"id": "python-repl",
"data": "def greet(name):\r"
}
{
"action": "stdin",
"id": "python-repl",
"data": " return f'Hello, {name}!'\r"
}
{
"action": "stdin",
"id": "python-repl",
"data": "\r"
}
{
"action": "stdin",
"id": "python-repl",
"data": "greet('Alice')\r"
}
Capturing REPL Output
{
"action": "stdout",
"id": "python-repl"
}
Returns the current terminal state including all executed code and output.
Stream Mode for Real-Time Monitoring
{
"action": "stream",
"id": "python-repl",
"since_last": true
}
Returns only new output since last check, useful for monitoring long-running computations.
IPython Advanced Features
Magic Commands
{
"action": "stdin",
"id": "ipython-repl",
"data": "%timeit sum(range(1000))\r"
}
{
"action": "stdin",
"id": "ipython-repl",
"data": "%run script.py\r"
}
{
"action": "stdin",
"id": "ipython-repl",
"data": "%history\r"
}
{
"action": "stdin",
"id": "ipython-repl",
"data": "%whos\r"
}
{
"action": "stdin",
"id": "ipython-repl",
"data": "%edit myfunction\r"
}
Object Introspection
{
"action": "stdin",
"id": "ipython-repl",
"data": "str.split?\r"
}
{
"action": "stdin",
"id": "ipython-repl",
"data": "str.split??\r"
}
{
"action": "stdin",
"id": "ipython-repl",
"data": "dir(str)\r"
}
{
"action": "stdin",
"id": "ipython-repl",
"data": "type(my_variable)\r"
}
Shell Commands in IPython
{
"action": "stdin",
"id": "ipython-repl",
"data": "!ls -la\r"
}
{
"action": "stdin",
"id": "ipython-repl",
"data": "files = !ls *.py\r"
}
{
"action": "stdin",
"id": "ipython-repl",
"data": "!echo {my_var}\r"
}
Node.js REPL
Starting Node REPL
{
"action": "start",
"command": "node",
"name": "node-repl"
}
Basic JavaScript Execution
{
"action": "stdin",
"id": "node-repl",
"data": "2 + 2\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": "const x = 42\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": "[1, 2, 3].map(n => n * 2)\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": "const fs = require('fs')\r"
}
Multi-Line Code
{
"action": "stdin",
"id": "node-repl",
"data": "function greet(name) {\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": " return `Hello, ${name}!`\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": "}\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": "greet('Bob')\r"
}
Async/Await in REPL
{
"action": "stdin",
"id": "node-repl",
"data": "async function fetchData() { return 'data' }\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": "await fetchData()\r"
}
Node REPL Commands
{
"action": "stdin",
"id": "node-repl",
"data": ".help\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": ".load script.js\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": ".save session.js\r"
}
{
"action": "stdin",
"id": "node-repl",
"data": ".exit\r"
}
Ruby REPL (irb)
Starting Ruby REPL
{
"action": "start",
"command": "irb",
"name": "ruby-repl"
}
Ruby Code Execution
{
"action": "stdin",
"id": "ruby-repl",
"data": "2 + 2\r"
}
{
"action": "stdin",
"id": "ruby-repl",
"data": "'hello'.upcase\r"
}
{
"action": "stdin",
"id": "ruby-repl",
"data": "[1, 2, 3].map { |n| n * 2 }\r"
}
{
"action": "stdin",
"id": "ruby-repl",
"data": "def greet(name); \"Hello, #{name}!\"; end\r"
}
{
"action": "stdin",
"id": "ruby-repl",
"data": "greet('Charlie')\r"
}
Lua REPL
Starting Lua REPL
{
"action": "start",
"command": "lua",
"name": "lua-repl"
}
Lua Code Execution
{
"action": "stdin",
"id": "lua-repl",
"data": "print(2 + 2)\r"
}
{
"action": "stdin",
"id": "lua-repl",
"data": "t = {1, 2, 3}\r"
}
{
"action": "stdin",
"id": "lua-repl",
"data": "print(t[1])\r"
}
Advanced Patterns
API Exploration Workflow
{
"action": "start",
"command": "ipython",
"name": "api-explore"
}
{
"action": "stdin",
"id": "api-explore",
"data": "import requests\r"
}
{
"action": "stdin",
"id": "api-explore",
"data": "dir(requests)\r"
}
{
"action": "stdin",
"id": "api-explore",
"data": "requests.get?\r"
}
{
"action": "stdin",
"id": "api-explore",
"data": "response = requests.get('https://api.github.com')\r"
}
{
"action": "stdin",
"id": "api-explore",
"data": "response.json()\r"
}
{
"action": "stdout",
"id": "api-explore"
}
Data Analysis Session
{
"action": "start",
"command": "ipython",
"name": "data-analysis"
}
{
"action": "stdin",
"id": "data-analysis",
"data": "import pandas as pd\r"
}
{
"action": "stdin",
"id": "data-analysis",
"data": "df = pd.read_csv('data.csv')\r"
}
{
"action": "stdin",
"id": "data-analysis",
"data": "df.head()\r"
}
{
"action": "stdin",
"id": "data-analysis",
"data": "df.describe()\r"
}
{
"action": "stdin",
"id": "data-analysis",
"data": "df.groupby('category').mean()\r"
}
{
"action": "stdout",
"id": "data-analysis"
}
Multi-Language Development
{
"action": "start",
"command": "python3 -i",
"name": "backend-repl"
}
{
"action": "start",
"command": "node",
"name": "frontend-repl"
}
{
"action": "stdin",
"id": "backend-repl",
"data": "def process_data(data): return data.upper()\r"
}
{
"action": "stdin",
"id": "frontend-repl",
"data": "const formatData = (data) => data.toLowerCase()\r"
}
{
"action": "list"
}
Code Prototyping Workflow
{
"action": "start",
"command": "python3 -i",
"name": "prototype"
}
{
"action": "stdin",
"id": "prototype",
"data": "def factorial(n): return 1 if n <= 1 else n * factorial(n-1)\r"
}
{
"action": "stdin",
"id": "prototype",
"data": "factorial(5)\r"
}
{
"action": "stdin",
"id": "prototype",
"data": "factorial(0)\r"
}
{
"action": "stdin",
"id": "prototype",
"data": "factorial(1)\r"
}
{
"action": "stdin",
"id": "prototype",
"data": "def factorial_iterative(n):\r result = 1\r for i in range(2, n + 1):\r result *= i\r return result\r\r"
}
{
"action": "stdin",
"id": "prototype",
"data": "import time\r"
}
{
"action": "stdin",
"id": "prototype",
"data": "start = time.time(); factorial(100); print(time.time() - start)\r"
}
{
"action": "stdout",
"id": "prototype"
}
Interactive Documentation Generation
{
"action": "start",
"command": "ipython",
"name": "doc-gen"
}
{
"action": "stdin",
"id": "doc-gen",
"data": "import mymodule\r"
}
{
"action": "stdin",
"id": "doc-gen",
"data": "import inspect\r"
}
{
"action": "stdin",
"id": "doc-gen",
"data": "inspect.signature(mymodule.my_function)\r"
}
{
"action": "stdin",
"id": "doc-gen",
"data": "mymodule.my_function.__doc__\r"
}
{
"action": "stdin",
"id": "doc-gen",
"data": "mymodule.my_function('test')\r"
}
{
"action": "stdout",
"id": "doc-gen"
}
Session State Management
{
"action": "stdin",
"id": "python-repl",
"data": "import dill\r"
}
{
"action": "stdin",
"id": "python-repl",
"data": "dill.dump_session('session.pkl')\r"
}
{
"action": "stdin",
"id": "python-repl",
"data": "dill.load_session('session.pkl')\r"
}
Best Practices
REPL Session Hygiene
- Name sessions descriptively: Use
name that reflects purpose (e.g., "api-test", "data-explore")
- Clean up variables: Use
del variable to free memory
- Restart when needed: Stop and start fresh sessions to avoid state pollution
- Use stream mode for long operations: Avoid blocking on compute-intensive tasks
Error Handling
{
"action": "stdin",
"id": "python-repl",
"data": "try:\r risky_operation()\rexcept Exception as e:\r print(f'Error: {e}')\r import traceback\r traceback.print_exc()\r\r"
}
Output Parsing
- Use
stdout action after commands that produce output
- Parse REPL prompt patterns to extract results
- Use
stream with since_last: true for incremental output
- Strip ANSI codes if needed for clean parsing
Managing Long-Running Operations
{
"action": "stdin",
"id": "python-repl",
"data": "result = expensive_computation()\r"
}
{
"action": "stream",
"id": "python-repl",
"since_last": true
}
{
"action": "stdout",
"id": "python-repl"
}
Multi-Session Coordination
{
"action": "list"
}
{
"action": "stop",
"id": "python-repl"
}
Common REPL Workflows
Quick Script Testing
- Start REPL
- Paste/type code snippets
- Test with various inputs
- Capture output
- Refine code
- Save final version to file
Library Evaluation
- Start REPL
- Import library
- Explore API with
dir() and help
- Test key functions
- Measure performance with
%timeit
- Document findings
Debugging Production Issues
- Start REPL with production environment
- Import relevant modules
- Reproduce issue with test data
- Inspect intermediate states
- Test fixes
- Verify solution
Interactive Configuration
- Start REPL
- Load configuration
- Test different settings
- Validate outcomes
- Save working configuration
This skill provides comprehensive patterns for AI-driven REPL interaction using terminalcp's persistent session management.