AGENT SKILL

agent-tools

Build MCP servers and agent tools. Covers tool design, MCP protocol, input validation, error handling, and testing. Use when: "build a tool", "MCP server", "agent tool", "function calling", "give the agent access to", or when agents need new capabilities.

License 许可
MIT
所属仓库
kalash33/kstack
最近更新
2026-05-20
Stars
★ 0
Forks
0

01 前言 Front Matter

name
agent-tools
description
Build MCP servers and agent tools. Covers tool design, MCP protocol, input validation, error handling, and testing. Use when: "build a tool", "MCP server", "agent tool", "function calling", "give the agent access to", or when agents need new capabilities.

03 SKILL.md 正文

/agent-tools — Tool Builder

Tools are how agents interact with the world. Build them right.

When to Use

  • Agent needs a new capability (API access, file ops, browser, etc.)
  • Building an MCP server
  • Designing function-calling interfaces
  • Wrapping an API for agent use

Tool Design Principles

  1. One tool, one job. Don't combine search + filter + format.
  2. Clear descriptions. The LLM reads them to decide when to call.
  3. Typed inputs. Validate everything. Agents will send garbage.
  4. Useful errors. "Invalid date format, expected YYYY-MM-DD" not "Error".
  5. Idempotent when possible. Agents retry. Don't double-charge.

MCP Server Template

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({ name: "my-tool", version: "1.0.0" });

server.tool(
  "search_docs",
  "Search documentation by keyword. Returns top 5 matches.",
  { query: z.string().describe("Search query") },
  async ({ query }) => {
    const results = await searchIndex(query);
    return { content: [{ type: "text", text: JSON.stringify(results) }] };
  }
);

const transport = new StdioServerTransport();
await server.connect(transport);

Python Tool Template

def search_docs(query: str) -> str:
    """Search documentation by keyword. Returns top 5 matches.
    
    Args:
        query: The search query string
        
    Returns:
        JSON string with matching documents
    """
    if not query or len(query) > 500:
        return json.dumps({"error": "Query must be 1-500 characters"})
    
    results = index.search(query, limit=5)
    return json.dumps({"results": results})

Testing Tools

# Test happy path
assert "results" in json.loads(search_docs("authentication"))

# Test edge cases
assert "error" in json.loads(search_docs(""))
assert "error" in json.loads(search_docs("x" * 501))

# Test with actual agent
response = agent.run("Find docs about authentication")
assert "search_docs" in response.tool_calls

Chaining

  • Before: /agent-design (identifies what tools are needed)
  • After: /agent-build (wires tools into agents)

04 同仓库更多 Skills