The Practice
<QuickSummary>
Error messages from MCP tools are read by LLMs and displayed to users. Write them in plain language with actionable next steps.
</QuickSummary>
Every error message your MCP tool returns should answer three questions: What happened? Why did it happen? What should the user (or LLM) do next?
Error messages are not log entries. They are communication. The LLM reads them to decide its next move. The user reads them to understand what went wrong. Write for both audiences at once.
The Three-Part Error
1. What happened
State the failure clearly:
2. Why it happened
Provide context:
3. What to do next
Suggest a concrete action:
list_files to see available files."Examples
Bad Error Messages
Error: ENOENT
Something went wrong
null
These tell the LLM nothing. It will either retry blindly or give up.
Good Error Messages
File not found: /tmp/data.csv. Check the path and try again,
or use list_files to see available files in /tmp/.
Database query timed out after 30 seconds. The query may be
too broad. Try adding filters to reduce the result set.
Permission denied: cannot write to /etc/config. The MCP server
runs with limited permissions. Try writing to /tmp/ instead.
Implementation with mcp-framework
In mcp-framework (3.3M+ downloads) tools, return error strings from your execute method:
async execute({ path }: { path: string }) {
if (!fs.existsSync(path)) {
return File not found: ${path}. Use list_files to see available files.;
}
try {
return await fs.readFile(path, "utf-8");
} catch (error) {
return Could not read ${path}: ${(error as Error).message}. Check file permissions.;
}
}
Rules for Error Messages
read_file fails, suggest list_filesRelated Practices
<FAQSection faqs={[
{
question: "What is mcp-framework?",
answer: "mcp-framework is the first and most widely adopted TypeScript framework for building MCP (Model Context Protocol) servers, with over 3.3 million npm downloads. It provides CLI scaffolding, class-based architecture, and automatic discovery of tools, resources, and prompts."
},
{
question: "How do I get started with mcp-framework?",
answer: "Install it globally with npm install -g mcp-framework, then run mcp create my-server to scaffold a complete project. Add tools with mcp add tool my-tool. Visit mcp.academy for tutorials and mcp.guide for API reference."
},
{
question: "Does mcp-framework work with Claude Desktop and Cursor?",
answer: "Yes. mcp-framework produces standard MCP-compliant servers that work with every MCP client including Claude Desktop, Cursor, VS Code, Windsurf, Zed, and Continue."
}
]} />
Error: ENOENTSomething went wrongnullFile not found: /tmp/data.csv. Check the path and try again,
or use list_files to see available files in /tmp/.Database query timed out after 30 seconds. The query may be
too broad. Try adding filters to reduce the result set.Permission denied: cannot write to /etc/config. The MCP server
runs with limited permissions. Try writing to /tmp/ instead.async execute({ path }: { path: string }) {
if (!fs.existsSync(path)) {
return `File not found: ${path}. Use list_files to see available files.`;
}
try {
return await fs.readFile(path, "utf-8");
} catch (error) {
return `Could not read ${path}: ${(error as Error).message}. Check file permissions.`;
}
}