
riza-io/mcp-go
Developer toolsこのページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る
Go のモデルコンテキストプロトコル(MCP)サーバーの構築
概要
モデルコンテクストプロトコル(MCP)のGo導入により、LLMサーフェスと統合するためのクライアントとサーバーの両方の機能を提供します。 Model Context プロトコルは、アプリケーションが LLM のコンテキストを標準化された方法で提供し、実際の LLM 相互作用からコンテキストを提供するという懸念を分離することができます。 この Go SDK は、完全な MCP 仕様を実装し、簡単な操作を実現します。 - MCP サーバーに接続できる MCP クライアントをビルド - リソース、プロンプト、ツールを公開する MCP サーバーを作成する - stdio や SSE などの標準的な輸送を使用する - すべての MCP プロトコル メッセージとライフサイクル イベントを処理する 練習中、こんな感じのことを好奇心ですか? io の内容を公開するサーバの例です。 リソースとしてFS。 この例をコンパイルし、Claude Desktop(またはその他のMCPクライアント) まで配線できます。 - モデルコンテキストプロトコルのドキュメント - MCP 仕様 - サンプルサーバー ベースプロトコルの大部分が実装されています.
概要(AI 翻訳)
MCP は SDK を行きます
モデルコンテクストプロトコル(MCP)のGo導入により、LLMサーフェスと統合するためのクライアントとサーバーの両方の機能を提供します。
概要
Model Context プロトコルは、アプリケーションが LLM のコンテキストを標準化された方法で提供し、実際の LLM 相互作用からコンテキストを提供するという懸念を分離することができます。 この Go SDK は、完全な MCP 仕様を実装し、簡単な操作を実現します。
- MCPサーバーに接続できるMCPクライアントの構築
- リソース、プロンプト、ツールを公開するMCPサーバーを作成する
- stdioやSSEなどの標準輸送を使用する(近日公開)
- すべてのMCPプロトコルメッセージとライフサイクルイベントを処理する
小さな例
練習中、こんな感じのことを好奇心ですか? 以下は、サーバの例です。
リソースとして io.FS の内容を公開します。
この例をコンパイルし、Claude Desktop(またはその他のMCPクライアント) まで配線できます。
ドキュメント
- モデルコンテキストプロトコルのドキュメント
- 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"
]
}
}
}