• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thoughtspot / mcp-server / 25460237569

06 May 2026 08:47PM UTC coverage: 88.326% (-0.06%) from 88.383%
25460237569

push

github

web-flow
Remove deprecated servers: API Server, OpenAI MCP Server (#139)

- Delete relevant code and update tests

Co-authored-by: Rifdhan Nazeer <rifdhan.nazeer@thoughtspot.com>

585 of 675 branches covered (86.67%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

3 existing lines in 2 files now uncovered.

1314 of 1475 relevant lines covered (89.08%)

619.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.39
/src/utils.ts
1
import { type Span, SpanStatusCode } from "@opentelemetry/api";
2
import { getActiveSpan } from "./metrics/tracing/tracing-utils";
3

4
export type Props = {
5
        accessToken: string;
6
        instanceUrl: string;
7
        clientName: {
8
                clientId: string;
9
                clientName: string;
10
                registrationDate: number;
11
        };
12
        apiVersion?: "beta";
13
};
14

15
export class McpServerError extends Error {
16
        public readonly span?: Span;
17
        public readonly errorJson: any;
18
        public readonly statusCode: number;
19

20
        constructor(errorJson: any, statusCode: number) {
21
                // Extract message from error JSON or use a default message
22
                const message =
23
                        typeof errorJson === "string"
1,448✔
24
                                ? errorJson
25
                                : errorJson?.message || errorJson?.error || "Unknown error occurred";
1,402✔
26

27
                super(message);
1,448✔
28

29
                this.name = "McpServerError";
1,448✔
30
                this.span = getActiveSpan();
1,448✔
31
                this.errorJson = errorJson;
1,448✔
32
                this.statusCode = statusCode;
1,448✔
33

34
                // Set span status if span is provided
35
                if (this.span) {
1,448✔
36
                        this.span.setStatus({
735✔
37
                                code: SpanStatusCode.ERROR,
38
                                message: this.message,
39
                        });
40

41
                        // Record the exception in the span
42
                        this.span.recordException(this);
735✔
43

44
                        // Add error details as span attributes
45
                        if (typeof errorJson === "object" && errorJson !== null) {
735✔
46
                                // Add relevant error details to span attributes
47
                                if (errorJson.code) {
689✔
48
                                        this.span.setAttribute("error.code", errorJson.code);
23✔
49
                                }
50
                                if (errorJson.type) {
689✔
51
                                        this.span.setAttribute("error.type", errorJson.type);
23✔
52
                                }
53
                                if (errorJson.details) {
689✔
54
                                        this.span.setAttribute(
81✔
55
                                                "error.details",
56
                                                JSON.stringify(errorJson.details),
57
                                        );
58
                                }
59
                        }
60

61
                        this.span.setAttribute("error.status_code", this.statusCode);
735✔
62
                }
63

64
                console.error("Error:", this.message);
1,448✔
65

66
                // Ensure proper prototype chain for instanceof checks
67
                Object.setPrototypeOf(this, McpServerError.prototype);
1,448✔
68
        }
69

70
        /**
71
         * Convert the error to a JSON representation
72
         */
73
        toJSON() {
74
                return {
46✔
75
                        name: this.name,
76
                        message: this.message,
77
                        statusCode: this.statusCode,
78
                        errorJson: this.errorJson,
79
                        stack: this.stack,
80
                };
81
        }
82

83
        /**
84
         * Get a user-friendly error message
85
         */
86
        getUserMessage(): string {
87
                if (typeof this.errorJson === "object" && this.errorJson?.userMessage) {
115✔
88
                        return this.errorJson.userMessage;
23✔
89
                }
90
                return this.message;
92✔
91
        }
92
}
93

94
/**
95
 * Store a value in Cloudflare KV
96
 */
97
export async function putInKV(
98
        key: string,
99
        value: any,
100
        env?: any,
101
): Promise<void> {
102
        if (!env?.OAUTH_KV) {
69✔
103
                return;
46✔
104
        }
105
        try {
23✔
106
                await env.OAUTH_KV.put(key, JSON.stringify(value), {
23✔
107
                        expirationTtl: 60 * 60 * 3,
108
                });
109
        } catch (error) {
110
                console.error("Error storing in KV:", error);
×
111
        }
112
}
113

114
/**
115
 * Retrieve a value from Cloudflare KV
116
 */
117
export async function getFromKV(key: string, env?: any): Promise<any> {
118
        console.log("[DEBUG] Getting from KV", key);
115✔
119

120
        if (!env?.OAUTH_KV) {
115✔
121
                return undefined;
69✔
122
        }
123

124
        try {
46✔
125
                const value = await env.OAUTH_KV.get(key, { type: "json" });
46✔
126
                return value;
46✔
127
        } catch (error) {
128
                console.error("Error retrieving from KV:", error);
×
129
                return undefined;
×
130
        }
131
}
132

133
export const capitalize = (s: string): string => {
163✔
UNCOV
134
        if (!s) return "";
×
UNCOV
135
        return s.charAt(0).toUpperCase() + s.slice(1);
×
136
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc