mcpStatusDiagnostics.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. MCP_SERVER_FAILURE_KINDS,
  4. zcodeMcpServerStatusSnapshotSchema,
  5. } from "../src/zcode-protocol/index.js";
  6. describe("MCP status diagnostics protocol", () => {
  7. it("accepts structured failure diagnostics and keeps legacy snapshots compatible", () => {
  8. expect(
  9. zcodeMcpServerStatusSnapshotSchema.parse({
  10. error: "raw sdk error",
  11. failureKind: "server_unavailable",
  12. serverRequestId: "20260822000000abcdef1234567890abcd",
  13. status: "failed",
  14. toolCount: 0,
  15. transport: "http",
  16. updatedAt: "2026-08-22T00:00:00.000Z",
  17. }),
  18. ).toMatchObject({
  19. failureKind: "server_unavailable",
  20. serverRequestId: "20260822000000abcdef1234567890abcd",
  21. });
  22. expect(
  23. zcodeMcpServerStatusSnapshotSchema.parse({
  24. status: "connected",
  25. toolCount: 3,
  26. transport: "stdio",
  27. updatedAt: "2026-08-22T00:00:00.000Z",
  28. }),
  29. ).not.toHaveProperty("failureKind");
  30. });
  31. it("enumerates every user-facing failure kind and rejects empty request ids", () => {
  32. expect(MCP_SERVER_FAILURE_KINDS).toEqual([
  33. "config_invalid",
  34. "runtime_unavailable",
  35. "process_start_failed",
  36. "network_unreachable",
  37. "connection_timeout",
  38. "protocol_negotiation_failed",
  39. "tool_list_failed",
  40. "unexpected_disconnect",
  41. "oauth_authorization_failed",
  42. "official_origin_untrusted",
  43. "not_authenticated",
  44. "coding_plan_required",
  45. "server_not_found",
  46. "server_unavailable",
  47. "rate_limited",
  48. "server_internal_error",
  49. "protocol_error",
  50. "status_unavailable",
  51. "connection_failed",
  52. ]);
  53. expect(
  54. zcodeMcpServerStatusSnapshotSchema.safeParse({
  55. serverRequestId: "",
  56. status: "failed",
  57. toolCount: 0,
  58. transport: "http",
  59. updatedAt: "2026-08-22T00:00:00.000Z",
  60. }).success,
  61. ).toBe(false);
  62. });
  63. });