MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / main

Function main

examples/http/main.go:25–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23)
24
25func 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.
62type GetTimeParams struct {

Callers

nothing calls this directly

Calls 2

runServerFunction · 0.70
runClientFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…