Skip to main content
Glama

Hello World MCP Server

by jageenshukla

你好,世界 MCP 服务器

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

该项目是博客文章《 构建 TypeScript MCP 服务器:集成现有服务的指南》的一部分。访问该博客,了解更多关于该项目背后的概念和实现细节。


特征

  • 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


项目结构

以下是项目结构的概述:

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。


执照

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

-
security - not tested
A
license - permissive license
-
quality - not tested

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

  1. 特征
    1. 先决条件
      1. 入门
        1. 1.克隆存储库
        2. 2.安装依赖项
        3. 3.配置环境变量
        4. 构建项目
        5. 5.运行服务器
      2. 测试服务器
        1. 使用 MCP 检查器
      3. 项目结构
        1. 故障排除
          1. 常见问题
          2. 调试
        2. 相关项目
          1. 贡献
            1. 执照

              Related MCP Servers

              • A
                security
                A
                license
                A
                quality
                A beginner-friendly Model Context Protocol (MCP) server that helps users understand MCP concepts, provides interactive examples, and lists available MCP servers. This server is designed to be a helpful companion for developers working with MCP. Also comes with a huge list of servers you can install.
                Last updated -
                3
                9
                36
                JavaScript
                Apache 2.0
              • -
                security
                A
                license
                -
                quality
                MCP Server simplifies the implementation of the Model Context Protocol by providing a user-friendly API to create custom tools and manage server workflows efficiently.
                Last updated -
                4
                3
                TypeScript
                MIT License
              • -
                security
                A
                license
                -
                quality
                MCP Server provides a simpler API to interact with the Model Context Protocol by allowing users to define custom tools and services to streamline workflows and processes.
                Last updated -
                13
                2
                TypeScript
                MIT License
              • -
                security
                -
                license
                -
                quality
                A specialized server that helps users create new Model Context Protocol (MCP) servers by providing tools and templates for scaffolding projects with various capabilities.
                Last updated -
                1
                TypeScript

              View all related MCP servers

              MCP directory API

              We provide all the information about MCP servers via our MCP API.

              curl -X GET 'https://glama.ai/api/mcp/v1/servers/jageenshukla/hello-world-mcp-server'

              If you have feedback or need assistance with the MCP directory API, please join our Discord server