JM

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

0 stars 0 forks 品質 34 トレンド 0

This package provides a Go implementation of the Model Context Protocol (MCP) server based on the 2025-03-26 specification.

概要

This package provides a Go implementation of the Model Context Protocol (MCP) server based on the 2025-03-26 specification. It allows applications to expose prompts, resources, and tools to language models through a standardized interface. - : Supports all major features of the MCP specification, including prompts, resources, tools, and utilities. - : Implements the SSE protocol for streaming responses and server-initiated notifications. - : Easily extend with custom handlers for resources, prompts, and tools. - : Provides ready-to-use default implementations for all required interfaces. - : Built-in support for paginated list operations. The implementation consists of the following main components: - Server: The main server implementation that handles HTTP requests and routes them to the appropriate handler. - ResourcesHandler: Interface for handling resource-related operations. - PromptsHandler: Interface for handling prompt-related operations.

README

以下は原文 README の抜粋です。原文を見る。

Model Context Protocol (MCP) Server Implementation

This package provides a Go implementation of the Model Context Protocol (MCP) server based on the 2025-03-26 specification. It allows applications to expose prompts, resources, and tools to language models through a standardized interface.

Features

  • Complete MCP Implementation: Supports all major features of the MCP specification, including prompts, resources, tools, and utilities.
  • Server-Sent Events: Implements the SSE protocol for streaming responses and server-initiated notifications.
  • Extensible Architecture: Easily extend with custom handlers for resources, prompts, and tools.
  • Default Implementations: Provides ready-to-use default implementations for all required interfaces.
  • Pagination Support: Built-in support for paginated list operations.

Components

The implementation consists of the following main components:

  • Server: The main server implementation that handles HTTP requests and routes them to the appropriate handler.
  • ResourcesHandler: Interface for handling resource-related operations.
  • PromptsHandler: Interface for handling prompt-related operations.
  • ToolsHandler: Interface for handling tool-related operations.
  • CompletionHandler: Interface for handling completion requests.
  • NotificationManager: Manages server-sent events and notifications.
  • LoggingManager: Handles logging operations.

Usage

Creating a Server

config := mcp.ServerConfig{
    ProtocolVersion: "2025-03-2",
    ServerInfo: mcp.ServerInfo{
        Name:    "My MCP Server",
        Version: "1.0.0",
    },
    Capabilities: map[string]interface{}{
        "resources": map[string]interface{}{
            "subscribe":   true,
            "listChanged": true,
        },
        "prompts": map[string]interface{}{
            "listChanged": true,
        },
        "tools": map[string]interface{}{
            "listChanged": true,
        },
    },
}

server := mcp.NewServer(config)

Adding Resources

resourceHandler := mcp.NewDefaultResourcesHandler()

resourceHandler.AddResource(
    mcp.ResourceInfo{
        URI:         "file:///example.txt",
        Name:        "example.txt",
        Description: "An example text file",
        MimeType:    "text/plain",
    },
    mcp.ResourceContent{
        URI:      "file:///example.txt",
        MimeType: "text/plain",
        Text:     "This is an example text file content.",
    },
)

server.SetResourcesHandler(resourceHandler)

Adding Prompts

promptsHandler := mcp.NewDefaultPromptsHandler()

promptsHandler.AddPrompt(
    mcp.PromptInfo{
        Name:        "code_review",
        Description: "Review code for quality",
        Arguments: []mcp.PromptArgument{
            {
                Name:        "code",
                Description: "The code to review",
                Required:    true,
            },
        },
    },
    mcp.PromptResult{
GitHub で README 全文を見る

インストール

This server does not publish a one-line install command.

Open the repository installation guide MCP 初心者?mcpskill.org のガイドから始めましょう →