MCP服务器模板

这是一个用于构建AI与自动化工具API的MCP(模型上下文协议)服务器模板,提供HTTP与stdio传输、令牌认证和Docker部署能力,适用于快速创建和部署MCP服务器。

  • by eliware
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 eliware/mcp-server-template

使用说明

@eliware/mcp-server-template

A Model Context Protocol (MCP) server template for building AI and automation tool APIs.

Table of Contents

Features

This template starts Model Context Protocol servers. Each derived server owns its behavior and operating decisions.

Requirements

Use Node.js 26 or later. Use an MCP client that supports protocol revision 2026-07-28. Use npm 12 or later for repository validation.

Setup

Create a repository from this template. Replace the package name, description, URLs, keywords, and sample tool. Run npm ci from the repository root.

Usage

Follow this README and the user guide. Read release notes for release history.

Development

Read AGENTS.md and the specifications index before you change files. Keep documents and records in the repository that owns them.

Testing

Run npm test before handoff. It runs the repository checks.

Troubleshooting

If HTTP startup reports a missing token, set MCP_TOKEN in your environment or .env file. If a container health check fails, confirm that MCP_TOKEN and PORT match the container settings. See the server guide.

Security

Keep credentials, secrets, private data, and runtime state out of Git. Use only approved secret stores for secret values.

Configuration

Set MCP_TOKEN before HTTP startup. Stdio mode does not require this token. PORT defaults to 1234. LOG_LEVEL defaults to info. Store the token in an untracked .env file or an approved secret store.

Operations

Run node bin/mcp-server-template.mjs for HTTP. Run node bin/mcp-server-template.mjs --stdio for stdio. The HTTP listener uses 1234 by default. Build the image with docker build -t mcp-server-template .. Set MCP_TOKEN in .env before you run docker compose up --build. Set HOST_PORT to change the host listener number.

Deploy a released image by version tag and recorded SHA-256 digest. Publication does not deploy the server.

Tools

The server discovers tool adapters from tools/. Keep tool logic in src/tools/. The starter provides an echo tool. It returns the input text as JSON.

Resources

The starter registers no resources.

Prompts

The starter registers no prompts.

Transport

HTTP is the default transport. Use PORT to set the listener number. Pass --stdio to start stdio. Stdio mode does not open an HTTP listener or require MCP_TOKEN. Use a client that supports protocol revision 2026-07-28.

Authentication

HTTP requires the bearer token in MCP_TOKEN. Keep the token secret. Limit HTTP access to approved clients. Use HTTPS for remote access.

Schemas

Define each tool input with a Zod schema. Test its input and response shape.

Support

For help, questions, or to chat with the author and community, visit:

eliware.org on Discord

Links

License

MIT © Eliware