runFakeMCPServer implements a minimal JSON-RPC / MCP server over stdin/stdout, just enough for initialize + tools/list.
()
| 562 | // runFakeMCPServer implements a minimal JSON-RPC / MCP server over |
| 563 | // stdin/stdout, just enough for initialize + tools/list. |
| 564 | func runFakeMCPServer() { |
| 565 | scanner := bufio.NewScanner(os.Stdin) |
| 566 | for scanner.Scan() { |
| 567 | line := scanner.Bytes() |
| 568 | |
| 569 | var req struct { |
| 570 | JSONRPC string `json:"jsonrpc"` |
| 571 | ID json.RawMessage `json:"id"` |
| 572 | Method string `json:"method"` |
| 573 | } |
| 574 | if err := json.Unmarshal(line, &req); err != nil { |
| 575 | continue |
| 576 | } |
| 577 | |
| 578 | var resp any |
| 579 | switch req.Method { |
| 580 | case "initialize": |
| 581 | resp = map[string]any{ |
| 582 | "jsonrpc": "2.0", |
| 583 | "id": req.ID, |
| 584 | "result": map[string]any{ |
| 585 | "protocolVersion": "2025-03-26", |
| 586 | "capabilities": map[string]any{ |
| 587 | "tools": map[string]any{}, |
| 588 | }, |
| 589 | "serverInfo": map[string]any{ |
| 590 | "name": "fake-server", |
| 591 | "version": "0.0.1", |
| 592 | }, |
| 593 | }, |
| 594 | } |
| 595 | case "notifications/initialized": |
| 596 | // No response needed for notifications. |
| 597 | continue |
| 598 | case "tools/list": |
| 599 | resp = map[string]any{ |
| 600 | "jsonrpc": "2.0", |
| 601 | "id": req.ID, |
| 602 | "result": map[string]any{ |
| 603 | "tools": []map[string]any{ |
| 604 | { |
| 605 | "name": "echo", |
| 606 | "description": "echoes input", |
| 607 | "inputSchema": map[string]any{ |
| 608 | "type": "object", |
| 609 | "properties": map[string]any{}, |
| 610 | }, |
| 611 | }, |
| 612 | }, |
| 613 | }, |
| 614 | } |
| 615 | default: |
| 616 | resp = map[string]any{ |
| 617 | "jsonrpc": "2.0", |
| 618 | "id": req.ID, |
| 619 | "error": map[string]any{ |
| 620 | "code": -32601, |
| 621 | "message": "method not found", |
no test coverage detected