> ## Documentation Index
> Fetch the complete documentation index at: https://mcpgolang.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Set up your first mcp-golang server

## Installation

First, add mcp-golang to your project:

```bash theme={null}
go get github.com/metoro-io/mcp-golang
```

## Basic Usage

Here's a simple example of creating an MCP server with a basic tool, a prompt and two resources.

```go theme={null}
package main

import (
	"fmt"
	"github.com/metoro-io/mcp-golang"
	"github.com/metoro-io/mcp-golang/transport/stdio"
)

type Content struct {
	Title       string  `json:"title" jsonschema:"required,description=The title to submit"`
	Description *string `json:"description" jsonschema:"description=The description to submit"`
}
type MyFunctionsArguments struct {
	Submitter string  `json:"submitter" jsonschema:"required,description=The name of the thing calling this tool (openai, google, claude, etc)"`
	Content   Content `json:"content" jsonschema:"required,description=The content of the message"`
}

func main() {
	done := make(chan struct{})

	server := mcp_golang.NewServer(stdio.NewStdioServerTransport())
	err := server.RegisterTool("hello", "Say hello to a person", func(arguments MyFunctionsArguments) (*mcp_golang.ToolResponse, error) {
		return mcp_golang.NewToolResponse(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %s!", arguments.Submitter))), nil
	})
	if err != nil {
		panic(err)
	}

	err = server.RegisterPrompt("prompt_test", "This is a test prompt", func(arguments Content) (*mcp_golang.PromptResponse, error) {
		return mcp_golang.NewPromptResponse("description", mcp_golang.NewPromptMessage(mcp_golang.NewTextContent(fmt.Sprintf("Hello, %s!", arguments.Title)), mcp_golang.RoleUser)), nil
	})
	if err != nil {
		panic(err)
	}

	err = server.RegisterResource("test://resource", "resource_test", "This is a test resource", "application/json", func() (*mcp_golang.ResourceResponse, error) {
		return mcp_golang.NewResourceResponse(mcp_golang.NewTextEmbeddedResource("test://resource", "This is a test resource", "application/json")), nil
	})

	err = server.RegisterResource("file://app_logs", "app_logs", "The app logs", "text/plain", func() (*mcp_golang.ResourceResponse, error) {
		return mcp_golang.NewResourceResponse(mcp_golang.NewTextEmbeddedResource("file://app_logs", "This is a test resource", "text/plain")), nil
	})

	err = server.Serve()
	if err != nil {
		panic(err)
	}

	<-done
}
```

### Using with Claude

Create a file in \~/Library/Application Support/Claude/claude\_desktop\_config.json with the following contents:

```json theme={null}
{
"mcpServers": {
  "golang-mcp-server": {
      "command": "<your path to golang MCP server go executable>",
      "args": [],
      "env": {}
    }
  }
}
```

## HTTP Server Example

You can also create an HTTP-based MCP server. Note that HTTP transport is stateless and doesn't support bidirectional features like notifications - use stdio transport if you need those features.

```go theme={null}
package main

import (
    "context"
    "log"
    "github.com/metoro-io/mcp-golang"
    "github.com/metoro-io/mcp-golang/transport/http"
)

func main() {
    // Create an HTTP transport
    transport := http.NewHTTPTransport("/mcp")
    transport.WithAddr(":8080")

    // Create server with the HTTP transport
    server := mcp.NewServer(transport)

    // Register your tools
    server.RegisterTool("hello", &HelloTool{})

    // Start the server
    if err := server.Serve(); err != nil {
        log.Fatal(err)
    }
}
```

Or using the Gin framework:

```go theme={null}
package main

import (
    "github.com/gin-gonic/gin"
    "github.com/metoro-io/mcp-golang"
    "github.com/metoro-io/mcp-golang/transport/http"
)

func main() {
    // Create a Gin transport
    transport := http.NewGinTransport()
    
    // Create server with the Gin transport
    server := mcp.NewServer(transport)

    // Register your tools
    server.RegisterTool("hello", &HelloTool{})

    // Set up Gin router
    router := gin.Default()
    router.POST("/mcp", transport.Handler())
    
    // Start the server
    router.Run(":8080")
}
```

## HTTP Client Example

To connect to an HTTP-based MCP server:

```go theme={null}
package main

import (
    "context"
    "log"
    "github.com/metoro-io/mcp-golang"
    "github.com/metoro-io/mcp-golang/transport/http"
)

func main() {
    // Create an HTTP client transport
    transport := http.NewHTTPClientTransport("/mcp")
    transport.WithBaseURL("http://localhost:8080")

    // Create client with the HTTP transport
    client := mcp.NewClient(transport)

    // Use the client with context
    ctx := context.Background()
    response, err := client.CallTool(ctx, "hello", map[string]interface{}{
        "submitter": "openai",
    })
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Response: %v", response)
}
```

## Next Steps

* If you're interested in contributing to mcp-golang, check out [Development Guide](/development) for more detailed information
* Join our [Discord Community](https://discord.gg/33saRwE3pT) for support
* Visit our [GitHub Repository](https://github.com/metoro-io/mcp-golang) to contribute
