MCP cover image

Golang MCP服务器

1

Github Watches

0

Github Forks

0

Github Stars

Model Context Protocol (MCP) Implementation in Go

This repository contains a Go implementation of the Model Context Protocol (MCP), a JSON-RPC based protocol for interaction between clients and servers in LLM-powered applications.

Contents

  • mcp/schema.go: Go struct definitions for the MCP schema, translated from the TypeScript schema
  • mcp/client.go: A client implementation for interacting with MCP servers
  • examples/mcp_client_example.go: A simple example showing how to use the client

MCP Overview

The Model Context Protocol (MCP) enables communication between model "hosts" (e.g., LLM clients or systems that interface with LLMs) and "servers" (systems that provide contextual information, tools, prompts, or resources to enhance LLM capabilities).

Key features of MCP include:

  • Resources: Files, documents, and other data that a host can read
  • Tools: Functions that a host can call on behalf of a model
  • Prompts: Templates or pre-defined message sequences a host can use
  • Roots: Filesystem or data roots that a server can operate on

Getting Started

Prerequisites

  • Go 1.18 or later

Running the Example

# Set the MCP server URL (optional, defaults to http://localhost:3000/jsonrpc)
export MCP_SERVER_URL=http://your-mcp-server/jsonrpc

# Run the example
go run examples/mcp_client_example.go

Using the MCP Client

import (
    "fmt"
    
    "path/to/mcp"
)

func main() {
    // Create a new client
    client := mcp.NewClient("http://your-mcp-server/jsonrpc")
    
    // Initialize the client
    clientInfo := mcp.Implementation{
        Name:    "My MCP Client",
        Version: "1.0.0",
    }
    
    capabilities := mcp.ClientCapabilities{
        // Specify the capabilities your client supports
    }
    
    err := client.Initialize(clientInfo, capabilities)
    if err != nil {
        // Handle error
    }
    
    // Now you can use various client methods:
    
    // List resources
    resources, err := client.ListResources("")
    
    // Read a resource
    resource, err := client.ReadResource("resource-uri")
    
    // Call a tool
    result, err := client.CallTool("tool-name", map[string]interface{}{
        "argument1": "value1",
        "argument2": 123,
    })
    
    // Get a prompt
    prompt, err := client.GetPrompt("prompt-name", map[string]string{
        "argName": "argValue",
    })
}

Implementation Details

Schema

The Go schema definitions in mcp/schema.go provide type-safe structures for MCP messages. This includes:

  • JSON-RPC protocol structures
  • Resource, Prompt, and Tool definitions
  • Content structures for text, images, and embedded resources
  • Helper functions for handling polymorphic types via json.RawMessage

Client

The client implementation in mcp/client.go provides methods for:

  • Initializing connections to MCP servers
  • Sending requests and handling responses
  • Converting Go structs to JSON-RPC messages
  • Helper methods for common MCP operations

Contributing

Contributions are welcome! Here are some ways you can contribute:

  • Implement a server
  • Add WebSocket support to the client
  • Improve error handling
  • Add tests
  • Document additional use cases

License

This project is licensed under the MIT License - see the LICENSE file for details.

References

相关推荐

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

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

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

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

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

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

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

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

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

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

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • modelcontextprotocol
  • 模型上下文协议服务器

  • n8n-io
  • 具有本机AI功能的公平代码工作流程自动化平台。将视觉构建与自定义代码,自宿主或云相结合,400+集成。

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

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

  • metorial
  • 数百个MCP服务器的容器化版本📡📡

  • open-webui
  • 用户友好的AI接口(支持Ollama,OpenAi API,...)

    Reviews

    5 (1)
    Avatar
    user_3wm64cR5
    2025-04-16

    Superset MCP Integration by aptro is a game-changer for data analytics and visualization. It seamlessly integrates Superset's powerful tools with the MCP ecosystem, providing a smoother and more efficient workflow. The setup is straightforward, and the added functionalities significantly enhance productivity. Highly recommended for anyone looking to streamline their data processes! Check it out here: https://mcp.so/server/superset-mcp/aptro