工具集成开发框架

xmcp是一个基于TypeScript的工具集成开发框架,支持自动发现和加载工具,适用于构建高效的工具链和自动化流程。

  • by alpic-ai
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 alpic-ai/mcp-server-template-xmcp

使用说明

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

或者,您可以使用脚本,该脚本将根据您的项目配置自动启动相应的传输:

npm run start
# or
yarn start
# or
pnpm start

启动脚本将根据初始化项目时选择的传输方法自动运行HTTP或STDIO传输。

了解更多