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

thoughtspot / mcp-server / 16427075859

21 Jul 2025 08:11PM UTC coverage: 91.696% (+0.02%) from 91.677%
16427075859

Pull #44

github

web-flow
Merge f01d382f5 into 914a35caa
Pull Request #44: [WIP] Chat GPT Deep research

167 of 191 branches covered (87.43%)

Branch coverage included in aggregate %.

102 of 106 new or added lines in 6 files covered. (96.23%)

3 existing lines in 1 file now uncovered.

617 of 664 relevant lines covered (92.92%)

133.56 hits per line

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

97.96
/src/utils.ts
1
import { type Span, SpanStatusCode } from '@opentelemetry/api';
2
import { getActiveSpan } from './metrics/tracing/tracing-utils';
3
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
import { McpAgent } from 'agents/mcp';
5
import type { BaseMCPServer, Context } from './servers/mcp-server-base';
6
import { instrumentDO, type ResolveConfigFn } from '@microlabs/otel-cf-workers';
7

8
export type Props = {
9
    accessToken: string;
10
    instanceUrl: string;
11
    clientName: {
12
        clientId: string;
13
        clientName: string;
14
        registrationDate: number;
15
    };
16
};
17

18
export class McpServerError extends Error {
19
    public readonly span?: Span;
20
    public readonly errorJson: any;
21
    public readonly statusCode: number;
22

23
    constructor(errorJson: any, statusCode: number) {
24
        // Extract message from error JSON or use a default message
25
        const message = typeof errorJson === 'string'
496✔
26
            ? errorJson
27
            : errorJson?.message || errorJson?.error || 'Unknown error occurred';
486✔
28

29
        super(message);
496✔
30

31
        this.name = 'McpServerError';
496✔
32
        this.span = getActiveSpan();
496✔
33
        this.errorJson = errorJson;
496✔
34
        this.statusCode = statusCode;
496✔
35

36
        // Set span status if span is provided
37
        if (this.span) {
496✔
38
            this.span.setStatus({
341✔
39
                code: SpanStatusCode.ERROR,
40
                message: this.message
41
            });
42

43
            // Record the exception in the span
44
            this.span.recordException(this);
341✔
45

46
            // Add error details as span attributes
47
            if (typeof errorJson === 'object' && errorJson !== null) {
341✔
48
                // Add relevant error details to span attributes
49
                if (errorJson.code) {
331✔
50
                    this.span.setAttribute('error.code', errorJson.code);
5✔
51
                }
52
                if (errorJson.type) {
331✔
53
                    this.span.setAttribute('error.type', errorJson.type);
5✔
54
                }
55
                if (errorJson.details) {
331✔
56
                    this.span.setAttribute('error.details', JSON.stringify(errorJson.details));
37✔
57
                }
58
            }
59

60
            this.span.setAttribute('error.status_code', this.statusCode);
341✔
61
        }
62

63
        console.error('Error:', this.message);
496✔
64

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

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

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

93
export function instrumentedMCPServer<T extends BaseMCPServer>(MCPServer: new (ctx: Context) => T, config: ResolveConfigFn) {
94
    const Agent = class extends McpAgent<Env, any, Props> {
56✔
95
        server = new MCPServer(this);
16✔
96

97
        // Argument of type 'typeof ThoughtSpotMCPWrapper' is not assignable to parameter of type 'DOClass'.
98
        // Cannot assign a 'protected' constructor type to a 'public' constructor type.
99
        // Created to satisfy the DOClass type.
100
        // biome-ignore lint/complexity/noUselessConstructor: required for DOClass
101
        public constructor(state: DurableObjectState, env: Env) {
102
            super(state, env);
16✔
103
        }
104

105
        async init() {
NEW
106
            await this.server.init();
×
107
        }
108
    }
109

110
    return instrumentDO(Agent, config);
56✔
111
}
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