mcpField
M
MCP-Go

MCP-Go

Local
github.com/OkutaniDaichi0106Developer Tools1Updated 78w ago

About MCP-Go

MCP-Go is a Go library for developers building MCP clients and servers. It provides typed, modular APIs, multiple transport options, and session lifecycle management using Go concurrency.

Key features

  1. 01MCP client and server implementation
  2. 02stdio, WebSockets, and HTTP transports
  3. 03Concurrency with goroutines and channels
  4. 04Type-safe APIs
  5. 05Modular handler design
  6. 06Session lifecycle management

Use cases

  1. 01Build MCP servers in Go
  2. 02Build MCP clients in Go
  3. 03Establish MCP sessions over different transports

MCP support

The library implements MCP specification v2025-03-26 and includes client and server components. Sessions can use stdio, WebSockets, HTTP, or custom transports.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

MCP-Go

What is MCP?

MCP (Model Context Protocol) is a lightweight, flexible protocol designed for efficient communication between AI models and applications. It provides a standardized way for services to exchange messages, tools, and resources while maintaining high performance and reliability.

About this Package

MCP-Go is a Go implementation of the Model Context Protocol that provides a robust framework for AI communication:

  • Client-Server Architecture: Complete implementation of both client and server components
  • Transport Flexibility: Seamlessly communicate via Standard I/O, WebSockets, or HTTP
  • Concurrent Design: Built from the ground up with Go's goroutines and channels
  • Type-Safe APIs: Strong typing throughout the codebase to prevent runtime errors
  • Modular Components: Handler-based design pattern for extensibility and maintainability
  • Session Management: Persistent connections with proper lifecycle handling

Usage

Common Pattern

All MCP-Go implementations follow a similar pattern:

package main

import (
    "github.com/OkutaniDaichi0106/mcp-go/mcp"
)

func main() {
    server := mcp.NewServer()

    // Tool registration
    mcp.HandleToolFunc(&mcp.ToolDefinition{
        Name:        "tool_name",
        Description: "Tool description",
        InputSchema: mcp.InputSchema(`{ "type": "object", ... }`),
    }, func(w mcp.ContentsWriter, name string, args map[string]any) {
        // Tool implementation
        // ...
        w.WriteContents(contents)
    })

    // Resource registration
    mcp.HandleResourceFunc(&mcp.ResourceDefinition{
        URI:         "resource_uri",
        MimeType:    "resource_mime_type",
        Name:        "resource_name",
        Description: "Resource description",
    }, func(w mcp.ContentsWriter, uri string) {
        // Resource implementation
        // ...
        w.WriteContents(contents)
    })

    // Prompt registration
    mcp.HandlePromptFunc(&mcp.PromptDefinition{
        Name:        "prompt_name",
        Description: "Prompt description",
        InputSchema: mcp.InputSchema(`{ "type": "object", ... }`),
    }, func(w mcp.PromptWriter, name string, args map[string]any) {
        // Prompt implementation
        // ...
        w.WriteContents(contents)
    })

    transport, err := ... // Create transport

    // Configure transport and accept -> get session
    session, err := server.Accept(transport)
    defer session.Close()

    // ...
}
package main

import (
    "github.com/OkutaniDaichi0106/mcp-go/mcp"
)

func main() {
    // Sample registration
    mcp.HandleSampleFunc(&mcp.SampleDefinition{
        Name:        "sample_name",
        Description: "Sample description",
    }, func(w mcp.ContentsWriter, name string, args map[string]any) {
        // Sample implementation
        // ...
        w.WriteContents(contents)
    })

    // Root registration
    mcp.HandleRoot(&mcp.RootDefinition{
        URI:  "root_uri",
        Name: "Root name",
    })

    // Create client
    client := mcp.NewClient()

    transport, err := ... // Create transport

    // Configure transport and dial -> get session
    session, err := client.Dial(transport)
    defer session.Close()

    // ...
}
Transport Options

MCP-Go supports multiple transport methods with minimal code changes:

Custom Transports

For custom transports, use the Accept and Dial methods with the appropriate transport object.

// Server
sess, err := server.Accept(t)
// Client
sess, err := client.Dial(t)

Standard I/O

For Standard I/O, use the AcceptStdio and DialStdio methods.

// Server
sess, err := server.AcceptStdio()
// Client
sess, err := client.DialStdio("command", "arg1", "arg2")

HTTP

With HTTP, you can use the AcceptHTTP and DialHTTP methods.

// Server
http.HandleFunc("/mcp", func(w http.ResponseWriter, r *http.Request) {
    sess, err := server.AcceptHTTP(w, r)
})
// Client
sess, err := client.DialHTTP("http://localhost:8080/mcp", nil)

Specification Compliance

MCP-Go implements the Model Context Protocol specification v2025-03-26, which is the latest version of the protocol as of this release.

Installation

go get github.com/OkutaniDaichi0106/mcp-go

Documentation

For detailed API documentation and advanced usage examples, please refer to our GoDoc.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.