无认证MCP服务器

一个无需认证的Express.js服务器模板,适用于公共API和开发环境,提供TypeScript类型安全和简单配置。

  • by granular-software
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 granular-software/template-express-no-auth

使用说明

{{项目名称}}

{{PROJECT_DESCRIPTION}}

此模板提供了一个无需身份验证的简单MCP服务器,非常适合公共API和开发。

特性

  • ✅ 不要求进行验证
  • ✅ Express.js服务器
  • ✅ 简单设置
  • ✅ 非常适合公共API
  • ✅ 有利于发展
  • ✅ 具有完全类型安全的TypeScript

快速开始

先决条件

  • Node.js 18+
  • npm或纱线

1.克隆和设置

# Clone this template
git clone https://github.com/granular-software/template-express-no-auth.git my-mcp-server
cd my-mcp-server

# Install dependencies
npm install

2.环境配置

复制示例环境文件并对其进行配置:

cp env.example .env

编辑 .env 根据您的配置:

# Server Configuration
SERVER_URL=http://localhost:3000
PORT=3000

3.发展

# Start development server
npm run dev

# The server will be available at http://localhost:3000
# MCP Inspector: http://localhost:3000

4.生产

# Build the application
npm run build

# Start production server
npm start

项目结构

├── src/
│   ├── server.ts              # Main server file
│   └── resources/
│       ├── schemas/           # Resource schemas
│       │   └── Note.ts        # Note data model
│       └── handlers/          # Resource handlers
│           └── note.ts        # Example note resource
├── env.example               # Environment variables template
└── README.md                 # This file

API访问

由于此模板没有身份验证,因此所有API端点都可以公开访问。这使其非常适合:

  • 公共数据API
  • 开发和测试
  • 具有网络级安全的内部服务
  • 原型制作和演示

环境变量

变量 描述 必填 默认
SERVER_URL 服务器的基本URL 是 -
PORT 服务器端口 否 3000

发展

添加资源

在中创建新的MCP资源 src/resources/:

import { z } from "zod";
import { createResource } from "mcpresso";

const MyResourceSchema = z.object({
  id: z.string(),
  name: z.string(),
  // ... your schema
});

export const myResource = createResource({
  name: "my-resource",
  schema: MyResourceSchema,
  uri_template: "my-resources/{id}",
  methods: {
    get: {
      handler: async ({ id }) => {
        // Your implementation
      },
    },
    // ... other methods
  },
});

示例资源

该模板包括一个示例注释资源,用于演示:

  • CRUD操作(创建、读取、更新、删除)
  • 搜索功能
  • 使用Zod进行模式验证
  • 错误处理

生产注意事项

  1. 安全:由于没有身份验证,请确保网络级安全
  2. 速率限制:考虑为公共API添加速率限制
  3. 安全套接层:确保在生产中启用HTTPS
  4. 监控:添加日志记录和监控
  5. 跨域资源共享:如果需要,为web客户端配置CORS

故障排除

常见问题

  1. 端口冲突:更改 PORT 在……里面 .env 如果3000正在使用中
  2. CORS问题:如果需要,添加CORS中间件
  3. 网络接入:确保防火墙允许连接

日志

检查调试日志:

# Application logs
npm run dev

许可证

MIT许可证-有关详细信息,请参阅许可证文件。

支持

  • GitHub问题:https://github.com/granular-software/mcpresso
  • 文档:https://github.com/granular-software/mcpresso