工具开发框架

xmcp是一个基于TypeScript的工具开发框架,支持自动发现和定义工具,适用于快速构建和部署工具服务。

  • by MarshallBorham
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 MarshallBorham/ff-mcp

使用说明

xmcp应用程序

此项目是通过以下方式创建的 创建xmcp应用程序.

入门指南

首先,运行开发服务器:

npm run dev
# or
yarn dev
# or
pnpm dev

这将使用所选的传输方法启动MCP服务器。

项目结构

该项目使用结构化方法,从中自动发现工具 src/tools 目录。每个工具都在自己的文件中定义,其结构如下:

import { z } from "zod";
import { type InferSchema } from "xmcp";

// Define the schema for tool parameters
export const schema = {
  a: z.number().describe("First number to add"),
  b: z.number().describe("Second number to add"),
};

// Define tool metadata
export const metadata = {
  name: "add",
  description: "Add two numbers together",
  annotations: {
    title: "Add Two Numbers",
    readOnlyHint: true,
    destructiveHint: false,
    idempotentHint: true,
  },
};

// Tool implementation
export default async function add({ a, b }: InferSchema<typeof schema>) {
  return {
    content: [{ type: "text", text: String(a + b) }],
  };
}

添加新工具

要添加新工具,请执行以下操作:

  1. 创建新的 .ts 文件在 src/tools 目录
  2. 出口A schema 使用Zod定义刀具参数的对象
  3. 出口A metadata 带有工具信息的对象
  4. 导出实现工具逻辑的默认函数

生产大楼

要构建生产项目,请执行以下操作:

npm run build
# or
yarn build
# or
pnpm build

这将编译你的TypeScript代码并将其输出到 dist 目录。

运行服务器

您可以为使用以下构建的传输运行服务器:

  • HTTP: node dist/http.js
  • 工作室: node dist/stdio.js

给定所选的传输方法,您将有一个自定义的启动脚本添加到 package.json 文件。

对于HTTP:

npm run start-http
# or
yarn start-http
# or
pnpm start-http

对于STDIO:

npm run start-stdio
# or
yarn start-stdio
# or
pnpm start-stdio

了解更多