@smartbear/mcp 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/index.js +2 -1
- package/dist/insight-hub/client/api/CurrentUser.js +1 -1
- package/dist/insight-hub/client/api/Error.js +14 -0
- package/dist/insight-hub/client/api/Project.js +28 -0
- package/dist/insight-hub/client/api/base.js +4 -0
- package/dist/insight-hub/client/api/filters.js +167 -0
- package/dist/insight-hub/client.js +153 -29
- package/dist/package.json +3 -2
- package/insight-hub/README.md +11 -8
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -70,13 +70,6 @@ REFLECT_API_TOKEN=your_reflect_token INSIGHT_HUB_AUTH_TOKEN=your_insight_hub_tok
|
|
|
70
70
|
|
|
71
71
|
This will open an inspector window in your browser, where you can test the tools.
|
|
72
72
|
|
|
73
|
-
## Environment Variables
|
|
74
|
-
|
|
75
|
-
- `INSIGHT_HUB_AUTH_TOKEN`: Required for Insight Hub tools. The Auth Token for Insight Hub.
|
|
76
|
-
- `REFLECT_API_TOKEN`: Required for Reflect tools. The Reflect Account API Key for Reflect-based tools.
|
|
77
|
-
- `API_HUB_API_KEY`: Required for API Hub tools. The API Key for API Hub tools.
|
|
78
|
-
- `MCP_SERVER_INSIGHT_HUB_API_KEY`: Optional. If set, enables error reporting of the _MCP_server_ code via the BugSnag SDK. This is useful for debugging and monitoring of the MCP server itself and shouldn't be set to the same API key as your app.
|
|
79
|
-
|
|
80
73
|
## Supported Tools
|
|
81
74
|
|
|
82
75
|
See individual guides for suggested prompts and supported tools and resources:
|
|
@@ -86,6 +79,15 @@ See individual guides for suggested prompts and supported tools and resources:
|
|
|
86
79
|
- [Reflect](./reflect/README.md)
|
|
87
80
|
- [API Hub](./api-hub/README.md)
|
|
88
81
|
|
|
82
|
+
## Environment Variables
|
|
83
|
+
|
|
84
|
+
- `INSIGHT_HUB_AUTH_TOKEN`: Required for Insight Hub tools. The Auth Token for Insight Hub.
|
|
85
|
+
- `REFLECT_API_TOKEN`: Required for Reflect tools. The Reflect Account API Key for Reflect-based tools.
|
|
86
|
+
- `API_HUB_API_KEY`: Required for API Hub tools. The API Key for API Hub tools.
|
|
87
|
+
- `MCP_SERVER_INSIGHT_HUB_API_KEY`: Optional. If set, enables error reporting of the _MCP_server_ code via the BugSnag SDK. This is useful for debugging and monitoring of the MCP server itself and shouldn't be set to the same API key as your app.
|
|
88
|
+
|
|
89
|
+
See individual guides for product-specific configuration via environment variables.
|
|
90
|
+
|
|
89
91
|
## Local Development
|
|
90
92
|
|
|
91
93
|
If you want to build and run the MCP server from source (for development or contribution):
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,8 @@ async function main() {
|
|
|
35
35
|
reflectClient.registerResources(server);
|
|
36
36
|
}
|
|
37
37
|
if (insightHubToken) {
|
|
38
|
-
const insightHubClient = new InsightHubClient(insightHubToken);
|
|
38
|
+
const insightHubClient = new InsightHubClient(insightHubToken, process.env.INSIGHT_HUB_PROJECT_API_KEY, process.env.INSIGHT_HUB_ENDPOINT);
|
|
39
|
+
await insightHubClient.initialize();
|
|
39
40
|
insightHubClient.registerTools(server);
|
|
40
41
|
insightHubClient.registerResources(server);
|
|
41
42
|
}
|
|
@@ -2,7 +2,7 @@ import { BaseAPI, pickFieldsFromArray } from './base.js';
|
|
|
2
2
|
// --- API Class ---
|
|
3
3
|
export class CurrentUserAPI extends BaseAPI {
|
|
4
4
|
static organizationFields = ['id', 'name'];
|
|
5
|
-
static projectFields = ['id', 'name', 'slug'];
|
|
5
|
+
static projectFields = ['id', 'name', 'slug', 'api_key'];
|
|
6
6
|
constructor(configuration) {
|
|
7
7
|
super(configuration);
|
|
8
8
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseAPI } from './base.js';
|
|
2
|
+
import { toQueryString } from './filters.js';
|
|
2
3
|
// --- API Class ---
|
|
3
4
|
export class ErrorAPI extends BaseAPI {
|
|
4
5
|
constructor(configuration) {
|
|
@@ -58,4 +59,17 @@ export class ErrorAPI extends BaseAPI {
|
|
|
58
59
|
url,
|
|
59
60
|
}));
|
|
60
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* List the Errors on a Project
|
|
64
|
+
* GET /projects/{project_id}/errors
|
|
65
|
+
*/
|
|
66
|
+
async listProjectErrors(projectId, options = {}) {
|
|
67
|
+
const url = options.filters
|
|
68
|
+
? `/projects/${projectId}/errors?${toQueryString(options.filters)}`
|
|
69
|
+
: `/projects/${projectId}/errors`;
|
|
70
|
+
return (await this.request({
|
|
71
|
+
method: 'GET',
|
|
72
|
+
url,
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
61
75
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseAPI, pickFieldsFromArray } from "./base.js";
|
|
2
|
+
// --- API Class ---
|
|
3
|
+
export class ProjectAPI extends BaseAPI {
|
|
4
|
+
static eventFieldFields = [
|
|
5
|
+
'custom',
|
|
6
|
+
'display_id',
|
|
7
|
+
'filter_options',
|
|
8
|
+
'pivot_options'
|
|
9
|
+
];
|
|
10
|
+
constructor(configuration) {
|
|
11
|
+
super(configuration);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* List the Event Fields for a Project
|
|
15
|
+
* GET /projects/{project_id}/event_fields
|
|
16
|
+
* @param projectId The project ID
|
|
17
|
+
* @returns A promise that resolves to the list of event fields
|
|
18
|
+
*/
|
|
19
|
+
async listProjectEventFields(projectId) {
|
|
20
|
+
const url = `/projects/${projectId}/event_fields`;
|
|
21
|
+
const data = await this.request({
|
|
22
|
+
method: 'GET',
|
|
23
|
+
url,
|
|
24
|
+
});
|
|
25
|
+
// Only return allowed fields
|
|
26
|
+
return pickFieldsFromArray(data, ProjectAPI.eventFieldFields);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -33,6 +33,10 @@ export class BaseAPI {
|
|
|
33
33
|
let nextUrl = url;
|
|
34
34
|
do {
|
|
35
35
|
const response = await fetch(nextUrl, fetchOptions);
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const errorText = await response.text();
|
|
38
|
+
throw new Error(`Request failed with status ${response.status}: ${errorText}`);
|
|
39
|
+
}
|
|
36
40
|
const data = await response.json();
|
|
37
41
|
if (paginate) {
|
|
38
42
|
results = results.concat(data);
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters utility for Insight Hub API
|
|
3
|
+
*
|
|
4
|
+
* This file provides utility functions for creating filter URL parameters
|
|
5
|
+
* based on the Insight Hub filtering specification described in the Filtering.md document.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
export const FilterValueSchema = z.object({
|
|
9
|
+
type: z.enum(['eq', 'ne', 'empty']),
|
|
10
|
+
value: z.union([z.string(), z.boolean(), z.number()]),
|
|
11
|
+
});
|
|
12
|
+
export const FilterObjectSchema = z.record(z.array(FilterValueSchema));
|
|
13
|
+
/**
|
|
14
|
+
* Creates a filter value object for equality comparison
|
|
15
|
+
*
|
|
16
|
+
* @param value The value to compare against
|
|
17
|
+
* @returns FilterValue with type 'eq'
|
|
18
|
+
*/
|
|
19
|
+
export function equals(value) {
|
|
20
|
+
return {
|
|
21
|
+
type: 'eq',
|
|
22
|
+
value,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a filter value object for inequality comparison
|
|
27
|
+
*
|
|
28
|
+
* @param value The value to compare against
|
|
29
|
+
* @returns FilterValue with type 'ne'
|
|
30
|
+
*/
|
|
31
|
+
export function notEquals(value) {
|
|
32
|
+
return {
|
|
33
|
+
type: 'ne',
|
|
34
|
+
value,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a filter value object for checking if a field is empty or not
|
|
39
|
+
*
|
|
40
|
+
* @param isEmpty Whether the field should be empty (true) or not (false)
|
|
41
|
+
* @returns FilterValue with type 'empty'
|
|
42
|
+
*/
|
|
43
|
+
export function empty(isEmpty) {
|
|
44
|
+
return {
|
|
45
|
+
type: 'empty',
|
|
46
|
+
value: isEmpty.toString(),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a relative time filter for event.since or event.before
|
|
51
|
+
*
|
|
52
|
+
* @param value The amount of time
|
|
53
|
+
* @param unit The time unit ('h' for hours, 'd' for days)
|
|
54
|
+
* @returns FilterValue for the relative time
|
|
55
|
+
*/
|
|
56
|
+
export function relativeTime(value, unit) {
|
|
57
|
+
return {
|
|
58
|
+
type: 'eq',
|
|
59
|
+
value: `${value}${unit}`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates an ISO 8601 time filter (must be in UTC format like 2018-05-20T00:00:00Z)
|
|
64
|
+
*
|
|
65
|
+
* @param date The date object to convert to ISO string
|
|
66
|
+
* @returns FilterValue for the ISO time
|
|
67
|
+
*/
|
|
68
|
+
export function isoTime(date) {
|
|
69
|
+
return {
|
|
70
|
+
type: 'eq',
|
|
71
|
+
value: date.toISOString(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Converts a FilterObject to URL search parameters
|
|
76
|
+
*
|
|
77
|
+
* @param filters The filter object to convert
|
|
78
|
+
* @returns URLSearchParams object with the encoded filters
|
|
79
|
+
*/
|
|
80
|
+
export function toUrlSearchParams(filters) {
|
|
81
|
+
const params = new URLSearchParams();
|
|
82
|
+
Object.entries(filters).forEach(([field, filterValues]) => {
|
|
83
|
+
filterValues.forEach((filterValue) => {
|
|
84
|
+
params.append(`filters[${field}][][type]`, filterValue.type);
|
|
85
|
+
params.append(`filters[${field}][][value]`, filterValue.value.toString());
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
return params;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Converts a FilterObject to a query string
|
|
92
|
+
*
|
|
93
|
+
* @param filters The filter object to convert
|
|
94
|
+
* @returns Query string representation of the filters
|
|
95
|
+
*/
|
|
96
|
+
export function toQueryString(filters) {
|
|
97
|
+
return toUrlSearchParams(filters).toString();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Helper to build a FilterObject with type safety
|
|
101
|
+
*
|
|
102
|
+
* @returns An empty FilterObject that can be built upon
|
|
103
|
+
*/
|
|
104
|
+
export function createFilter() {
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Adds a field filter to an existing FilterObject
|
|
109
|
+
*
|
|
110
|
+
* @param filters The FilterObject to add to
|
|
111
|
+
* @param field The field name (e.g., 'error.status', 'event.since')
|
|
112
|
+
* @param filterValue The FilterValue to add
|
|
113
|
+
* @returns The updated FilterObject for chaining
|
|
114
|
+
*/
|
|
115
|
+
export function addFilter(filters, field, filterValue) {
|
|
116
|
+
if (!filters[field]) {
|
|
117
|
+
filters[field] = [];
|
|
118
|
+
}
|
|
119
|
+
filters[field].push(filterValue);
|
|
120
|
+
return filters;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Utility to create a time range filter between two dates
|
|
124
|
+
*
|
|
125
|
+
* @param filters The FilterObject to add to
|
|
126
|
+
* @param since Start date
|
|
127
|
+
* @param before End date
|
|
128
|
+
* @returns The updated FilterObject for chaining
|
|
129
|
+
*/
|
|
130
|
+
export function addTimeRange(filters, since, before) {
|
|
131
|
+
addFilter(filters, 'event.since', isoTime(since));
|
|
132
|
+
addFilter(filters, 'event.before', isoTime(before));
|
|
133
|
+
return filters;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Utility to create a relative time range filter
|
|
137
|
+
*
|
|
138
|
+
* @param filters The FilterObject to add to
|
|
139
|
+
* @param amount The amount of time (e.g., 7 for 7 days)
|
|
140
|
+
* @param unit The time unit ('h' for hours, 'd' for days)
|
|
141
|
+
* @returns The updated FilterObject for chaining
|
|
142
|
+
*/
|
|
143
|
+
export function addRelativeTimeRange(filters, amount, unit) {
|
|
144
|
+
addFilter(filters, 'event.since', relativeTime(amount, unit));
|
|
145
|
+
return filters;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Usage examples:
|
|
149
|
+
*
|
|
150
|
+
* // Example 1: Open errors with events in the last day
|
|
151
|
+
* const filters = createFilter();
|
|
152
|
+
* addRelativeTimeRange(filters, 1, 'd');
|
|
153
|
+
* addFilter(filters, 'error.status', equals('open'));
|
|
154
|
+
* const queryString = toQueryString(filters);
|
|
155
|
+
*
|
|
156
|
+
* // Example 2: Events affecting specific users on a specific day
|
|
157
|
+
* const filters = createFilter();
|
|
158
|
+
* addTimeRange(filters, new Date('2017-01-01'), new Date('2017-01-02'));
|
|
159
|
+
* addFilter(filters, 'user.email', equals('user1@example.com'));
|
|
160
|
+
* addFilter(filters, 'user.email', equals('user2@example.com'));
|
|
161
|
+
* const queryString = toQueryString(filters);
|
|
162
|
+
*
|
|
163
|
+
* // Example 3: Events that have user data
|
|
164
|
+
* const filters = createFilter();
|
|
165
|
+
* addFilter(filters, 'user.id', empty(false));
|
|
166
|
+
* const queryString = toQueryString(filters);
|
|
167
|
+
*/
|
|
@@ -3,20 +3,71 @@ import { MCP_SERVER_NAME, MCP_SERVER_VERSION } from "../common/info.js";
|
|
|
3
3
|
import { CurrentUserAPI, ErrorAPI, Configuration } from "./client/index.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import Bugsnag from "../common/bugsnag.js";
|
|
6
|
+
import NodeCache from "node-cache";
|
|
7
|
+
import { ProjectAPI } from "./client/api/Project.js";
|
|
8
|
+
import { FilterObjectSchema } from "./client/api/filters.js";
|
|
9
|
+
const HUB_PREFIX = "00000";
|
|
10
|
+
const HUB_API_ENDPOINT = "https://api.insighthub.smartbear.com";
|
|
11
|
+
const DEFAULT_API_ENDPOINT = "https://api.bugsnag.com";
|
|
12
|
+
const cacheKeys = {
|
|
13
|
+
ORG: "insight_hub_org",
|
|
14
|
+
PROJECTS: "insight_hub_projects",
|
|
15
|
+
CURRENT_PROJECT: "insight_hub_current_project",
|
|
16
|
+
PROJECT_EVENT_FILTERS: "insight_hub_project_event_filters",
|
|
17
|
+
};
|
|
6
18
|
export class InsightHubClient {
|
|
7
19
|
currentUserApi;
|
|
8
20
|
errorsApi;
|
|
9
|
-
|
|
21
|
+
cache;
|
|
22
|
+
projectApi;
|
|
23
|
+
projectApiKey;
|
|
24
|
+
constructor(token, projectApiKey, endpoint) {
|
|
25
|
+
if (!endpoint) {
|
|
26
|
+
if (projectApiKey && projectApiKey.startsWith(HUB_PREFIX)) {
|
|
27
|
+
endpoint = HUB_API_ENDPOINT;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
endpoint = DEFAULT_API_ENDPOINT;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
10
33
|
const config = new Configuration({
|
|
11
34
|
authToken: token,
|
|
12
35
|
headers: {
|
|
13
36
|
"User-Agent": `${MCP_SERVER_NAME}/${MCP_SERVER_VERSION}`,
|
|
14
37
|
"Content-Type": "application/json",
|
|
15
38
|
},
|
|
16
|
-
basePath:
|
|
39
|
+
basePath: endpoint,
|
|
17
40
|
});
|
|
18
41
|
this.currentUserApi = new CurrentUserAPI(config);
|
|
19
42
|
this.errorsApi = new ErrorAPI(config);
|
|
43
|
+
this.cache = new NodeCache();
|
|
44
|
+
this.projectApi = new ProjectAPI(config);
|
|
45
|
+
this.projectApiKey = projectApiKey;
|
|
46
|
+
}
|
|
47
|
+
async initialize() {
|
|
48
|
+
const orgs = await this.listOrgs();
|
|
49
|
+
if (!orgs || orgs.length === 0) {
|
|
50
|
+
throw new Error("No organizations found for the current user.");
|
|
51
|
+
}
|
|
52
|
+
// We should only have one org
|
|
53
|
+
this.cache.set(cacheKeys.ORG, orgs[0]);
|
|
54
|
+
const projects = await this.listProjects(orgs[0].id);
|
|
55
|
+
this.cache.set(cacheKeys.PROJECTS, projects);
|
|
56
|
+
if (this.projectApiKey) {
|
|
57
|
+
const project = projects.find((project) => project.api_key === this.projectApiKey);
|
|
58
|
+
if (!project) {
|
|
59
|
+
throw new Error(`Project with API key ${this.projectApiKey} not found in organization ${orgs[0].name}.`);
|
|
60
|
+
}
|
|
61
|
+
this.cache.set(cacheKeys.CURRENT_PROJECT, project);
|
|
62
|
+
const projectFields = await this.listProjectEventFields(project.id);
|
|
63
|
+
if (!projectFields || projectFields.length === 0) {
|
|
64
|
+
throw new Error(`No event fields found for project ${project.name}.`);
|
|
65
|
+
}
|
|
66
|
+
this.cache.set(cacheKeys.PROJECT_EVENT_FILTERS, projectFields);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async listProjectEventFields(projectId) {
|
|
70
|
+
return this.projectApi.listProjectEventFields(projectId);
|
|
20
71
|
}
|
|
21
72
|
async listOrgs() {
|
|
22
73
|
return this.currentUserApi.listUserOrganizations();
|
|
@@ -28,6 +79,25 @@ export class InsightHubClient {
|
|
|
28
79
|
};
|
|
29
80
|
return this.currentUserApi.getOrganizationProjects(orgId, options);
|
|
30
81
|
}
|
|
82
|
+
// This method retrieves all projects for the organization stored in the cache.
|
|
83
|
+
// If no projects are found in the cache, it fetches them from the API and
|
|
84
|
+
// stores them in the cache for future use.
|
|
85
|
+
// It throws an error if no organizations are found in the cache.
|
|
86
|
+
async getProjects() {
|
|
87
|
+
let projects = this.cache.get(cacheKeys.PROJECTS);
|
|
88
|
+
if (!projects) {
|
|
89
|
+
const org = this.cache.get(cacheKeys.ORG);
|
|
90
|
+
if (!org) {
|
|
91
|
+
throw new Error("No organization found in cache.");
|
|
92
|
+
}
|
|
93
|
+
projects = await this.listProjects(org.id);
|
|
94
|
+
this.cache.set(cacheKeys.PROJECTS, projects);
|
|
95
|
+
}
|
|
96
|
+
if (!projects) {
|
|
97
|
+
throw new Error("No projects found.");
|
|
98
|
+
}
|
|
99
|
+
return projects;
|
|
100
|
+
}
|
|
31
101
|
async getErrorDetails(projectId, errorId) {
|
|
32
102
|
return this.errorsApi.viewErrorOnProject(projectId, errorId);
|
|
33
103
|
}
|
|
@@ -42,29 +112,46 @@ export class InsightHubClient {
|
|
|
42
112
|
const eventDetails = await Promise.all(projects.map((p) => this.getProjectEvent(p.id, eventId).catch(_e => null)));
|
|
43
113
|
return eventDetails.find(event => !!event);
|
|
44
114
|
}
|
|
115
|
+
async listProjectErrors(projectId, filters) {
|
|
116
|
+
return this.errorsApi.listProjectErrors(projectId, { filters });
|
|
117
|
+
}
|
|
45
118
|
registerTools(server) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
119
|
+
if (!this.projectApiKey) {
|
|
120
|
+
server.tool("list_insight_hub_projects", "List all projects in an organization.", {
|
|
121
|
+
page_size: z.number().optional().describe("Number of projects to return per page"),
|
|
122
|
+
page: z.number().optional().describe("Page number to return"),
|
|
123
|
+
}, async (args, _extra) => {
|
|
124
|
+
try {
|
|
125
|
+
let projects = await this.getProjects();
|
|
126
|
+
if (!projects || projects.length === 0) {
|
|
127
|
+
return {
|
|
128
|
+
content: [{ type: "text", text: "No projects found." }],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (args.page_size || args.page) {
|
|
132
|
+
const pageSize = args.page_size || 10;
|
|
133
|
+
const page = args.page || 1;
|
|
134
|
+
projects = projects.slice((page - 1) * pageSize, page * pageSize);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
content: [{ type: "text", text: JSON.stringify(projects) }],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
Bugsnag.notify(e);
|
|
142
|
+
throw e;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
60
146
|
server.tool("get_insight_hub_error", "Get error details from a project", {
|
|
61
|
-
projectId: z.string().describe("ID of the project"),
|
|
62
147
|
errorId: z.string().describe("ID of the error to fetch"),
|
|
148
|
+
...(!this.projectApiKey ? { projectId: z.string().optional().describe("ID of the project") } : {}),
|
|
63
149
|
}, async (args, _extra) => {
|
|
64
150
|
try {
|
|
65
|
-
|
|
151
|
+
const projectId = typeof args.projectId === 'string' ? args.projectId : this.cache.get(cacheKeys.CURRENT_PROJECT)?.id;
|
|
152
|
+
if (!projectId || !args.errorId)
|
|
66
153
|
throw new Error("Both projectId and errorId arguments are required");
|
|
67
|
-
const response = await this.getErrorDetails(
|
|
154
|
+
const response = await this.getErrorDetails(projectId, args.errorId);
|
|
68
155
|
return {
|
|
69
156
|
content: [{ type: "text", text: JSON.stringify(response) }],
|
|
70
157
|
};
|
|
@@ -102,9 +189,14 @@ export class InsightHubClient {
|
|
|
102
189
|
if (!projectSlug || !eventId)
|
|
103
190
|
throw new Error("Both projectSlug and eventId must be present in the link");
|
|
104
191
|
// get the project id from list of projects
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
192
|
+
const projects = this.cache.get("insight_hub_projects");
|
|
193
|
+
if (!projects) {
|
|
194
|
+
throw new Error("No projects found in cache.");
|
|
195
|
+
}
|
|
196
|
+
const projectId = projects.find((p) => p.slug === projectSlug)?.id;
|
|
197
|
+
if (!projectId) {
|
|
198
|
+
throw new Error("Project with the specified slug not found.");
|
|
199
|
+
}
|
|
108
200
|
const response = await this.getProjectEvent(projectId, eventId);
|
|
109
201
|
return {
|
|
110
202
|
content: [{ type: "text", text: JSON.stringify(response) }],
|
|
@@ -115,15 +207,45 @@ export class InsightHubClient {
|
|
|
115
207
|
throw e;
|
|
116
208
|
}
|
|
117
209
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
210
|
+
// Dynamically infer the filters schema from cached project event fields
|
|
211
|
+
server.tool("list_insight_hub_project_errors", "List errors in the current project based on a set of event filters. Use this tool to find or list errors based on user-provided search filters. You can use the `get_project_event_filters` tool to find valid filters for the current project.", {
|
|
212
|
+
filters: FilterObjectSchema.optional().describe("Filters to apply to the error list. Valid filters for a project can be found in the `get_project_event_filters` tool."),
|
|
213
|
+
// Conditionally add projectId only when no project API key is configured
|
|
214
|
+
...(this.projectApiKey ? {} : {
|
|
215
|
+
projectId: z.string().describe("ID of the project"),
|
|
216
|
+
}),
|
|
217
|
+
}, async (args, _extra) => {
|
|
121
218
|
try {
|
|
219
|
+
const projectId = typeof args.projectId === 'string' ? args.projectId : this.cache.get(cacheKeys.CURRENT_PROJECT)?.id;
|
|
220
|
+
if (!projectId)
|
|
221
|
+
throw new Error("projectId argument is required");
|
|
222
|
+
// Optionally, validate filter keys against cached event fields
|
|
223
|
+
const eventFields = this.cache.get(cacheKeys.PROJECT_EVENT_FILTERS) || [];
|
|
224
|
+
if (args.filters) {
|
|
225
|
+
const validKeys = new Set(eventFields.map(f => f.display_id));
|
|
226
|
+
for (const key of Object.keys(args.filters)) {
|
|
227
|
+
if (!validKeys.has(key)) {
|
|
228
|
+
throw new Error(`Invalid filter key: ${key}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const response = await this.listProjectErrors(projectId, args.filters);
|
|
122
233
|
return {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
234
|
+
content: [{ type: "text", text: JSON.stringify(response) }],
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
Bugsnag.notify(e);
|
|
239
|
+
throw e;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
server.tool("get_project_event_filters", "Get the available event filters for the current project. Use this tool to find valid filters for the `list_insight_hub_project_errors` tool.", {}, async (_args, _extra) => {
|
|
243
|
+
try {
|
|
244
|
+
const eventFields = this.cache.get(cacheKeys.PROJECT_EVENT_FILTERS);
|
|
245
|
+
if (!eventFields)
|
|
246
|
+
throw new Error("No event filters found in cache.");
|
|
247
|
+
return {
|
|
248
|
+
content: [{ type: "text", text: JSON.stringify(eventFields) }],
|
|
127
249
|
};
|
|
128
250
|
}
|
|
129
251
|
catch (e) {
|
|
@@ -131,6 +253,8 @@ export class InsightHubClient {
|
|
|
131
253
|
throw e;
|
|
132
254
|
}
|
|
133
255
|
});
|
|
256
|
+
}
|
|
257
|
+
registerResources(server) {
|
|
134
258
|
server.resource("insight_hub_event", new ResourceTemplate("insighthub://event/{id}", { list: undefined }), async (uri, { id }) => {
|
|
135
259
|
try {
|
|
136
260
|
return {
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartbear/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MCP server for interacting SmartBear Products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"smartbear",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@bugsnag/js": "^8.2.0",
|
|
38
|
-
"@modelcontextprotocol/sdk": "1.12.1"
|
|
38
|
+
"@modelcontextprotocol/sdk": "1.12.1",
|
|
39
|
+
"node-cache": "^5.1.2"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@eslint/js": "^9.29.0",
|
package/insight-hub/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Fetch details of your app crashes and errors from your [Insight Hub](https://www.smartbear.com/insight-hub) dashboard for your LLM to help you diagnose and fix.
|
|
4
4
|
|
|
5
|
+
To connect an MCP server, you will need to create a personal auth token from the user settings page on your Insight Hub dashboard. If you wish to interact with only one Insight Hub project, we also recommend setting `INSIGHT_HUB_PROJECT_API_KEY` to reduce the scope of the conversation.
|
|
6
|
+
|
|
5
7
|
## Example prompts
|
|
6
8
|
|
|
7
9
|
- "Help me fix this crash from Insight Hub: https://app.bugsnag.com/my-org/my-project/errors/1a2b3c4d5e6f7g8h9i0j1k2l?&event_id=1a2b3c4d5e6f7g8h9i0j1k2l"
|
|
@@ -9,27 +11,28 @@ Fetch details of your app crashes and errors from your [Insight Hub](https://www
|
|
|
9
11
|
|
|
10
12
|
## Environment Variables
|
|
11
13
|
|
|
12
|
-
- `INSIGHT_HUB_AUTH_TOKEN`: Required
|
|
13
|
-
- `
|
|
14
|
+
- `INSIGHT_HUB_AUTH_TOKEN`: (Required) The auth token for your account from your Insight Hub dashboard, under **Personal auth tokens** in user settings.
|
|
15
|
+
- `INSIGHT_HUB_PROJECT_API_KEY`: (Optional) The API key for the Insight Hub project you wish to interact with. Use this to scope all operations to a single project.
|
|
16
|
+
- `INSIGHT_HUB_ENDPOINT`: (Optional) The API server to connect to. Use this for on-premise installations to point to your own endpoint (e.g. `https://your.api.server`).
|
|
14
17
|
|
|
15
18
|
## Tools
|
|
16
19
|
|
|
17
20
|
1. `list_insight_hub_projects`
|
|
18
21
|
- List all projects in an organization.
|
|
22
|
+
- Multi-project mode only.
|
|
19
23
|
2. `get_insight_hub_error`
|
|
20
24
|
- Get error details from a project.
|
|
21
25
|
3. `get_insight_hub_error_latest_event`
|
|
22
26
|
- Get the latest event for an error.
|
|
23
27
|
4. `get_insight_hub_event_details`
|
|
24
|
-
- Get details of a specific event
|
|
28
|
+
- Get details of a specific event.
|
|
29
|
+
5. `get_project_event_filters`
|
|
30
|
+
- List the filters available for a project.
|
|
31
|
+
6. `list_insight_hub_project_errors`
|
|
32
|
+
- List and filter the errors from a project.
|
|
25
33
|
|
|
26
34
|
## Resources
|
|
27
35
|
|
|
28
|
-
- **insight_hub_orgs**
|
|
29
|
-
- URI: `insighthub://orgs`
|
|
30
|
-
- Description: Lists all organizations available to your Insight Hub account in JSON format.
|
|
31
|
-
- Example usage: Retrieve a list of all organizations to get their IDs for use with other tools.
|
|
32
|
-
|
|
33
36
|
- **insight_hub_event**
|
|
34
37
|
- URI Template: `insighthub://event/{id}`
|
|
35
38
|
- Description: Fetches details for a specific event by its event ID. Returns the event details in JSON format.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartbear/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MCP server for interacting SmartBear Products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"smartbear",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@bugsnag/js": "^8.2.0",
|
|
38
|
-
"@modelcontextprotocol/sdk": "1.12.1"
|
|
38
|
+
"@modelcontextprotocol/sdk": "1.12.1",
|
|
39
|
+
"node-cache": "^5.1.2"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@eslint/js": "^9.29.0",
|