dentaku7_mcp_go_sdk

dentaku7_mcp_go_sdk

by dentaku7
A Go SDK for building MCP-compliant tools and servers, enabling integration with AI applications like Cursor IDE.

Model Communication Protocol SDK for Go

Overview

The Model Communication Protocol SDK for Go (MCP-Go SDK) is a Go-based SDK designed to build tools and servers that comply with the Model Communication Protocol (MCP). This SDK enables developers to create MCP-compliant tools that can be integrated with AI applications like Cursor IDE. It provides the necessary building blocks for implementing tools that can communicate effectively with AI systems.

Quick Start

To get started with the MCP-Go SDK, check out the example server in the servers/example directory. This example demonstrates a minimal implementation of an MCP tool that echoes back messages:

package main

import (
    "encoding/json"
    "mcp-go/server"
    "mcp-go/transport"
)

// EchoTool implements a simple echo tool
type EchoTool struct{}

func (t *EchoTool) Name() string {
    return "echo"
}

func (t *EchoTool) Description() string {
    return "A simple echo tool that returns the input message"
}

func (t *EchoTool) Schema() json.RawMessage {
    return json.RawMessage(`{
        "type": "object",
        "properties": {
            "message": {
                "type": "string",
                "description": "The message to echo back"
            }
        },
        "required": ["message"]
    }`)
}

func (t *EchoTool) Execute(params json.RawMessage) (interface{}, error) {
    var input struct {
        Message string `json:"message"`
    }
    if err := json.Unmarshal(params, &input); err != nil {
        return nil, err
    }

    return map[string]interface{}{
        "content": []map[string]interface{}{
            {
                "type": "text",
                "text": input.Message,
            },
        },
        "metadata": map[string]interface{}{
            "length": len(input.Message),
        },
    }, nil
}

func main() {
    // Create a new server with stdin/stdout transport
    srv := server.NewServer(transport.NewStdioTransport())

    // Register your tool
    if err := srv.RegisterTool(&EchoTool{}); err != nil {
        panic(err)
    }

    // Start the server
    if err := srv.Start(); err != nil {
        panic(err)
    }
}

Core Concepts

1. Tools

A Tool in MCP is a service that can be called by AI applications. Each tool must implement the mcp.Tool interface:

type Tool interface {
    // Name returns the unique identifier for this tool
    Name() string

    // Description returns a human-readable description
    Description() string

    // Schema returns the JSON schema for the tool's parameters
    Schema() json.RawMessage

    // Execute runs the tool with the given parameters
    Execute(params json.RawMessage) (interface{}, error)
}

2. Response Format

Tools should return responses in the MCP format:

{
    "content": [\
        {\
            "type": "text",\
            "text": "Your response text"\
        }\
    ],
    "metadata": {
        // Optional metadata about the response
    }
}

3. Transport Layer

The SDK provides a flexible transport layer through the Transport interface:

type Transport interface {
    Send(data interface{}) error
    Receive() ([]byte, error)
    Close() error
}

By default, the SDK includes a stdio transport (transport.NewStdioTransport()) for command-line tools.

4. Configuration

To use your MCP tool with Cursor IDE, create a .cursor/mcp.json in your project root:

{
    "mcpServers": {
        "mytool": {
            "command": "mytool",
            "args": [],
            "env": {}
        }
    }
}

Contributing

  1. Fork the repository.
  2. Create a feature branch.
  3. Add tests for new functionality.
  4. Submit a pull request.

Please ensure your code:
- Follows Go best practices.
- Includes appropriate documentation.
- Has test coverage.
- Handles errors appropriately.

About

The MCP Server SDK in Go is a project developed by dentaku7 to create MCP-compliant tools and servers. It is licensed under the MIT license.

Resources

Stats

  • Stars: 2
  • Watchers: 1
  • Forks: 0

Languages

Features & Capabilities

Categories
mcp_server model_context_protocol go sdk ai_integration cursor_ide transport_layer

Implementation Details

Stats

0 Views
2 GitHub Stars

Repository Info

dentaku7 Organization

Similar MCP Servers

continuedev_continue by continuedev
25049
21423
9300