Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ The CLI searches for configuration in this order:
| `MCP_MAX_RETRIES` | Retry attempts for transient errors (0 = disable) | `3` |
| `MCP_RETRY_DELAY` | Base retry delay (milliseconds) | `1000` |
| `MCP_STRICT_ENV` | Error on missing `${VAR}` in config | `true` |
| `MCP_DAEMON_SOCKET` | Daemon socket path | `~/.mcp-cli/daemon.sock` |
| `MCP_DAEMON_IDLE_MS` | Daemon idle timeout (ms) | `300000` |

## Using with AI Agents

Expand Down Expand Up @@ -303,8 +305,12 @@ mcp-cli <server> # Show server tools and parameters
mcp-cli <server>/<tool> # Get tool JSON schema and descriptions
mcp-cli <server>/<tool> '<json>' # Call tool with JSON arguments
mcp-cli grep "<pattern>" # Search tools by name (glob pattern)
mcp-cli daemon start # Start persistent connection daemon
mcp-cli daemon stop # Stop daemon
```

For stateful MCP servers (browser automation, database sessions), start the daemon first. Connections persist across calls.

**Add `-d` to include tool descriptions** (e.g., `mcp-cli <server> -d`)

Workflow:
Expand Down
1 change: 1 addition & 0 deletions SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Access MCP servers through the command line. MCP enables interaction with extern
| `mcp-cli <server>/<tool>` | Get tool JSON schema |
| `mcp-cli <server>/<tool> '<json>'` | Call tool with arguments |
| `mcp-cli grep "<glob>"` | Search tools by name |
| `mcp-cli daemon start\|stop` | Manage persistent connections (for stateful servers) |

**Add `-d` to include descriptions** (e.g., `mcp-cli filesystem -d`)

Expand Down
31 changes: 31 additions & 0 deletions src/commands/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getServerConfig,
loadConfig,
} from '../config.js';
import { callViaDaemon, isDaemonRunning } from '../daemon.js';
import {
ErrorCode,
formatCliError,
Expand Down Expand Up @@ -148,6 +149,36 @@ export async function callCommand(options: CallOptions): Promise<void> {
process.exit(ErrorCode.CLIENT_ERROR);
}

if (await isDaemonRunning()) {
debug(`routing call through daemon: ${serverName}/${toolName}`);
try {
const result = await callViaDaemon(
serverName,
serverConfig,
toolName,
args,
);
if (options.json) {
console.log(formatJson(result));
} else {
console.log(formatToolResult(result));
}
return;
} catch (error) {
const errMsg = (error as Error).message;
if (errMsg.includes('not found') || errMsg.includes('unknown tool')) {
console.error(
formatCliError(toolNotFoundError(toolName, serverName, undefined)),
);
} else {
console.error(
formatCliError(toolExecutionError(toolName, serverName, errMsg)),
);
}
process.exit(ErrorCode.SERVER_ERROR);
}
}

let client: Client;
let close: () => Promise<void> = async () => {}; // Initialize to noop to prevent undefined access

Expand Down
Loading