OT

ollama-tlms-golang/05-make-your-mcp-server

Developer tools

이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기

11 stars 5 forks 품질 52 트렌드 8MIT

오늘 우리는 MCP 서버를 Go에서 만들고 Docker로 봉사하는 방법을 살펴볼 것입니다.

개요

오늘 우리는 MCP 서버를 Go에서 만들고 Docker로 봉사하는 방법을 살펴볼 것입니다. 필수품 : Model Context Protocol (MCP) 이해 MCP 서버를 작성하려면 몇 가지 공식 SDK가 있습니다. - TypeScript SDK - Python SDK - 코틀린 SDK 최근 몇 년 동안, 나는 Go에 대한 식욕을 개발했다, 그래서 나는 Go 구현이 있었다면 볼 주변을 보았다. 이 페이지에 https://github.com/punkpeye/awesome-mcp-servers?tab=readme-ov-file#frameworks, 나는 몇 가지를 발견, notably https://github.com/mark3labs/mcp-go, mcphost의 제작자에 의해 (나는 이전 블로그 게시물에서 토론 및 사용). mcp-go 프로젝트의 장점은 단순하고 미래 블로그 게시물에 매우 유용 할 MCP 클라이언트를 개발하기위한 도구를 제공합니다. MCP 서버의 모든 가능성을 자세히 설명하거나 구현하지 않습니다. 나는 단지 필수를 구현할 것이다 : - LLM에 대한 도구 목록 제공 - LLM이 그들에게 부각 할 때이 도구를 실행

개요(AI 번역)

소개

오늘 우리는 MCP 서버를 Go에서 만들고 Docker로 봉사하는 방법을 살펴볼 것입니다.

필수품 : Model Context Protocol (MCP) 이해

MCP 서버를 작성하려면 몇 가지 공식 SDK가 있습니다.

  • TypeScript SDK를
  • 파이썬 SDK
  • 코틀린 SDK

최근 몇 년 동안, 나는 Go에 대한 식욕을 개발했다, 그래서 나는 Go 구현이 있었다면 볼 주변을 보았다. 이 페이지에 https://github.com/punkpeye/awesome-mcp-servers?tab=readme-ov-file#frameworks, I found several, notably https://github.com/mark3labs/mcp-go, by the creator of [T2]] (이전 블로그 게시물에서 토론 및 사용).

mcp-go] 프로젝트의 장점은 단순하고 미래의 블로그 게시물에 매우 유용 할 MCP 클라이언트를 개발하기위한 도구를 제공합니다.

MCP Server 만들기

MCP 서버의 모든 가능성을 자세히 설명하거나 구현하지 않습니다. 나는 단지 필수를 구현할 것이다 :

  • LLM의 도구 목록 제공
  • LLM이 그(것)들을 호출할 때 이러한 도구를 실행

LLM을 사용할 때, 내가 할 수있는 것과 같은 한 가지가 있습니다 : 웹 사이트 링크를 제공하므로 정보를 찾을 수 있으므로, 나를 위해 요약을하십시오.

이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요.

README

원문 README의 일부입니다. 원문 보기.

Creating an MCP Server in Go and Serving it with Docker

Introduction

Today we’ll look at how to create an MCP server in Go and serve it with Docker.

Prerequisites: having read Understanding the Model Context Protocol (MCP)

To write an MCP server, there are several official SDKs:

In recent years, I’ve developed an appetite for Go, so I looked around to see if there was a Go implementation. On this page https://github.com/punkpeye/awesome-mcp-servers?tab=readme-ov-file#frameworks, I found several, notably https://github.com/mark3labs/mcp-go, by the creator of mcphost (which I discuss and use in the previous blog post).

The advantage of the mcp-go project is that it’s simple and also provides tools to develop an MCP client, which will be very useful for a future blog post.

Creating an MCP Server

I won’t detail or implement all the possibilities of an MCP server here. I’ll just implement the essentials:

  • Provide a list of tools for the LLM
  • Execute these tools when the LLM invokes them

When I use an LLM, there’s one thing I’d like to be able to do: give it a website link so it can find information there, make a summary for me, etc.

So I created an MCP server that calls the curl utility with a URL parameter and returns its content. But let’s look at the source code:

go.mod:

module mcp-curl

go 1.23.4

require github.com/mark3labs/mcp-go v0.8.2
require github.com/google/uuid v1.6.0

main.go:

package main

import (
	"context"
	"fmt"
	"os/exec"

	"github.com/mark3labs/mcp-go/mcp"
	"github.com/mark3labs/mcp-go/server"
)

func main() {
	// Create MCP server
	s := server.NewMCPServer(
		"mcp-curl",
		"1.0.0",
	)

	// Add a tool
	tool := mcp.NewTool("use_curl",
		mcp.WithDescription("fetch this webpage"),
		mcp.WithString("url",
			mcp.Required(),
			mcp.Description("url of the webpage to fetch"),
		),
	)

	// Add a tool handler
	s.AddTool(tool, curlHandler)

	fmt.Println("🚀 Server started")
	// Start the stdio server
	if err := server.ServeStdio(s); err != nil {
		fmt.Printf("😡 Server error: %v\n", err)
	}
	fmt.Println("👋 Server stopped")
}

func curlHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {

	url, ok := request.Params.Arguments["url"].(string)
	if !ok {
		return mcp.NewToolResultError("url must be a string"), nil
	}
	cmd := exec.Command("curl", "-s", url)
	output, err := cmd.Output()
	if err != nil {
		return mcp.NewToolResultError(err.Error()), nil
	}
	content := string(output)
GitHub에서 전체 README 보기

설치

docker run --rm -i mcp-curl
MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →

설정

{ "mcpServers": { "mcp-curl-with-docker" :{ "command": "docker", "args": [ "run", "--rm", "-i", "mcp-curl" ] } } }