Return errors over MCP

This commit is contained in:
Conrad Irwin
2025-08-28 13:15:14 -06:00
parent 79c2cae29d
commit 163b5c87b5

View File

@@ -47,39 +47,51 @@ In sessions with mcp__acp__read always use it instead of Read as it contains the
}, },
}, },
async (input) => { async (input) => {
console.error("READ TOOL", input); try {
const session = agent.sessions[sessionId]; console.error("READ TOOL", input);
if (!session) { const session = agent.sessions[sessionId];
if (!session) {
return {
content: [
{
type: "text",
text: "The user has left the building",
},
],
};
}
let content = await agent.client.readTextFile({
sessionId,
path: input.abs_path,
limit: input.limit,
line: input.offset,
});
console.error("READ FILE READ", content);
return { return {
content: [ content: [
{ {
type: "text", type: "text",
text: "The user has left the building", text:
}, content.content +
], `
};
}
let content = await agent.client.readTextFile({
sessionId,
path: input.abs_path,
limit: input.limit,
line: input.offset,
});
return {
content: [
{
type: "text",
text:
content.content +
`
<system-reminder> <system-reminder>
Whenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior. Whenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.
</system-reminder>`, </system-reminder>`,
}, },
], ],
}; };
} catch (error: any) {
return {
content: [
{
type: "text",
text: "Reading file failed: " + error.message,
},
],
};
}
}, },
); );
@@ -104,27 +116,38 @@ allow the user to conveniently review changes.`,
}, },
}, },
async (input) => { async (input) => {
console.error("WRITE TOOL", input); try {
const session = agent.sessions[sessionId]; console.error("WRITE TOOL", input);
if (!session) { const session = agent.sessions[sessionId];
if (!session) {
return {
content: [
{
type: "text",
text: "The user has left the building",
},
],
};
}
let content = await agent.client.writeTextFile({
sessionId,
path: input.abs_path,
content: input.content,
});
return {
content: [],
};
} catch (error: any) {
return { return {
content: [ content: [
{ {
type: "text", type: "text",
text: "The user has left the building", text: "Writing file failed: " + error.message,
}, },
], ],
}; };
} }
let content = await agent.client.writeTextFile({
sessionId,
path: input.abs_path,
content: input.content,
});
return {
content: [],
};
}, },
); );
@@ -162,35 +185,46 @@ File editing instructions:
}, },
}, },
async (input) => { async (input) => {
console.error("EDIT TOOL", input); try {
const session = agent.sessions[sessionId]; console.error("EDIT TOOL", input);
if (!session) { const session = agent.sessions[sessionId];
if (!session) {
return {
content: [
{
type: "text",
text: "The user has left the building",
},
],
};
}
let { content } = await agent.client.readTextFile({
sessionId,
path: input.abs_path,
});
let newContent = content.replace(input.old_text, input.new_text);
await agent.client.writeTextFile({
sessionId,
path: input.abs_path,
content: newContent,
});
return {
content: [],
};
} catch (error: any) {
return { return {
content: [ content: [
{ {
type: "text", type: "text",
text: "The user has left the building", text: "Editing file failed: " + error.message,
}, },
], ],
}; };
} }
let { content } = await agent.client.readTextFile({
sessionId,
path: input.abs_path,
});
let newContent = content.replace(input.old_text, input.new_text);
await agent.client.writeTextFile({
sessionId,
path: input.abs_path,
content: newContent,
});
return {
content: [],
};
}, },
); );