Cover image
Try Now
2025-03-21

具有计算器和问候功能的MCP服务器的实现

3 years

Works with Finder

1

Github Watches

1

Github Forks

1

Github Stars

MCP Calculator

A Go implementation of a Model Context Protocol (MCP) server with calculator and greeting functionality. This implementation follows the official MCP specification.

Features

  • Full JSON-RPC 2.0 implementation
  • MCP protocol support
  • Tool registration and execution
  • Resource handling
  • Server capability negotiation
  • Error handling according to spec

Project Structure

mcpcalculator/
├── mcp/
│   └── protocol/
│       ├── types.go    # Protocol types and structures
│       ├── server.go   # MCP server implementation
│       └── client.go   # MCP client implementation
├── main.go            # Example usage
├── go.mod             # Go module file
└── README.md          # Documentation

Requirements

  • Go 1.21 or higher

Installation

git clone https://github.com/akhidasTech/mcpcalculator.git
cd mcpcalculator
go mod download

Usage

Starting the Server

go run main.go

The server will start on port 8080.

Making Requests

Tools and resources follow the JSON-RPC 2.0 specification:

Add Tool

curl -X POST http://localhost:8080 \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "add",
    "params": {"a": 5, "b": 3}
  }'

Greeting Resource

curl -X POST http://localhost:8080 \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "greeting",
    "params": {"name": "John"}
  }'

Response Format

All responses follow the JSON-RPC 2.0 format:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": <result_value>
}

Or for errors:

{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": <error_code>,
        "message": "error message",
        "data": <additional_data>
    }
}

Protocol Implementation

This implementation follows the Model Context Protocol specification:

  1. JSON-RPC 2.0: All communication uses the JSON-RPC 2.0 protocol
  2. Capabilities: Server advertises its capabilities during initialization
  3. Tools: Implements the tool registration and execution protocol
  4. Resources: Implements the resource access protocol
  5. Error Handling: Uses standard error codes and formats

Security

This implementation follows MCP security guidelines:

  1. User Consent: Tools and resources require explicit invocation
  2. Data Privacy: No data is shared without explicit requests
  3. Tool Safety: Tool execution is controlled and validated
  4. Error Handling: Proper error reporting and handling

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Callycode Limited
  • A geek-themed horoscope generator blending Bitcoin prices, tech jargon, and astrological whimsy.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Khalid kalib
  • Write professional emails

  • Beniyam Berhanu
  • Therapist adept at identifying core issues and offering practical advice with images.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • deemkeen
  • 用电源组合控制您的MBOT2:MQTT+MCP+LLM

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

    Reviews

    2 (1)
    Avatar
    user_Ayaxq7Q1
    2025-04-15

    As a devoted user of Alpaca MCP Server, I can confidently say it's an outstanding tool for managing multiple connections seamlessly. The intuitive interface and robust performance make it a top choice for anyone in need of reliable MCP server management. Highly recommend checking it out! You can learn more about it here: https://mcp.so/server/miguelyad26_alpaca-mcp-server/MCP-Mirror.