MCP ExplorerExplorer

Mcp Server Demo

@hchyueon a month ago
1 Apache-2.0
FreeCommunity
AI Systems
In order to integrate with Dify's MCP SSE / StreamableHTTP plugin, a simple mcp-server example built using the streamable_http transmission mode has been implemented to query the CPU utilization of a Linux server.

Overview

What is Mcp Server Demo

mcp-server-demo is a demonstration project designed to interface with Dify’s MCP SSE/StreamableHTTP plugin. It is built using the streamable_http transport mode and provides a simple functionality to query the CPU utilization of a Linux server.

Use cases

Use cases for mcp-server-demo include monitoring CPU performance in real-time, integrating with other monitoring tools, and validating the functionality of the MCP SSE/StreamableHTTP plugin in a development or testing environment.

How to use

To use mcp-server-demo, clone the repository from GitHub, set up a virtual environment, install the necessary dependencies, and run the server. Configuration for the MCP SSE/StreamableHTTP plugin must be done by providing the server’s IP address in a JSON format.

Key features

Key features of mcp-server-demo include: 1) Integration with Dify’s MCP SSE/StreamableHTTP plugin; 2) Ability to monitor Linux server CPU utilization; 3) Simple setup and execution process; 4) Support for Python 3.10, 3.11, and 3.12.

Where to use

mcp-server-demo can be used in various fields such as system monitoring, performance analysis, and server management, particularly in environments that utilize Dify’s MCP functionalities.

Content

mcp-server-demo

Overview

为了测试验证Dify的MCP功能,Dify上使用MCP SSE/StreamableHTTP插件,需要一个mcp server来对接验证。本项目采用streamable_http传输模式构建的的mcp-server示例,实现了查询linux服务器cpu利用的简单功能。
最终效果如下图所示
alt text

Get Started

如何安装MCP SSE/StreamableHTTP插件,这里不赘述

下载代码

git clone https://github.com/hchyue/mcp-server-demo.git
cd mcp-server-demo

运行环境

# Create a virtual environment and install dependencies
# 如何没有安装uv,可以执行下面这个命令,如果已经安装,可以跳过

# macOS
pip3 install uv --break-system-packages

# Linux(ubuntu)
pip3 install uv --break-system-packages

执行

# We support using Python 3.10, 3.11, 3.12
uv venv .mcpvenv --python=3.10

# Activate the virtual environment
# For macOS/Linux
source .mcpvenv/bin/activate

uv pip install psutil Flask
python mcp-server.py

MCP SSE/StreamableHTTP插件的授权配置

找到MCP SSE/StreamableHTTP插件的授权配置入口
alt text

填写如下的json,注意x.x.x.x是mcp-server.py所运行的server IP

{
    "linux_monitor": {
        "transport": "streamable_http",
        "url": "http://x.x.x.x:5000/mcp",
        "headers": {
            "X-Mcp-Protocol": "streamable_http",
            "X-Mcp-Version": "1.0",
            "Content-Type": "application/json"
        },
        "timeout": 30,
        "provider_name": "linux_monitor"
    }
}

alt text

验证

创建一个agent,增加“mcp_sse 获取MCP工具列表”和“mcp_sse 调用MCP工具”两个工具,然后输入“使用mcp工具获取cpu利用率”
alt text

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers