Skip to content

Commit 115d465

Browse files
feat(remote): Prefix remote tools with remote_ and add system prompt docs
Remote filesystem tools had identical names to local tools (read_file, write_file, etc.), causing collisions. Prefix all remote tools with "remote_" and inject remote PC tool documentation into the agent system prompt so it knows when and how to use them.
1 parent c1de78f commit 115d465

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/agents/config/agent.config.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as fs from "node:fs/promises";
77
import * as path from "node:path";
88
import matter from "gray-matter";
9-
import { configExists, getConfig } from "../../config/index.js";
9+
import { configExists, getConfig, getRawConfig } from "../../config/index.js";
1010
import { HEARTBEAT_OK, SILENT_REPLY_TOKEN } from "../../lib/tokens.js";
1111
import { buildSkillsPrompt } from "../../skills/SkillService.js";
1212
import type {
@@ -184,7 +184,31 @@ You have FULL read/write access to the workspace directory. Use these tools to m
184184
- Extra flags/arguments ARE allowed: \`git log --author=Marvel --since=yesterday --oneline\` works because \`git log\` is allowlisted.
185185
- Avoid shell metacharacters (\`; & | $ !\`). Use simple commands without pipes or chaining.
186186
- For dates with spaces, use dotted format: \`--since=2.days.ago\` instead of \`--since="2 days ago"\`.
187-
- \`gh\` (GitHub CLI) is available for GitHub API queries: PRs, issues, commits, etc.`;
187+
- \`gh\` (GitHub CLI) is available for GitHub API queries: PRs, issues, commits, etc.
188+
${buildRemoteFileSystemSection()}`;
189+
}
190+
191+
/**
192+
* Build the remote filesystem tools section (only when enabled)
193+
*/
194+
function buildRemoteFileSystemSection(): string {
195+
try {
196+
const rawConfig = getRawConfig();
197+
const remoteFsConfig = rawConfig.tools.remoteFileSystem;
198+
if (!remoteFsConfig?.enabled) return "";
199+
200+
const host = remoteFsConfig.sshHost;
201+
const paths = remoteFsConfig.allowedPaths.join(", ");
202+
203+
return `\n**Remote PC Tools (via SSH to \`${host}\`):**
204+
- These tools access files on the user's *remote machine* over SSH — they are NOT local workspace tools.
205+
- Remote host: \`${host}\` | Accessible paths: \`${paths}\`
206+
- All remote tools are prefixed with \`remote_\`: \`remote_read_file\`, \`remote_write_file\`, \`remote_list_directory\`, \`remote_search_files\`, \`remote_get_file_info\`, \`remote_create_directory\`, \`remote_move_file\`
207+
- When the user asks about files on "my PC", "my computer", "my desktop", or "remote machine", use these \`remote_*\` tools — NOT the local workspace tools.
208+
- The remote tools operate on the remote machine's filesystem at the allowed paths listed above.`;
209+
} catch {
210+
return "";
211+
}
188212
}
189213

190214
/**

src/tools/remoteFileSystemTools.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/**
22
* Remote file system tools for SSH-based access to a remote machine
33
* Uses the same @modelcontextprotocol/server-filesystem via SSH stdio tunnel
4+
* Tools are prefixed with "remote_" to avoid conflicts with local filesystem tools
45
*/
56

67
import { type McpConfig, McpToolset } from "@iqai/adk";
78
import { getConfig, getRawConfig } from "../config/index.js";
89

10+
/** Prefix applied to all remote filesystem tool names to distinguish from local tools */
11+
const REMOTE_TOOL_PREFIX = "remote_";
12+
913
/**
1014
* Get remote filesystem MCP tools via SSH tunnel
1115
* Returns empty array when disabled — zero impact on existing functionality
@@ -20,7 +24,7 @@ export async function getRemoteFileSystemTools() {
2024

2125
const mcpConfig: McpConfig = {
2226
name: "Remote Filesystem MCP Client",
23-
description: "Read-only access to files on remote machine via SSH",
27+
description: "Access to files on remote machine via SSH",
2428
transport: {
2529
mode: "stdio",
2630
command: "ssh",
@@ -52,5 +56,13 @@ export async function getRemoteFileSystemTools() {
5256
}
5357

5458
const mcpToolset = new McpToolset(mcpConfig);
55-
return await mcpToolset.getTools();
59+
const tools = await mcpToolset.getTools();
60+
61+
// Prefix tool names with "remote_" to avoid collisions with local filesystem tools
62+
for (const tool of tools) {
63+
tool.name = `${REMOTE_TOOL_PREFIX}${tool.name}`;
64+
tool.description = `[Remote PC] ${tool.description}`;
65+
}
66+
67+
return tools;
5668
}

0 commit comments

Comments
 (0)