Skip to content

Instantly share code, notes, and snippets.

@yakuter
Created October 27, 2025 21:22
Show Gist options
  • Save yakuter/eb420c6bb4f919d3cb81108f241b8d15 to your computer and use it in GitHub Desktop.
Save yakuter/eb420c6bb4f919d3cb81108f241b8d15 to your computer and use it in GitHub Desktop.
go-mcp-sdk-server
import (
"context"
"log"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
type Input struct {
FilePath string `json:"file_path"`
}
type Output struct {
Lines int `json:"lines"`
}
func CountLines(ctx context.Context, req *mcp.CallToolRequest, input Input) (*mcp.CallToolResult, Output, error) {
// implement logic
return nil, Output{Lines: 1234}, nil
}
func main() {
server := mcp.NewServer(&mcp.Implementation{Name: "line-counter", Version: "v0.1.0"}, nil)
mcp.AddTool(server, &mcp.Tool{Name: "count_lines", Description: "Counts lines in a file"}, CountLines)
if err := server.Run(context.Background(), &mcp.StdioTransport{}); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment