Created
October 27, 2025 21:22
-
-
Save yakuter/eb420c6bb4f919d3cb81108f241b8d15 to your computer and use it in GitHub Desktop.
go-mcp-sdk-server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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