mcp-tools

本專案的 MCP Tools 位於 pai-bot/src/mcp/tools/ 。

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "mcp-tools" with this command: npx skills add wayne930242/merlin-my-pai/wayne930242-merlin-my-pai-mcp-tools

MCP Tools 開發指南

本專案的 MCP Tools 位於 pai-bot/src/mcp/tools/ 。

架構模式

Service Layer (ts-results) MCP Tool Layer ┌─────────────────────┐ ┌──────────────────────┐ │ Result<T, Error> │ --> │ { content, isError } │ └─────────────────────┘ └──────────────────────┘

Service Layer

使用 ts-results 回傳 Result<T, Error> :

import { Err, Ok, type Result } from "ts-results";

export async function getData(): Promise<Result<Data, Error>> { try { const data = await api.fetch(); return Ok(data); } catch (error) { return Err(error instanceof Error ? error : new Error(String(error))); } }

MCP Tool Layer

  1. 註冊工具

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

export function registerMyTools(server: McpServer): void { server.registerTool( "tool_name", // 命名:category_action { title: "Tool Title", description: "工具描述(中文)", inputSchema: { param: z.string().describe("參數說明"), optional: z.number().optional().describe("可選參數"), }, }, async ({ param, optional = 5 }) => { // 實作 } ); }

  1. 處理 Result

async ({ query }) => { const result = await service.getData(query);

if (result.err) { return { content: [{ type: "text", text: 錯誤: ${result.val.message} }], isError: true, }; }

return { content: [{ type: "text", text: JSON.stringify(result.val, null, 2) }], }; }

  1. 無 Result 的 Service(使用 try-catch)

async ({ query }) => { try { const data = await legacyService.fetch(query); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { const message = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: 錯誤: ${message} }], isError: true, }; } }

命名規範

類別 格式 範例

工具名稱 category_action

google_calendar_list , memory_search

函數名稱 registerXxxTools

registerGoogleTools

錯誤訊息格式

${Category} 錯誤: ${error.message} // 範例: "Google Calendar 錯誤: Invalid credentials"

註冊入口

在 pai-bot/src/mcp/index.ts 註冊:

import { registerMyTools } from "./tools/my-tools";

export function createMcpServer(): McpServer { const server = new McpServer({ name: "pai-bot", version: "1.0.0" }); registerMyTools(server); return server; }

Checklist

  • Service 使用 Result<T, Error>

  • Tool 處理 result.err 並回傳 isError: true

  • 使用 Zod schema 定義參數

  • 錯誤訊息包含分類前綴

  • 在 index.ts 註冊

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

mcp-tools

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

changelog-curator

从变更记录、提交摘要或发布说明中整理对外 changelog,并区分用户价值与内部改动。;use for changelog, release-notes, docs workflows;do not use for 捏造未发布功能, 替代正式合规审批.

Archived SourceRecently Updated
Automation

klaviyo

Klaviyo API integration with managed OAuth. Access profiles, lists, segments, campaigns, flows, events, metrics, templates, catalogs, and webhooks. Use this skill when users want to manage email marketing, customer data, or integrate with Klaviyo workflows. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).

Archived SourceRecently Updated
Automation

lifelog

生活记录自动化系统。自动识别消息中的日期(今天/昨天/前天/具体日期),使用 SubAgent 智能判断,记录到 Notion 对应日期,支持补录标记。 适用于:(1) 用户分享日常生活点滴时自动记录;(2) 定时自动汇总分析并填充情绪、事件、位置、人员字段

Archived SourceRecently Updated