buildJSONRPCRequest creates a JSON-RPC request with the given tool name and arguments
(method, toolName string, arguments map[string]any)
| 356 | |
| 357 | // buildJSONRPCRequest creates a JSON-RPC request with the given tool name and arguments |
| 358 | func 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. |
no outgoing calls
no test coverage detected