MCP Demo Server

MCP Demo Server

A stateless HTTP streaming MCP server built with Express that provides tools to read resource files (widgetResource.md and pageResource.md) and demonstrates the HTTP Streaming Transport protocol implementation.

Category
Visit Server

README

MCP Demo Server

一个基于 Model Context Protocol (MCP) 和 Express 的纯 HTTP Streaming 无状态服务器。

📚 文档

特性

  • 完全无状态 - 每个请求独立处理
  • HTTP Streaming - 基于标准 HTTP POST 的流式传输
  • 易于扩展 - 无需会话管理,可水平扩展
  • 简单部署 - 适合无服务器环境(Lambda、Cloud Functions)
  • ✅ 两个内置工具:
    • read_widget_resource: 读取 widgetResource.md 文件
    • read_page_resource: 读取 pageResource.md 文件

安装

npm install

运行

# 生产模式
npm start

# 开发模式(支持热重载)
npm run dev

# 使用 MCP Inspector 测试
npm run test

服务器默认运行在 http://localhost:3000

测试和调试

使用 HTTP Streaming 测试客户端(推荐)

# 首先启动服务器
npm start

# 在另一个终端运行测试客户端
npm run test-streaming

测试客户端会:

  1. 列出所有可用工具
  2. 调用 read_widget_resource 工具
  3. 调用 read_page_resource 工具

使用 curl 测试

# 列出可用工具
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'

# 调用 read_widget_resource 工具
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"read_widget_resource","arguments":{}}}'

# 检查服务器状态
curl http://localhost:3000/health

# 获取服务器信息
curl http://localhost:3000/

API 端点

HTTP Streaming Transport

1. MCP 端点

  • 路径: /mcp
  • 方法: POST
  • 描述: HTTP streaming 端点,处理 MCP JSON-RPC 请求
  • 特点: 完全无状态,每个请求独立处理
  • 描述: 接收来自客户端的消息(由 SSE transport 使用)

其他端点

3. 健康检查

  • 路径: /health
  • 方法: GET
  • 描述: 检查服务器状态

2. 健康检查

  • 路径: /health
  • 方法: GET
  • 描述: 检查服务器状态

3. 根路径

  • 路径: /
  • 方法: GET
  • 描述: 获取服务器信息和可用工具列表

可用工具

read_widget_resource

读取 src/resources/widgetResource.md 文件的内容。

输入: 无需参数

输出: 文件内容的文本

示例:

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"read_widget_resource","arguments":{}}}'

read_page_resource

读取 src/resources/pageResource.md 文件的内容。

输入: 无需参数

输出: 文件内容的文本

示例:

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"read_page_resource","arguments":{}}}'

使用示例

检查服务器健康状态

curl http://localhost:3000/health

获取服务器信息

curl http://localhost:3000/

MCP 客户端集成

要连接到此 MCP 服务器,你的 MCP 客户端需要:

  1. 发送 HTTP POST 请求到 /mcp 端点
  2. 使用 JSON-RPC 2.0 格式
  3. 通过 HTTP 响应接收结果

示例 MCP 客户端配置:

{
  "mcpServers": {
    "mcp-demo": {
      "transport": {
        "type": "http-streaming",
        "url": "http://localhost:3000/mcp"
      }
    }
  }
}

使用 MCP SDK:

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';

const client = new Client({
  name: 'my-client',
  version: '1.0.0',
});

const transport = new StreamableHTTPClientTransport(
  new URL('http://localhost:3000/mcp')
);

await client.connect(transport);

// 列出工具
const tools = await client.listTools();

// 调用工具
const result = await client.callTool({
  name: 'read_widget_resource',
  arguments: {},
});

技术栈

  • @modelcontextprotocol/sdk: MCP 协议实现
  • Express: Web 框架
  • CORS: 跨域资源共享支持
  • Node.js: ES Modules

项目结构

mcp-demo/
├── src/
│   ├── index.js                 # 主服务器文件
│   └── resources/
│       ├── widgetResource.md    # Widget 资源文件
│       └── pageResource.md      # Page 资源文件
├── package.json
├── README.md
└── LICENSE

环境变量

  • PORT: 服务器端口(默认: 3000)
PORT=8080 npm start

开发

服务器使用 ES Modules,需要 Node.js 14.0 或更高版本。

在开发模式下,可以使用 --watch 标志实现自动重启:

npm run dev

许可证

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured