使用说明
MCP服务器模板
使用以下构建的生产就绪MCP(模型上下文协议)服务器模板 玛斯特拉, 荣誉和Node.js。
快速开始
bun install
cp .env.example .env
bun run dev
服务器启动于 http://localhost:3000.MCP端点位于 /api/mcp/main/mcp.
项目结构
src/
server.ts - Entry point: Hono app + HTTP server
mastra/
index.ts - Mastra instance configuration
mcp-servers/
index.ts - MCPServer definition with tools
tools/
index.ts - Tool barrel export
echo.ts - Example echo tool
calculator.ts - Example calculator tool
test/
server.test.ts - Integration tests via MCPClient
添加工具
- 创建
src/mastra/tools/my-tool.ts:
import { createTool } from "@mastra/core/tools";
import { z } from "zod";
export const myTool = createTool({
id: "my-tool",
description: "Description of what the tool does",
inputSchema: z.object({
input: z.string().describe("Description of input"),
}),
execute: async ({ input }) => {
return { result: input };
},
});
- 出口自
src/mastra/tools/index.ts - 注册于
src/mastra/mcp-servers/index.ts
脚本
| 命令 | 描述 |
|---|---|
bun run dev |
以监视模式启动开发服务器 |
bun run start |
启动生产服务器 |
bun run test |
运行测试 |
bun run check |
棉绒和格式检查 |
bun run fix |
自动修复棉绒和格式化 |
部署
服务器通过以下方式在Node.js上运行 @hono/node-server.部署到任何支持Node.js的地方。
