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) {
return {
content: [{ type: 'text', text: String(a + b) }],
}
}添加新工具
要添加新工具,请执行以下操作:
- 创建新
.ts文件在src/tools目录 - 出口A
schema使用Zod定义刀具参数的对象 - 出口A
metadata带有工具信息的对象 - 导出实现工具逻辑的默认函数
生产大楼
要构建生产项目,请执行以下操作:
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传输。
