Skills: Custom Tool Development
Last updated: 2026-08-31
Built-in tools not enough? Build your own — the MCP protocol means Skill capabilities have no boundaries.
1. MCP Protocol Basics
(1) What is MCP
Model Context Protocol is the standard protocol for AI tools:
TEXT
📖 Display only
MCP Architecture
┌──────────┐ MCP Protocol ┌──────────────┐
│ AI Client │ ←──────────────→ │ MCP Server │
│ (Claude) │ │ (Custom Tool) │
└──────────┘ └──────────────┘
↕
┌──────────────┐
│ External │
│ Service │
│ (DB/API/File) │
└──────────────┘
(2) Tool Types
| Type | Description | Example |
|---|---|---|
| Resource tools | Provide data reading | Database queries, file systems |
| Action tools | Execute operations | Send email, create tickets |
| Prompt tools | Provide templates | Report templates, review checklists |
2. Developing Custom Tools
(1) Requirements Analysis
TEXT
📖 Display only
Custom Tool Development Flow
1. Identify needs that built-in tools can't meet
2. Define tool input/output
3. Choose implementation (Node.js / Python)
4. Implement tool logic
5. Configure MCP server
6. Bind and use in Skill
(2) Minimal Implementation
TYPESCRIPT
// mcp-server-example/index.ts
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new McpServer({ name: "db-query", version: "1.0.0" });
server.tool("query_database", { sql: { type: "string" } }, async ({ sql }) => {
const result = await executeQuery(sql);
return { content: [{ type: "text", text: JSON.stringify(result) }] };
});
const transport = new StdioServerTransport();
await server.connect(transport);
(3) Configuration & Integration
JSON
{
"mcpServers": {
"db-query": {
"command": "node",
"args": ["./mcp-servers/db-query/index.js"],
"env": {
"DATABASE_URL": "postgresql://localhost/mydb"
}
}
}
}
3. Tool Design Principles
(1) Single Responsibility
Each tool does one thing:
| ✅ Good Design | ❌ Bad Design |
|---|---|
query_database |
do_database_stuff |
send_email |
communicate |
search_logs |
find_stuff |
(2) Input Validation
TYPESCRIPT
server.tool("query_database", {
sql: {
type: "string",
description: "SQL query statement (SELECT only)",
validate: (sql: string) => {
if (/^\s*(DROP|DELETE|UPDATE|INSERT|ALTER)/i.test(sql)) {
throw new Error("Only SELECT queries are allowed");
}
}
}
}, handler);
(3) Error Handling
TYPESCRIPT
async ({ sql }) => {
try {
const result = await executeQuery(sql);
return { content: [{ type: "text", text: JSON.stringify(result) }] };
} catch (error) {
return {
content: [{ type: "text", text: `Query failed: ${error.message}` }],
isError: true
};
}
};
4. Tool Debugging & Publishing
(1) Local Debugging
BASH
# Run MCP server directly for testing
node ./mcp-servers/db-query/index.js
# Send test request
echo '{"method":"tools/list"}' | node ./mcp-servers/db-query/index.js
(2) Logging
TYPESCRIPT
// Add logging middleware
server.tool("query_database", { sql: { type: "string" } }, async ({ sql }) => {
console.error(`[DB-QUERY] SQL: ${sql}`);
const start = Date.now();
const result = await executeQuery(sql);
console.error(`[DB-QUERY] Duration: ${Date.now() - start}ms`);
return { content: [{ type: "text", text: JSON.stringify(result) }] };
});
(3) Publishing & Distribution
TEXT
📖 Display only
Publishing Methods
├── npm package: npm publish @your-org/mcp-server-xxx
├── Docker: docker build + docker push
├── Git repo: Direct clone and use
└── Config template: Provide JSON configuration template
5. Custom Tool Practice
▶ Example: Log Search Tool
Alice developed a log search MCP tool:
YAML
---
name: log-analyzer
description: "Log analysis: search, filter, statistics"
tools:
- Read
- search_logs # Custom MCP tool
---
Bob said: "The value of custom tools is connecting AI to your proprietary systems — where generic tools can't reach, custom tools fill the gap."
❓ FAQ
Q Must I use TypeScript for MCP tools?
A No. MCP protocol is JSON-RPC; any language can implement it. Official SDKs provide TypeScript and Python versions.
Q Do custom tools have security risks?
A Yes. Always do input validation and access control inside the tool; don't leave security entirely to Skill prompts.
Q Can one MCP server provide multiple tools?
A Yes. But we recommend no more than 5 tools per server to maintain focused responsibility.
📖 Summary
- MCP protocol: Standard communication protocol between AI clients and custom tools
- Development flow: Requirements analysis → implement → configure → debug → publish
- Design principles: Single responsibility, input validation, error handling
- Core value: Connect AI with proprietary systems, extend Skill capability boundaries
📝 Exercises
- Basic (⭐): Use the MCP SDK to create a simple Hello World tool and integrate it with a Skill.
- Intermediate (⭐⭐): Develop a database query MCP tool with input validation and error handling.
- Advanced (⭐⭐⭐): Develop a complete log analysis MCP tool supporting search, filtering, and statistics, with debugging and publishing documentation.