MCP cover image

Ce SDK fournit une implémentation GO du protocole de contrôle de la machine (MCP), permettant une communication bidirectionnelle entre les clients et les serveurs pour l'exécution des outils, l'accès aux ressources et la manipulation rapide. Basé Onhttps: //github.com/modelcontextprotocolsdk

1

Github Watches

1

Github Forks

1

Github Stars

MCP Go SDK

This SDK provides a Go implementation of the Model Context Protocol (MCP), enabling bidirectional communication between clients and servers for tool execution, resource access, and prompt handling.

Features

  • Transport Layer

    • Multiple transport options (stdio, SSE, WebSocket)
    • Bidirectional communication
    • Configurable endpoints and settings
  • Server Implementation

    • Tool registration and execution
    • Resource pattern matching and access
    • Prompt template rendering
    • Session management
    • Reflection-based handler invocation
  • Core Protocol Types

    • JSON-RPC message handling
    • MCP-specific types (tools, resources, prompts)
    • Capabilities and initialization

Installation

go get github.com/SetiabudiResearch/mcp-go-sdk

Quick Start

Here's a simple example of creating an MCP server:

package main

import (
    "context"
    "log"
    "github.com/SetiabudiResearch/mcp-go-sdk/pkg/mcp/server"
    "github.com/SetiabudiResearch/mcp-go-sdk/pkg/mcp/transport"
)

func main() {
    // Create a new server
    srv := server.NewServer("Example Server")

    // Add a tool
    srv.AddTool("greet", func(name string) string {
        return "Hello, " + name + "!"
    }, "Greet a person")

    // Create a session
    session := server.NewSession(context.Background(), srv)

    // Create and start a transport
    t := transport.NewStdioTransport(session)
    if err := t.Start(); err != nil {
        log.Fatal(err)
    }
}

Usage Guide

Creating a Server

// Create a new server with a name
srv := server.NewServer("My Server")

// Optionally configure server capabilities
srv.WithCapabilities(protocol.ServerCapabilities{
    SupportsAsync: true,
})

Adding Tools

// Add a synchronous tool
srv.AddTool("myTool", func(arg1 string, arg2 int) (string, error) {
    return fmt.Sprintf("Processed %s with %d", arg1, arg2), nil
}, "Tool description")

// Add an asynchronous tool
srv.AddAsyncTool("longRunningTool", func(params string) error {
    // Long-running operation
    return nil
}, "Async tool description")

Adding Resources

// Add a resource with pattern matching
srv.AddResource("files/{path}", func(path string) ([]byte, error) {
    return ioutil.ReadFile(path)
}, "Access files")

// Resource patterns support multiple parameters
srv.AddResource("api/{version}/{endpoint}", func(version, endpoint string) (interface{}, error) {
    return callAPI(version, endpoint)
}, "API access")

Adding Prompts

// Add a simple text prompt
srv.AddPrompt("confirm", func(action string) string {
    return fmt.Sprintf("Are you sure you want to %s?", action)
}, "Confirmation prompt")

// Add a multi-message prompt
srv.AddPrompt("chat", func(context string) []protocol.PromptMessage {
    return []protocol.PromptMessage{
        {
            Role: protocol.RoleAssistant,
            Content: protocol.TextContent{
                Type: "text",
                Text: "How can I help you with " + context + "?",
            },
        },
    }
}, "Chat prompt")

Transport Configuration

// Create a session
session := server.NewSession(context.Background(), srv)

// Stdio transport (for CLI applications)
t := transport.NewStdioTransport(session)

// WebSocket transport (for web applications)
t := transport.NewWebSocketTransport(session, transport.WithAddress(":8080"))

// Server-Sent Events transport (for web browsers)
t := transport.NewSSETransport(session, transport.WithAddress(":8080"))

// Start the transport
if err := t.Start(); err != nil {
    log.Fatal(err)
}

Example Applications

See the examples directory for complete example applications:

  • File Server: A complete file server implementation using MCP
  • Calculator: A simple calculator service
  • Chat Bot: An example chat bot using prompts

Contributing

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

License

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

相关推荐

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

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

  • 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

  • https://jgadvisorycpa.com
  • This GPT assists in finding a top-rated business CPA - local or virtual. We account for their qualifications, experience, testimonials and reviews. Business operators provide a short description of your business, services wanted, and city or state.

  • 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.

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

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

  • apappascs
  • Découvrez la collection la plus complète et la plus à jour de serveurs MCP sur le marché. Ce référentiel sert de centre centralisé, offrant un vaste catalogue de serveurs MCP open-source et propriétaires, avec des fonctionnalités, des liens de documentation et des contributeurs.

  • modelcontextprotocol
  • Serveurs de protocole de contexte modèle

  • Mintplex-Labs
  • L'application tout-en-un desktop et Docker AI avec chiffon intégré, agents AI, constructeur d'agent sans code, compatibilité MCP, etc.

  • ShrimpingIt
  • Manipulation basée sur Micropython I2C de l'exposition GPIO de la série MCP, dérivée d'Adafruit_MCP230XX

  • OffchainLabs
  • Aller la mise en œuvre de la preuve de la participation Ethereum

  • n8n-io
  • Plateforme d'automatisation de workflow à code équitable avec des capacités d'IA natives. Combinez le bâtiment visuel avec du code personnalisé, de l'auto-hôte ou du cloud, 400+ intégrations.

  • huahuayu
  • Une passerelle API unifiée pour intégrer plusieurs API d'explorateur de blockchain de type étherscan avec la prise en charge du protocole de contexte modèle (MCP) pour les assistants d'IA.

    Reviews

    1 (1)
    Avatar
    user_1DT7flKR
    2025-04-16

    As a devoted user of the mcp-go-sdk, I highly recommend it for anyone working with Go. Created by SetiabudiResearch, this SDK simplifies interactions with MCP services and enhances development efficiency. The comprehensive documentation and clear welcome message make the onboarding process smooth and straightforward. Check it out at https://github.com/SetiabudiResearch/mcp-go-sdk.