Back to MCP Catalog

Golang Framework MCP Server

Developer ToolsGo
A lightweight framework for building Model Context Protocol servers in Go
Available Tools

hello

A simple greeting tool that takes a name parameter and returns a greeting message

The Golang MCP Framework provides a simple and efficient way to create Model Context Protocol servers using Go. It enables developers to build custom tools and integrations that can be used by AI assistants like Claude and other MCP-compatible clients. With just a few lines of Go code, you can create powerful server implementations that extend AI capabilities through custom APIs.

Introduction

The Golang MCP Framework allows you to build Model Context Protocol (MCP) servers with minimal Go code. MCP servers enable AI assistants to access external tools, data, and services through a standardized protocol.

Installation

To get started with the Golang MCP Framework, you'll need to have Go installed on your system. Then you can install the package using:

go get github.com/metoro-io/mcp-golang

Basic Usage

Here's a simple example of how to create an MCP server:

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	mcp "github.com/metoro-io/mcp-golang"
)

func main() {
	// Create a new MCP server
	server := mcp.NewServer()

	// Register a handler for a custom tool
	server.RegisterPromptHandler("hello", func(ctx context.Context, req *mcp.PromptRequest) (*mcp.PromptResponse, error) {
		name := req.Args["name"]
		return &mcp.PromptResponse{
			Content: fmt.Sprintf("Hello, %s!", name),
		}, nil
	})

	// Start the server
	log.Println("Starting MCP server on :8080")
	if err := http.ListenAndServe(":8080", server); err != nil {
		log.Fatalf("Failed to start server: %v", err)
	}
}

Advanced Features

Server Instructions

You can provide instructions for AI assistants about how to use your tools:

server := mcp.NewServerWithInstructions("This server provides tools for greeting users.")

Resource Handlers

In addition to prompt handlers, you can register resource handlers to serve files and other resources:

server.RegisterResourceHandler("get_image", func(ctx context.Context, req *mcp.ResourceRequest) (*mcp.ResourceResponse, error) {
	// Return an image or other resource
	return &mcp.ResourceResponse{
		ContentType: "image/png",
		Data:        imageData,
	}, nil
})

Client Implementation

The framework also includes a client for connecting to MCP servers:

client := mcp.NewClient("http://localhost:8080")
resp, err := client.SendPrompt(context.Background(), "hello", map[string]string{"name": "World"})
if err != nil {
	log.Fatalf("Error: %v", err)
}
fmt.Println(resp.Content)

HTTP Transport

For more control over HTTP connections, you can use the transport package:

import "github.com/metoro-io/mcp-golang/transport"

httpTransport := transport.NewHTTPClientTransport("http://localhost:8080")
client := mcp.NewClientWithTransport(httpTransport)

Integration with AI Assistants

To connect your MCP server to an AI assistant like Claude, you'll need to configure the assistant to use your server. The exact configuration depends on the assistant you're using, but typically involves specifying the server URL and any authentication requirements.

Examples

The repository includes several examples in the examples directory that demonstrate different use cases and features of the framework. These examples are a great way to learn how to build more complex MCP servers.

For more detailed documentation, visit https://mcpgolang.com.

Related MCPs

Apple Shortcuts
Developer ToolsJavaScript

Control Apple Shortcuts automations from AI assistants

Clojars Dependency Lookup
Developer ToolsJavaScript

Fetch dependency information from Clojars, the Clojure community's artifact repository

Simple Timeserver
Developer ToolsPython

Provides Claude with current time and timezone information

About Model Context Protocol

Model Context Protocol (MCP) allows AI models to access external tools and services, extending their capabilities beyond their training data.

Generate Cursor Documentation

Save time on coding by generating custom documentation and prompts for Cursor IDE.