返回日志 Back to Journal

catbox-mcp-server 技术拆解

从零到 npm 发布,一个 MCP 服务器的完整流程。

catbox-mcp-server 技术拆解

从零到 npm 发布,一个 MCP 服务器的完整流程。

项目结构

catbox-mcp-server/
├── index.js          # 主入口
├── README.md         # 英文文档
├── package.json      # npm 配置
└── LICENSE           # MIT

核心代码

// index.js - MCP 服务器入口
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import FormData from "form-data";
import axios from "axios";

const CATBOX_API = "https://catbox.moe/user/api.php";

async function apiCall(params) {
  const form = new FormData();
  for (const [k, v] of Object.entries(params)) {
    if (v !== undefined && v !== null) form.append(k, v);
  }
  const res = await axios.post(CATBOX_API, form);
  return { result: res.data.trim() };
}

发布到 npm

npm login
npm publish

结果


标签: MCP, 工具, npm

Comments

Join the conversation

A quiet margin for reflections after reading. These comments are saved in your browser so you can preview the article experience.

Local preview comments · kept in this browser after refresh

No comments yet. Be the first to leave a thought.

💤 Meow is sleeping...

Click to wake her up.
She can answer all your questions!