Skip to content

Commit c03a73d

Browse files
authored
Merge pull request #10 from ferrislucas/cleanup
Additional REPL support
2 parents b7a731d + a71477d commit c03a73d

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
1-
![Main Image](.github/images/demo.gif)
2-
31
# iterm-mcp
42
A Model Context Protocol server that provides access to your iTerm session.
53

4+
![Main Image](.github/images/demo.gif)
5+
66
### Features
77

8-
- **Efficient Token Use**: Only the visible content of the terminal is passed to the model. The model can retrieve content that's not visible if necessary.
9-
- **Supports Long-Running Processes**: iterm-mcp knows when the terminal is waiting for user input. Long-running processes are handled gracefully.
10-
- **Interrupt When Needed**: Send control characters to the terminal to interrupt processes.
11-
- **Inspect Terminal Activity**: Gives the model visibility into the current terminal content.
8+
**Efficient Token Use:** iterm-mcp gives the model the ability to inspect only the output that the model is interested in. The model typically only wants to see the last few lines of output even for long running commands.
9+
10+
**Natural Integration:** You share iTerm with the model. You can ask questions about what's on the screen, or delegate a task to the model and watch as it performs each step.
11+
12+
**Full Terminal Control and REPL support:** The model can start and interact with REPL's as well as send control characters like ctrl-c, ctrl-z, etc.
13+
14+
**Easy on the Dependencies:** iterm-mcp is built with minimal dependencies and is runnable via npx. It's designed to be easy to add to Claude Desktop and other MCP clients. It should just work.
15+
1216

1317
<a href="https://glama.ai/mcp/servers/h89lr05ty6"><img width="380" height="200" src="https://glama.ai/mcp/servers/h89lr05ty6/badge" alt="iTerm Server MCP server" /></a>
1418

19+
## Safety Considerations
20+
21+
* The user is responsible for using the tool safely.
22+
* No built-in restrictions: iterm-mcp makes no attempt to evaluate the safety of commands that are executed.
23+
* Models can behave in unexpected ways. The user is expected to monitor activity and abort when appropriate.
24+
* For multi-step tasks, you may need to interrupt the model if it goes off track. Start with smaller, focused tasks until you're familiar with how the model behaves.
25+
1526
### Tools
16-
- `write_to_terminal` - Writes to the active iTerm terminal, often used to run a command.
17-
- `read_terminal_output` - Reads the output from the active iTerm terminal.
27+
- `write_to_terminal` - Writes to the active iTerm terminal, often used to run a command. Returns the number of lines of output produced by the command.
28+
- `read_terminal_output` - Reads the requested number of lines from the active iTerm terminal.
1829
- `send_control_character` - Sends a control character to the active iTerm terminal.
1930

20-
## Installation
21-
2231
### Requirements
2332

24-
- Node.js 18 or higher
33+
* iTerm2 must be running
34+
* Node version 18 or greater
35+
36+
37+
## Installation
2538

2639
To use with Claude Desktop, add the server config:
2740

@@ -74,7 +87,7 @@ Since MCP servers communicate over stdio, debugging can be challenging. We recom
7487

7588
```bash
7689
yarn run inspector
77-
yarn debug
90+
yarn debug <command>
7891
```
7992

8093
The Inspector will provide a URL to access debugging tools in your browser.

src/ProcessTracker.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ interface ActiveProcess {
4444

4545
class ProcessTracker {
4646
private readonly shellNames = new Set(['bash', 'zsh', 'sh', 'fish', 'csh', 'tcsh']);
47-
private readonly replNames = new Set(['irb', 'pry', 'rails', 'node', 'python', 'ipython']);
47+
private readonly replNames = new Set([
48+
'irb', 'pry', 'rails', 'node', 'python', 'ipython',
49+
'scala', 'ghci', 'iex', 'lein', 'clj', 'julia', 'R', 'php', 'lua'
50+
]);
4851

4952
/**
5053
* Get the active process and its resource usage in an iTerm tab
@@ -240,29 +243,28 @@ class ProcessTracker {
240243
let score = 0;
241244

242245
// Base scores for process state
246+
// 'R' (running) processes get 2 points, 'S' (sleeping) get 1 point
243247
score += process.state === 'R' ? 2 : process.state === 'S' ? 1 : 0;
244248

245249
// CPU usage bonus
246-
score += Math.min(process.cpuPercent / 10, 5); // Up to 5 points for CPU usage
250+
// Add up to 5 points based on CPU usage percentage (1 point per 10%)
251+
score += Math.min(process.cpuPercent / 10, 5);
247252

248253
// Penalize shell processes unless they're the only option
254+
// Shell processes are less interesting, so deduct 1 point
249255
if (this.shellNames.has(cmdName)) {
250256
score -= 1;
251257
}
252258

253259
// Give high priority to REPL processes
254-
if (cmd.includes('rails console') ||
255-
cmd.includes('rails server') ||
256-
this.replNames.has(cmdName)) {
260+
// Add 3 points for REPLY processes
261+
if (this.replNames.has(cmdName)) {
257262
score += 3;
258263
}
259264

260-
// Bonus for Ruby processes in a Rails context
261-
if (cmdName === 'ruby' && cmd.includes('rails')) {
262-
score += 2;
263-
}
264265

265266
// Bonus for active package manager operations
267+
// Add 2 points for package managers like 'brew', 'npm', or 'yarn' if they are using CPU
266268
if ((cmdName === 'brew' || cmdName === 'npm' || cmdName === 'yarn') &&
267269
process.cpuPercent > 0) {
268270
score += 2;

0 commit comments

Comments
 (0)