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
给定所选的传输方法,您将有一个自定义的启动脚本添加到 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