MCP Server Boilerplate
MCP 服务器样板
使用 TypeScript 和 Express 构建的模型上下文协议 (MCP) 样板服务器实现。
目录
Related MCP server: MCP Server Scaffold
概述
该项目实现了一个遵循模型上下文协议 (MCP) 的服务器,允许应用程序以标准化的方式为 LLM 提供上下文。它包括:
一个完全配置的 MCP 服务器,具有 HTTP 和 stdio 传输选项
用于演示关键功能的示例资源、工具和提示
TypeScript 支持类型安全并改善开发人员体验
HTTP 传输层的快速集成
项目结构
mcp-server-boilerplate/
├── .env # Environment variables
├── .env.example # Example environment variables
├── .gitignore # Git ignore file
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── src/
│ ├── index.ts # Main HTTP server entry point
│ ├── stdio.ts # Stdio server entry point
│ ├── resources/ # MCP resources
│ │ ├── index.ts # Resource registration
│ │ ├── infoResource.ts # Static info resource
│ │ └── greetingResource.ts # Dynamic greeting resource
│ ├── tools/ # MCP tools
│ │ ├── index.ts # Tool registration
│ │ ├── calculatorTool.ts # Sample calculator tool
│ │ └── timestampTool.ts # Sample timestamp tool
│ └── prompts/ # MCP prompts
│ ├── index.ts # Prompt registration
│ ├── greetingPrompt.ts # Sample greeting prompt
│ └── analyzeDataPrompt.ts # Sample data analysis prompt
└── dist/ # Compiled JavaScript output入门
先决条件
Node.js(v18 或更高版本)
npm 或 yarn
安装
克隆存储库并安装依赖项:
git clone https://github.com/yourusername/mcp-server-boilerplate.git
cd mcp-server-boilerplate
npm install环境变量
复制示例环境文件并根据需要修改:
cp .env.example .env可用的环境变量:
PORT:HTTP 服务器的端口(默认值:3000)NODE_ENV:环境模式(开发、生产)OAuth 设置(如果需要)
运行服务器
HTTP 服务器
构建并启动 HTTP 服务器:
npm run build
npm start对于自动重启的开发:
npm run dev该服务器将在http://localhost:3000/mcp (或 .env 文件中指定的端口)上可用。
标准输入输出模式
要在 stdio 模式下运行服务器(对于命令行工具):
npm run start:stdio对于自动重启的开发:
npm run dev:stdio资源
样板包括以下示例资源:
静态信息资源:
info://server提供有关服务器的基本信息
动态问候资源:
greeting://{name}使用提供的名称参数生成个性化问候语
要访问资源:
通过MCP协议
使用 MCP 客户端库
工具
样板包括以下示例工具:
计算器:执行基本的算术运算
参数:
operation:要执行的操作(加、减、乘、除)a:第一个数字b:第二个数字
时间戳:以各种格式提供当前时间
参数:
format:输出格式(iso,unix,可读)
提示
样板包括以下示例提示:
问候语:创建个性化的问候提示
参数:
name:问候的名字formal:是否使用正式的问候风格(可选)
分析数据:创建数据分析提示
参数:
data:要分析的数据format:数据格式(json、csv、text)instructions:附加分析说明(可选)
扩展服务器
添加资源
要添加新资源:
在
src/resources/中创建一个新文件(例如myResource.ts)实现资源处理程序
在
src/resources/index.ts中注册
例子:
// myResource.ts
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
export function myResource(server: McpServer): void {
server.resource('my-resource', 'my-resource://path', async uri => ({
contents: [
{
uri: uri.href,
text: 'My resource content',
},
],
}));
}
// Then add to resources/index.ts
import { myResource } from './myResource.js';
export function registerResources(server: McpServer): void {
// ...existing resources
myResource(server);
}添加工具
要添加新工具:
在
src/tools/中创建一个新文件(例如,myTool.ts)实现工具处理程序
在
src/tools/index.ts中注册
例子:
// myTool.ts
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
export function myTool(server: McpServer): void {
server.tool('my-tool', { param: z.string() }, async ({ param }) => ({
content: [
{
type: 'text',
text: `Processed: ${param}`,
},
],
}));
}
// Then add to tools/index.ts
import { myTool } from './myTool.js';
export function registerTools(server: McpServer): void {
// ...existing tools
myTool(server);
}添加提示
要添加新提示:
在
src/prompts/中创建一个新文件(例如myPrompt.ts)实现提示处理程序
在
src/prompts/index.ts中注册
例子:
// myPrompt.ts
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
export function myPrompt(server: McpServer): void {
server.prompt('my-prompt', { topic: z.string() }, ({ topic }) => ({
messages: [
{
role: 'user',
content: {
type: 'text',
text: `Please explain ${topic} in simple terms.`,
},
},
],
}));
}
// Then add to prompts/index.ts
import { myPrompt } from './myPrompt.js';
export function registerPrompts(server: McpServer): void {
// ...existing prompts
myPrompt(server);
}测试和调试
要测试您的 MCP 服务器,您可以使用:
MCP 检查器工具
MCP 客户端库
直接 HTTP 请求(用于调试)
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。
Available Tools
2 toolscalculateD
| Name | Required | Description | Default |
|---|---|---|---|
| operation | Yes | ||
| a | Yes | ||
| b | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
timestampD
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | iso |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
2 tool updates
- First observed
calculate - First observed
timestamp
TDQS
Scored across 2 tools
The two tools have clearly distinct purposes: 'calculate' suggests mathematical or computational operations, while 'timestamp' implies time-related functions. With no overlapping descriptions, there is no ambiguity between them.
Both tool names follow a consistent pattern of using single, descriptive nouns in lowercase. There are no deviations in style or convention across the set.
With only 2 tools, the server feels thin and under-scoped for a 'boilerplate' purpose, which typically implies a foundational or example set. This minimal count limits functionality and utility.
The server lacks descriptions, making it impossible to infer a clear domain or assess coverage. Without context, it appears severely incomplete, with no indication of what operations are supported or how they fit together.
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
The Mercado Pago MCP Server implements the Model Context Protocol to provide AI agents and LLMs with access to Mercado Pago's APIs and tools within compatible development environments. It acts as an intermediary that translates Mercado Pago resources into executable functions (tools) that AI applications can invoke to perform actions and automate flows. The server simplifies integration, enables using documentation to implement or improve code, and optimizes operations through natural language interactions without manual implementations.
An MCP server that provides an API to LLMs to manage their JumpCloud resources.
Related MCP Servers
- AlicenseBqualityDmaintenanceAn educational implementation of a Model Context Protocol server that demonstrates how to build a functional MCP server integrating with various LLM clients.2MIT
- FlicenseBqualityDmaintenanceA basic starter project for building Model Context Protocol (MCP) servers that enables standardized interactions between AI systems and various data sources through secure, controlled tool implementations.2-
- FlicenseNot gradedqualityDmaintenanceA starter project designed to quickly build and deploy Model Context Protocol (MCP) servers using the TypeScript SDK and Zod for schema validation. It features example implementations for tools and resources, providing a solid foundation for custom MCP development and integration.-
- FlicenseNot gradedqualityDmaintenanceA minimal Model Context Protocol (MCP) server demonstrating the implementation of tools, resources, and prompts. It serves as a starter template built with the Smithery SDK for developing custom integrations.-