模型协议服务器

一个基于Flask的简单MCP服务器,提供多种工具功能并通过Web GUI展示。

  • by thedcfix
  • HTML
  • 本地部署
  • 更新于
在 GitHub 查看 thedcfix/MCP-Server

使用说明

MCP服务器

基于Flask的web GUI的简单MCP(模型上下文协议)服务器

概述

这是一个简单的MCP服务器实现,通过基于web的GUI公开各种工具。该服务器包括几个演示不同功能的示例工具:

  • 计算:执行基本的数学运算(加、减、乘、除)
  • 文本分析器:分析文本并提供统计数据(字数、字符数等)
  • 时间戳:获取各种格式的当前时间戳
  • 字符串转换:转换字符串(大写、小写、反转、标题大小写)
  • 斐波那契:生成斐波那契数列

安装

  1. 克隆此存储库:
git clone https://github.com/thedcfix/MCP-Server.git
cd MCP-Server
  1. 安装依赖项:
pip install -r requirements.txt

用法

  1. 启动Flask服务器:
python app.py
  1. 打开您的网络浏览器并导航到:
http://localhost:5000
  1. GUI将显示:
    • 服务器信息和统计
    • 所有可用工具及其描述和参数的列表
    • 一个测试部分,您可以在其中使用自定义参数执行工具

API终点

服务器公开以下REST API终结点:

  • GET / -Web GUI界面
  • GET /api/tools -列出所有可用工具
  • GET /api/server-info -获取服务器信息
  • POST /api/execute -使用参数执行工具

API使用示例

# List all tools
curl http://localhost:5000/api/tools

# Execute the calculate tool
curl -X POST http://localhost:5000/api/execute \
  -H "Content-Type: application/json" \
  -d '{"tool_name": "calculate", "parameters": {"operation": "add", "a": 10, "b": 5}}'

# Analyze text
curl -X POST http://localhost:5000/api/execute \
  -H "Content-Type: application/json" \
  -d '{"tool_name": "text_analyzer", "parameters": {"text": "Hello world!"}}'

项目结构

MCP-Server/
├── app.py              # Flask web application
├── mcp_server.py       # MCP server implementation with tools
├── templates/
│   └── index.html      # Web GUI template
├── requirements.txt    # Python dependencies
└── README.md          # This file

添加新工具

要向MCP服务器添加新工具,请执行以下操作:

  1. 打开 mcp_server.py
  2. 添加一种新的方法来处理该工具(例如。, _my_tool)
  3. 在中注册该工具 _register_tools() 方法及其元数据
  4. 该工具将自动出现在web GUI中

许可证

MIT许可证