
riza-io/mcp-go
Developer tools이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기
Go에서 Model Context Protocol (MCP) 서버 구축
개요
Model Context Protocol (MCP)의 Go 구현은 LLM 표면과 통합하기위한 클라이언트 및 서버 기능을 제공합니다. Model Context Protocol은 LLM의 표준 방식으로 LLM에 대한 컨텍스트를 제공 할 수 있으며 실제 LLM 상호 작용에서 컨텍스트를 제공하는 데 대한 우려를 분리합니다. 이 Go SDK는 전체 MCP 사양을 구현하여 쉽게 만들기: - MCP 서버에 연결할 수있는 MCP 클라이언트를 구축 - 리소스, 프롬프트 및 도구를 노출 MCP 서버를 생성 - stdio 및 SSE와 같은 표준 운송을 사용하여 (곧) - 모든 MCP 프로토콜 메시지 및 라이프 사이클 이벤트를 처리 이 모든 것을 연습과 같은 것? 다음은 io의 내용을 노출하는 예 서버입니다. 자원으로 FS. 이 예제를 컴파일 할 수 있으며 Claude Desktop (또는 다른 MCP 클라이언트)까지 와이어 할 수 있습니다. - 모형 Context 의정서 문서 - MCP 명세 - 예 서버 기본 프로토콜의 대다수가 구현됩니다.
개요(AI 번역)
MCP 이동 SDK
Model Context Protocol (MCP)의 Go 구현은 LLM 표면과 통합하기위한 클라이언트 및 서버 기능을 제공합니다.
개요
Model Context Protocol은 LLM의 표준 방식으로 LLM에 대한 컨텍스트를 제공 할 수 있으며 실제 LLM 상호 작용에서 컨텍스트를 제공하는 데 대한 우려를 분리합니다. 이 Go SDK는 전체 MCP 사양을 구현하여 쉽게 만들기:
- MCP 서버에 연결할 수 있는 MCP 클라이언트 구축
- 리소스, 프롬프트 및 도구를 노출하는 MCP 서버를 만듭니다.
- stdio 및 SSE와 같은 표준 운송을 사용하십시오 (곧 도착)
- 모든 MCP 프로토콜 메시지 및 Lifecycle 이벤트 처리
작은 예
이 모든 것을 연습과 같은 것? 다음은 예제 서버입니다.
자원으로 io.FS의 내용을 노출합니다.
이 예제를 컴파일 할 수 있으며 Claude Desktop (또는 다른 MCP 클라이언트)까지 와이어 할 수 있습니다.
문서
- Model Context Protocol 문서
- MCP 사양
- 예제 서버
로드맵
기본 프로토콜의 대다수가 구현됩니다. 다음 기능은 우리의 로드맵에 있습니다:
- 알림
- 샘플링
- 뿌리
법률
MIT 라이선스에 따라 제공됩니다.
이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요.
README
원문 README의 일부입니다. 원문 보기.
MCP Go SDK
A Go implementation of the Model Context Protocol (MCP), providing both client and server capabilities for integrating with LLM surfaces.
Overview
The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This Go SDK implements the full MCP specification, making it easy to:
- Build MCP clients that can connect to any MCP server
- Create MCP servers that expose resources, prompts and tools
- Use standard transports like stdio and SSE (coming soon)
- Handle all MCP protocol messages and lifecycle events
A small example
Curious what all this looks like in practice? Here’s an example server that
exposes the contents of an io.FS as resources.
package main
import (
"context"
"flag"
"io/fs"
"log"
"mime"
"os"
"path/filepath"
"strings"
"github.com/riza-io/mcp-go"
)
type FSServer struct {
fs fs.FS
mcp.UnimplementedServer
}
func (s *FSServer) Initialize(ctx context.Context, req *mcp.Request[mcp.InitializeRequest]) (*mcp.Response[mcp.InitializeResponse], error) {
return mcp.NewResponse(&mcp.InitializeResponse{
ProtocolVersion: req.Params.ProtocolVersion,
Capabilities: mcp.ServerCapabilities{
Resources: &mcp.Resources{},
},
}), nil
}
func (s *FSServer) ListResources(ctx context.Context, req *mcp.Request[mcp.ListResourcesRequest]) (*mcp.Response[mcp.ListResourcesResponse], error) {
var resources []mcp.Resource
fs.WalkDir(s.fs, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
resources = append(resources, mcp.Resource{
URI: "file://" + path,
Name: path,
MimeType: mime.TypeByExtension(filepath.Ext(path)),
})
return nil
})
return mcp.NewResponse(&mcp.ListResourcesResponse{
Resources: resources,
}), nil
}
func (s *FSServer) ReadResource(ctx context.Context, req *mcp.Request[mcp.ReadResourceRequest]) (*mcp.Response[mcp.ReadResourceResponse], error) {
contents, err := fs.ReadFile(s.fs, strings.TrimPrefix(req.Params.URI, "file://"))
if err != nil {
return nil, err
}
return mcp.NewResponse(&mcp.ReadResourceResponse{
Contents: []mcp.ResourceContent{
{
URI: req.Params.URI,
MimeType: mime.TypeByExtension(filepath.Ext(req.Params.URI)),
Text: string(contents), // TODO: base64 encode
},
},
}), nil
}
func main() {
flag.Parse()
root := flag.Arg(0)
if root == "" {
root = "/"
}
설치
This server does not publish a one-line install command.
Open the repository installation guide MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →설정
{
"mcpServers": {
"fs": {
"command": "/path/to/mcp-go-fs",
"args": [
"/path/to/root/directory"
]
}
}
}