MCPcopy Index your code
hub / github.com/github/github-mcp-server / buildJSONRPCRequest

Function buildJSONRPCRequest

cmd/mcpcurl/main.go:358–377  ·  view source on GitHub ↗

buildJSONRPCRequest creates a JSON-RPC request with the given tool name and arguments

(method, toolName string, arguments map[string]any)

Source from the content-addressed store, hash-verified

356
357// buildJSONRPCRequest creates a JSON-RPC request with the given tool name and arguments
358func buildJSONRPCRequest(method, toolName string, arguments map[string]any) (string, error) {
359 id, err := rand.Int(rand.Reader, big.NewInt(10000))
360 if err != nil {
361 return "", fmt.Errorf("failed to generate random ID: %w", err)
362 }
363 request := JSONRPCRequest{
364 JSONRPC: "2.0",
365 ID: int(id.Int64()), // Random ID between 0 and 9999
366 Method: method,
367 Params: RequestParams{
368 Name: toolName,
369 Arguments: arguments,
370 },
371 }
372 jsonData, err := json.Marshal(request)
373 if err != nil {
374 return "", fmt.Errorf("failed to marshal JSON request: %w", err)
375 }
376 return string(jsonData), nil
377}
378
379// executeServerCommand runs the specified command, performs the MCP initialization
380// handshake, sends the JSON request to stdin, and returns the response from stdout.

Callers 3

main.goFile · 0.85
mainFunction · 0.85
addCommandFromToolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected