mcp-tool-design
Skill4 starsChanged 9 months agoMITView on GitHub
Best practices for designing MCP tools including naming conventions, input schemas, error responses, pagination, idempotency, and descriptions. Use when the user is designing tools for an MCP server, writing tool schemas, handling tool errors, or needs guidance on tool naming and input validation patterns.
In this repository78 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/agents.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/claude-initial-setup.mdcCursor rule
- parallel-task-executionSkill
- subagent-patternsSkill
- task-coordinationSkill
- agent-communicationSkill
- context-managementSkill
- multi-agent-orchestrationSkill
- deploy-strategiesSkill
- github-actions-guideSkill
- pipeline-patternsSkill
- anthropic-sdk-guideSkill
- prompt-engineeringSkill
- tool-use-patternsSkill
- automated-review-setupSkill
- pr-standardsSkill
- review-checklistSkill
- file-organizationSkill
- immutability-patternsSkill
- naming-conventionsSkill
- branching-strategySkill
- commit-conventionsSkill
- pr-workflowSkill
- migration-patternsSkill
- query-optimizationSkill
- schema-design-guideSkill
- error-tracingSkill
- log-analysisSkill
- systematic-debuggingSkill
- django-admin-customizationSkill
- django-orm-masterySkill
- drf-api-patternsSkill
- docker-compose-guideSkill
- dockerfile-best-practicesSkill
- multi-stage-buildsSkill
- express-error-handlingSkill
- middleware-patternsSkill
- rest-api-nodeSkill
- async-fastapiSkill
- dependency-injection-fastapiSkill
- pydantic-validationSkill
- concurrency-patterns-goSkill
- error-handling-goSkill
- idiomatic-goSkill
- automation-triggersSkill
- hook-recipesSkill
- pre-post-hooksSkill
- junit-testingSkill
- maven-gradle-guideSkill
- spring-boot-patternsSkill
- mcp-resource-patternsSkill
- mcp-server-creationSkill
- context-optimizationSkill
- knowledge-persistenceSkill
- memory-patternsSkill
- caching-strategiesSkill
- lazy-loading-patternsSkill
- profiling-guideSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 26
Use snake_case, verb-first names.
- Distinctive: line 69
Use JSON Schema with descriptive property names, descriptions, and constraints.
- Distinctive: line 136
Use cursor-based pagination for tools that return large result sets.
- Distinctive: line 204
Not including pagination for tools that can return unbounded results
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MCP Tool Design
Best practices for designing well-structured, reliable MCP tools. Covers naming, schemas, error handling, pagination, idempotency, and effective descriptions.
When to Use
- User is designing new tools for an MCP server
- User is writing JSON Schema for tool inputs
- User needs pagination or idempotency patterns
- User wants guidance on tool naming or descriptions
- User is handling errors in MCP tool responses
Core Patterns
Naming Conventions
Use snake_case, verb-first names. Group related tools with a common prefix.
// Good: verb_noun pattern, clear scope
server.tool("search_issues", ...);
server.tool("create_issue", ...);
server.tool("update_issue", ...);
server.tool("list_repositories", ...);
server.tool("get_file_contents", ...);
// Bad: inconsistent, vague, or noun-first
server.tool("issues", ...); // What action?
server.tool("doSearch", ...); // camelCase
server.tool("repository-list", ...); // kebab-case, noun-firstWriting Effective Descriptions
Descriptions tell Claude WHEN and WHY to use the tool. Be specific and directive.
// Good: explains purpose, trigger conditions, and constraints
server.tool(
"search_codebase",
"Search for code patterns across the repository using regex. " +
"Use this when the user asks to find functions, classes, imports, " +
"or specific code patterns. Supports file type filtering. " +
"Returns up to 50 matches per call -- use pagination for more.",
schema,
handler
);
// Bad: vague, tells Claude nothing useful
server.tool(
"search",
"Searches for things.",
schema,
handler
);Input Schema Design
Use JSON Schema with descriptive property names, descriptions, and constraints.
import { z } from "zod";
server.tool(
"search_issues",
"Search GitHub issues by query, state, and labels.",
{
query: z.string()
.describe("Search query string. Searches title and body text."),
state: z.enum(["open", "closed", "all"])
.default("open")
.describe("Filter by issue state. Default: open."),
labels: z.array(z.string())
.optional()
.describe("Filter by label names. Returns issues matching ALL labels."),
limit: z.number()
.int()
.min(1)
.max(100)
.default(20)
.describe("Maximum results to return. Range: 1-100. Default: 20."),
cursor: z.string()
.optional()
.describe("Pagination cursor from a previous response.")
},
handler
);Error Response Patterns
Return structured errors with the isError flag so Claude can reason and recover.
server.tool("get_file", "Read a file by path.", { path: z.string() }, async ({ path }) => {
// Validate input
if (path.includes("..")) {
return {
isError: true,
content: [{ type: "text", text: "Path traversal not allowed. Use absolute paths within the project." }]
};
}
try {
const content = await fs.readFile(path, "utf-8");
return {
content: [{ type: "text", text: content }]
};
} catch (error) {
if (error.code === "ENOENT") {
return {
isError: true,
content: [{ type: "text", text: `File not found: ${path}. Check the path and try again.` }]
};
}
return {
isError: true,
content: [{ type: "text", text: `Failed to read file: ${error.message}` }]
};
}
});Pagination Pattern
Use cursor-based pagination for tools that return large result sets.
server.tool(
"list_commits",
"List commits for a repository branch. Returns 20 commits per page with a cursor for pagination.",
{
repo: z.string().describe("Repository name in owner/repo format."),
branch: z.string().default("main").describe("Branch name. Default: main."),
cursor: z.string().optional().describe("Pagination cursor from previous response.")
},
async ({ repo, branch, cursor }) => {
const page = cursor ? decodeCursor(cursor) : 1;
const commits = await fetchCommits(repo, branch, page, 20);
const hasMore = commits.length === 20;
const result = {
commits: commits.map(c => ({
sha: c.sha,
message: c.message,
author: c.author,
date: c.date
})),
next_cursor: hasMore ? encodeCursor(page + 1) : null,
has_more: hasMore
};
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
}
);Idempotency Pattern
Design tools so repeated calls with the same input produce the same result.
server.tool(
"set_config",
"Set a configuration value. Idempotent -- calling with the same key and value multiple times has no additional effect.",
{
key: z.string().describe("Configuration key."),
value: z.string().describe("Configuration value.")
},
async ({ key, value }) => {
const current = await getConfig(key);
if (current === value) {
return {
content: [{ type: "text", text: `Config "${key}" already set to "${value}". No change needed.` }]
};
}
await setConfig(key, value);
return {
content: [{ type: "text", text: `Config "${key}" set to "${value}".` }]
};
}
);Anti-Patterns
- Tool names longer than 64 characters (may be truncated or rejected)
- Missing
requiredarray in raw JSON Schema (Claude may skip required fields) - Descriptions that say "This tool does X" instead of "Use this when..."
- Returning HTML or binary data as text content (use appropriate MIME types)
- Tools with more than 10-15 parameters (split into multiple focused tools)
- Not including pagination for tools that can return unbounded results
- Destructive tools without confirmation (delete, drop, reset)
- Using generic error messages like "Something went wrong" without actionable guidance
Quick Reference
| Aspect | Guideline |
| Name format | snake_case, verb_noun, max 64 chars |
| Description | Explain WHEN to use, not just what it does |
| Parameters | Include type, description, defaults, constraints |
| Required fields | Always specify in schema |
| Pagination | Cursor-based, 20-50 items per page |
| Errors | Use isError: true, give actionable messages |
| Idempotency | Same input = same result for write operations |
| Tool count | Prefer many focused tools over few large ones |
Description template:
"[Action description]. Use when [trigger conditions]. [Constraints/limits]. [Returns description]."Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

