Alpic MCP模板
用于使用Streamable HTTP传输构建MCP服务器的TypeScript模板。
概述
此模板为创建可以与AI助手和其他MCP客户端通信的MCP服务器提供了基础。它包括一个简单的HTTP服务器实现,其中包含示例工具、资源和提示,以帮助您开始构建自己的MCP集成。
先决条件
- Node.js 22+(见
.nvmrc确切版本)
安装
- 克隆存储库:
git clone
cd mcp-server-template- 安装依赖项:
npm install- 创建环境文件:
cp .env.example .env用法
发展
使用热重载启动开发服务器:
npm run dev服务器将于启动 http://localhost:3000 并在更改源代码时自动重新启动。
生产构建
建设生产项目:
npm run build编译后的JavaScript将输出到 dist/ 目录。
运行检查器
使用MCP检查器工具测试您的服务器:
npm run inspectorAPI终点
POST /mcp-主MCP通信端点GET /mcp-返回“方法不允许”(405)DELETE /mcp-返回“方法不允许”(405)
部署
使用以下按钮将服务器部署到Alpic

发展
添加新工具
要添加新工具,请修改 src/server.ts:
server.tool(
"tool-name",
"Tool description",
{
// Define your parameters using Zod schemas
param: z.string().describe("Parameter description"),
},
async ({ param }): Promise => {
// Your tool implementation
return {
content: [
{
type: "text",
text: `Result: ${param}`,
},
],
};
},
);添加新提示
要添加新的提示模板,请修改 src/server.ts:
server.prompt(
"prompt-name",
"Prompt description",
{
// Define your parameters using Zod schemas
param: z.string().describe("Parameter description"),
},
async ({ param }): Promise => {
return {
messages: [
{
role: "user",
content: {
type: "text",
text: `Your prompt content with ${param}`,
},
},
],
};
},
);