| 23 | ) |
| 24 | |
| 25 | func main() { |
| 26 | out := flag.CommandLine.Output() |
| 27 | flag.Usage = func() { |
| 28 | fmt.Fprintf(out, "Usage: %s <client|server> [-proto <http|https>] [-port <port] [-host <host>]\n\n", os.Args[0]) |
| 29 | fmt.Fprintf(out, "This program demonstrates MCP over HTTP using the streamable transport.\n") |
| 30 | fmt.Fprintf(out, "It can run as either a server or client.\n\n") |
| 31 | fmt.Fprintf(out, "Options:\n") |
| 32 | flag.PrintDefaults() |
| 33 | fmt.Fprintf(out, "\nExamples:\n") |
| 34 | fmt.Fprintf(out, " Run as server: %s server\n", os.Args[0]) |
| 35 | fmt.Fprintf(out, " Run as client: %s client\n", os.Args[0]) |
| 36 | fmt.Fprintf(out, " Custom host/port: %s -port 9000 -host 0.0.0.0 server\n", os.Args[0]) |
| 37 | os.Exit(1) |
| 38 | } |
| 39 | flag.Parse() |
| 40 | |
| 41 | if flag.NArg() != 1 { |
| 42 | fmt.Fprintf(out, "Error: Must specify 'client' or 'server' as first argument\n") |
| 43 | flag.Usage() |
| 44 | } |
| 45 | mode := flag.Arg(0) |
| 46 | |
| 47 | switch mode { |
| 48 | case "server": |
| 49 | if *proto != "http" { |
| 50 | log.Fatalf("Server only works with 'http' (you passed proto=%s)", *proto) |
| 51 | } |
| 52 | runServer(fmt.Sprintf("%s:%d", *host, *port)) |
| 53 | case "client": |
| 54 | runClient(fmt.Sprintf("%s://%s:%d", *proto, *host, *port)) |
| 55 | default: |
| 56 | fmt.Fprintf(os.Stderr, "Error: Invalid mode '%s'. Must be 'client' or 'server'\n\n", mode) |
| 57 | flag.Usage() |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // GetTimeParams defines the parameters for the cityTime tool. |
| 62 | type GetTimeParams struct { |