Skip to content

sunpx3/mcp-calculator_new

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCP Sample Project | MCP 示例项目

A powerful interface for extending AI capabilities through remote control, calculations, email operations, knowledge search, and more.

一个强大的接口,用于通过远程控制、计算、邮件操作、知识搜索等方式扩展AI能力。

Overview | 概述

MCP (Model Context Protocol) is a protocol that allows servers to expose tools that can be invoked by language models. Tools enable models to interact with external systems, such as querying databases, calling APIs, or performing computations. Each tool is uniquely identified by a name and includes metadata describing its schema.

MCP(模型上下文协议)是一个允许服务器向语言模型暴露可调用工具的协议。这些工具使模型能够与外部系统交互,例如查询数据库、调用API或执行计算。每个工具都由一个唯一的名称标识,并包含描述其模式的元数据。

Features | 特性

  • 🔌 Bidirectional communication between AI and external tools | AI与外部工具之间的双向通信
  • 🔄 Automatic reconnection with exponential backoff | 具有指数退避的自动重连机制
  • 📊 Real-time data streaming | 实时数据流传输
  • 🛠️ Easy-to-use tool creation interface | 简单易用的工具创建接口
  • 🔒 Secure WebSocket communication | 安全的WebSocket通信

开始说明

  • 因为原项目是调用的环境变量来获取 MCP_ENDPOINT地址,但不同系统之间环境是有差异的,就容易导致找不到这个变量连接不到MCP服务,所以改为了配置文件获取, 修改config/mcp_config.json里面MCP_ENDPOINT值 为自己的小智MCP地址就可以直接执行 python mcp_pipe.py calculator.py 服务就启动起来了。所以本fork只是修改了获取mcp 地址的代码,改为配置文件获取,供对环境不熟悉的朋友使用。

Quick Start | 快速开始

  1. Install dependencies | 安装依赖:
pip install -r requirements.txt
  1. Run the calculator example | 运行计算器示例:
python mcp_pipe.py calculator.py

Project Structure | 项目结构

  • mcp_pipe.py: Main communication pipe that handles WebSocket connections and process management | 处理WebSocket连接和进程管理的主通信管道
  • calculator.py: Example MCP tool implementation for mathematical calculations | 用于数学计算的MCP工具示例实现
  • requirements.txt: Project dependencies | 项目依赖

Creating Your Own MCP Tools | 创建自己的MCP工具

Here's a simple example of creating an MCP tool | 以下是一个创建MCP工具的简单示例:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("YourToolName")

@mcp.tool()
def your_tool(parameter: str) -> dict:
    """Tool description here"""
    # Your implementation
    return {"success": True, "result": result}

if __name__ == "__main__":
    mcp.run(transport="stdio")

Use Cases | 使用场景

  • Mathematical calculations | 数学计算
  • Email operations | 邮件操作
  • Knowledge base search | 知识库搜索
  • Remote device control | 远程设备控制
  • Data processing | 数据处理
  • Custom tool integration | 自定义工具集成

Requirements | 环境要求

  • Python 3.7+
  • websockets>=11.0.3
  • python-dotenv>=1.0.0
  • mcp>=1.8.1
  • pydantic>=2.11.4

About

Xiaozhi MCP sample program calculator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%