Hello World MCP Server

by jageenshukla
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Manages environment configuration for the MCP server through .env files

  • Handles HTTP endpoints for server-sent events (SSE) and message communication in the MCP server

  • Used for version control and cloning the repository to set up the MCP server

你好,世界 MCP 服务器

欢迎来到Hello World MCP 服务器!本项目演示了如何使用模型上下文协议 (MCP) SDK 设置服务器。它包含用于处理服务器发送事件 (SSE) 和消息的工具、提示符和端点。


特征

  • MCP 集成:使用 MCP SDK 创建带有工具和提示的服务器。
  • Express Framework :处理 SSE 和消息通信的 HTTP 端点。
  • 环境配置:使用.env文件方便配置。
  • TypeScript 支持:完全类型化的代码库,可提供更好的开发人员体验。

先决条件

开始之前,请确保已安装以下软件:

  1. Node.js (v16 或更高版本)-点击此处下载
  2. npm (Node.js 附带)或yarn

入门

按照以下步骤设置并运行项目:

1.克隆存储库

如果还没有,请将存储库克隆到本地计算机:

git clone https://github.com/your-username/hello-world-mcp-server.git cd hello-world-mcp-server

2.安装依赖项

使用 npm 或 yarn 安装所需的依赖项:

npm install

或者

yarn install

3.配置环境变量

该项目使用.env文件来配置服务器的端口。提供了一个示例.env.example文件。

  1. .env.example文件复制到.env
    cp .env.example .env
  2. 打开.env文件并根据需要更新PORT变量。默认值为4000
    PORT=4000

4. 构建项目

将 TypeScript 代码编译为 JavaScript:

npm run build

这将在dist目录中生成编译的文件。

5.运行服务器

以生产模式启动服务器:

npm start

或者,对于具有实时重新加载的开发模式,请使用:

npm run dev

测试服务器

1. 使用 MCP 检查器

MCP 检查器是一款用于测试和检查 MCP 服务器的工具。您可以使用它来验证您的工具和提示是否已正确注册。

运行以下命令检查您的服务器:

npx @modelcontextprotocol/inspector ./dist/server.js

这将打开一个交互式界面,您可以在其中测试服务器中注册的工具和提示,如下所示。


项目结构

以下是项目结构的概述:

hello-world-mcp-server/ ├── src/ │ ├── server.ts # Main server entry point │ ├── modules/ │ │ ├── tools.ts # Registers MCP tools │ │ ├── prompts.ts # Registers MCP prompts │ │ └── transports.ts # Handles SSE and message endpoints ├── .env # Environment variables ├── .env.example # Example environment variables ├── package.json # Project metadata and scripts ├── tsconfig.json # TypeScript configuration └── README.md # Project documentation

故障排除

常见问题

  1. 端口已在使用中:如果您看到有关端口正在使用的错误,请更新.env文件中的PORT变量。
  2. TypeScript 错误:确保您已安装所有依赖项并使用正确的 Node.js 版本。

调试

使用以下命令调试服务器:

npm run dev

这将启动服务器并进行实时重新加载和详细日志。


贡献

欢迎贡献代码!欢迎随时提交 issue 或 PR。


执照

本项目遵循 ISC 许可证。详情请参阅许可证文件。

-
security - not tested
F
license - not found
-
quality - not tested

实现模型上下文协议 (MCP) SDK 的演示服务器,为服务器发送的事件和消息处理提供工具和端点。

  1. Features
    1. Prerequisites
      1. Getting Started
        1. 1. Clone the Repository
        2. 2. Install Dependencies
        3. 3. Configure Environment Variables
        4. 4. Build the Project
        5. 5. Run the Server
      2. Testing the Server
        1. 1. Using the MCP Inspector
      3. Project Structure
        1. Troubleshooting
          1. Common Issues
          2. Debugging
        2. Contributing
          1. License
            ID: 80jthm8z6d