m

mcp服务器

@hyen43/mcpServer
0 Stars 18 次浏览 hyen43 更新于 2026-08-23

使用mcp框架构建的服务器,允许用户通过添加自定义工具来扩展Claude的功能,这些工具可以通过Claude桌面客户端使用。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "my-mcp-server": {
      "args": [
        "my-mcp-server"
      ],
      "command": "npx"
    }
  }
}

服务介绍

my-mcp-server

一个使用 mcp-framework 构建的 Model Context Protocol (MCP) 服务器。

快速开始

# Install dependencies
npm install

# Build the project
npm run build

项目结构

my-mcp-server/
├── src/
│   ├── tools/        # MCP Tools
│   │   └── ExampleTool.ts
│   └── index.ts      # Server entry point
├── package.json
└── tsconfig.json

添加组件

该项目在 src/tools/ExampleTool.ts 中包含一个示例工具。您可以使用 CLI 添加更多工具:

# Add a new tool
mcp add tool my-tool

# Example tools you might create:
mcp add tool data-processor
mcp add tool api-client
mcp add tool file-handler

工具开发

示例工具结构:

import { MCPTool } from "mcp-framework";
import { z } from "zod";

interface MyToolInput {
  message: string;
}

class MyTool extends MCPTool<MyToolInput> {
  name = "my_tool";
  description = "Describes what your tool does";

  schema = {
    message: {
      type: z.string(),
      description: "Description of this input parameter",
    },
  };

  async execute(input: MyToolInput) {
    // Your tool logic here
    return `Processed: ${input.message}`;
  }
}

export default MyTool;

发布到 npm

  1. 更新您的 package.json:

    • 确保 name 是唯一的,并且遵循 npm 的命名规范
    • 设置适当的 version
    • 添加 description, author, license
    • 检查 bin 是否指向正确的入口文件
  2. 本地构建和测试:

    npm run build
    npm link
    my-mcp-server  # 本地测试您的 CLI
    
  3. 登录 npm(如果需要,请创建账户):

    npm login
    
  4. 发布您的包:

    npm publish
    

发布后,用户可以将其添加到他们的 Claude 桌面客户端配置文件中(请参阅下面的内容),或者使用 npx 运行它


## Using with Claude Desktop

### Local Development

Add this configuration to your Claude Desktop config file:

**MacOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
**Windows**: `%APPDATA%/Claude/claude_desktop_config.json`

```json
{
  "mcpServers": {
    "my-mcp-server": {
      "command": "node",
      "args":["/absolute/path/to/my-mcp-server/dist/index.js"]
    }
  }
}

发布后

将以下配置添加到您的 Claude Desktop 配置文件中:

MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "my-mcp-server": {
      "command": "npx",
      "args": ["my-mcp-server"]
    }
  }
}

构建和测试

  1. 对您的工具进行修改
  2. 运行 npm run build 编译
  3. 服务器将在启动时自动加载您的工具

了解更多