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

Function runBackendServer

examples/server/proxy/main.go:52–69  ·  view source on GitHub ↗

Backend Server: Echoes received headers to verify propagation.

()

Source from the content-addressed store, hash-verified

50
51// Backend Server: Echoes received headers to verify propagation.
52func runBackendServer() {
53 server := mcp.NewServer(&mcp.Implementation{Name: "backend-server", Version: "1.0.0"}, nil)
54
55 mcp.AddTool(server, &mcp.Tool{
56 Name: "echo_headers",
57 Description: "Returns the headers received by the server",
58 }, func(ctx context.Context, req *mcp.CallToolRequest, args struct{}) (*mcp.CallToolResult, any, error) {
59 return nil, req.Extra.Header, nil
60 })
61
62 // Start the backend server on port 8082.
63 log.Println("Starting Backend Server on :8082")
64 if err := http.ListenAndServe(":8082", mcp.NewStreamableHTTPHandler(func(r *http.Request) *mcp.Server {
65 return server
66 }, nil)); err != nil {
67 log.Fatal(err)
68 }
69}
70
71// Proxy Server: Forwards requests to the backend with headers.
72func runProxyServer(ctx context.Context) {

Callers 1

mainFunction · 0.85

Calls 3

NewServerFunction · 0.92
AddToolFunction · 0.92
NewStreamableHTTPHandlerFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…