mcp4go
MCP Servermcp4gopublic

mcp4go

A comprehensive Go SDK for the Model Context Protocol (MCP) - simplifying AI application development by abstracting away protocol complexities.

Repository Info

5
Stars
2
Forks
5
Watchers
0
Issues
Go
Language
MIT License
License

About This Server

A comprehensive Go SDK for the Model Context Protocol (MCP) - simplifying AI application development by abstracting away protocol complexities.

Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.

Documentation

Go Test Lint codeql GoDoc CodeCover Go Report Card License Release

MCP4Go

MCP4Go is a Go implementation of the Model Context Protocol (MCP), designed to simplify the development of AI applications by abstracting away protocol complexities.

Features

  • Complete MCP protocol implementation in pure Go
  • High-level abstractions for common MCP resources
  • Pluggable architecture for custom extensions
  • Comprehensive documentation and examples
  • Production-ready with robust error handling

Installation

MCP4Go requires Go 1.18 or later. Install it using Go modules:

go get github.com/mcp4go/mcp4go

Getting Started

To get started with MCP4Go, import the package in your Go application:

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/mcp4go/mcp4go/pkg/logger"
	"github.com/mcp4go/mcp4go/protocol"
	"github.com/mcp4go/mcp4go/server"
	"github.com/mcp4go/mcp4go/server/iface"
	"github.com/mcp4go/mcp4go/server/transport"

	_ "time/tzdata" // Load all time zones
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	_logger := logger.DefaultLog

	// Listen for interrupt signals for graceful exit
	signalCh := make(chan os.Signal, 1)
	signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
	go func() {
		<-signalCh
		_logger.Logf(ctx, logger.LevelWarn, "Received shutdown signal")
		cancel()
	}()

	type timeRequest struct {
		TimeZone string `json:"time_zone,omitempty" description:"time zone default is Asia/Shanghai"`
	}

	// Create standard input/output transport layer
	stdioTransport := transport.NewStdioTransport()
	// Create MCP server and configure options
	srv, cleanup, err := server.NewServer(
		stdioTransport,
		server.WithServerInfo(protocol.Implementation{
			Name:    "time-mcp",
			Version: "0.1.0",
		}),
		server.WithInstructions("Welcome to Time MCP! This server provides Time tools."),
		server.WithToolBuilder(iface.NewFunctionalToolsBuilder(
			iface.NewFunctionalToolWrapper(
				"time",
				"get current time",
				func(ctx context.Context, args timeRequest) ([]protocol.Content, error) {
					if args.TimeZone == "" {
						args.TimeZone = "Asia/Shanghai"
					}

					getTimezoneTime := func(_ context.Context, timeZone string) time.Time {
						if timeZone == "" {
							timeZone = "Asia/Shanghai"
						}
						loc, err := time.LoadLocation(timeZone)
						if err != nil {
							return time.Now()
						}
						return time.Now().In(loc)
					}

					currentTime := getTimezoneTime(ctx, args.TimeZone)

					return []protocol.Content{
						protocol.NewTextContent(fmt.Sprintf("current time is %s", currentTime), nil),
					}, nil
				}),
		)),
	)
	if err != nil {
		log.Printf("Failed to create server: %v\n", err)
		return
	}
	defer cleanup()

	// Start the server
	_logger.Logf(ctx, logger.LevelWarn, "Starting Time MCP server")
	if err := srv.Run(ctx); err != nil {
		_logger.Logf(ctx, logger.LevelError, "Server error: %v", err)
		return
	}

	_logger.Logf(ctx, logger.LevelWarn, "Server shutdown complete")
}

Protocol Implementation

MCP4Go provides a complete implementation of the Model Context Protocol with support for:

  • JSON-RPC communication
  • Resource lifecycle management
  • Prompt engineering
  • Tool definitions and invocations
  • Sampling parameters
  • Logging and diagnostics

License

This project is licensed under the MIT License

Contributing

Contributions are welcome! Please see our Contributing Guide for more information.

Quick Start

1

Clone the repository

git clone https://github.com/mcp4go/mcp4go
2

Install dependencies

cd mcp4go
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

Ownermcp4go
Repomcp4go
LanguageGo
LicenseMIT License
Last fetched8/10/2025

Recommended MCP Servers

💬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
🔗

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
🕷️

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation