Skip to content

Commit cf74fa3

Browse files
authored
Merge pull request #41 from rollbar/brianr/user-agent-dynamic-version
User agent: dynamic version, add tool name
2 parents 09cc139 + 0b47b1b commit cf74fa3

20 files changed

+165
-62
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141

4242
- name: Run tests with coverage
4343
run: npm run test:coverage
44+
env:
45+
ROLLBAR_ACCESS_TOKEN: not-a-token
4446

4547
- name: Run end-to-end tests
4648
run: npm run test:e2e

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rollbar/mcp-server",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "Model Context Protocol server for Rollbar",
55
"repository": {
66
"type": "git",

src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import dotenv from "dotenv";
2+
import packageJson from "../package.json" with { type: "json" };
23

34
// Load environment variables from .env file
45
// `quiet: true` to prevent logging to stdio which disrupts some mcp clients
56
dotenv.config({ quiet: true });
67

78
export const ROLLBAR_API_BASE = "https://api.rollbar.com/api/1";
8-
export const USER_AGENT = "rollbar-mcp-server/0.0.1";
9+
export function getUserAgent(toolName: string): string {
10+
return `rollbar-mcp-server/${packageJson.version} (tool: ${toolName})`;
11+
}
912
export const ROLLBAR_ACCESS_TOKEN = process.env.ROLLBAR_ACCESS_TOKEN;
1013

1114
if (!ROLLBAR_ACCESS_TOKEN) {

src/tools/get-deployments.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ export function registerGetDeploymentsTool(server: McpServer) {
1616
},
1717
async ({ limit }) => {
1818
const deploysUrl = `${ROLLBAR_API_BASE}/deploys?limit=${limit}`;
19-
const deploysResponse =
20-
await makeRollbarRequest<RollbarApiResponse<RollbarDeployResponse>>(
21-
deploysUrl,
22-
);
19+
const deploysResponse = await makeRollbarRequest<
20+
RollbarApiResponse<RollbarDeployResponse>
21+
>(deploysUrl, "get-deployments");
2322

2423
if (deploysResponse.err !== 0) {
2524
const errorMessage =

src/tools/get-item-details.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ export function registerGetItemDetailsTool(server: McpServer) {
2727
async ({ counter, max_tokens }) => {
2828
// Redirects are followed, so we get an item response from the counter request
2929
const counterUrl = `${ROLLBAR_API_BASE}/item_by_counter/${counter}`;
30-
const itemResponse =
31-
await makeRollbarRequest<RollbarApiResponse<RollbarItemResponse>>(
32-
counterUrl,
33-
);
30+
const itemResponse = await makeRollbarRequest<
31+
RollbarApiResponse<RollbarItemResponse>
32+
>(counterUrl, "get-item-details");
3433

3534
if (itemResponse.err !== 0) {
3635
const errorMessage =
@@ -41,10 +40,9 @@ export function registerGetItemDetailsTool(server: McpServer) {
4140
const item = itemResponse.result;
4241

4342
const occurrenceUrl = `${ROLLBAR_API_BASE}/instance/${item.last_occurrence_id}`;
44-
const occurrenceResponse =
45-
await makeRollbarRequest<RollbarApiResponse<RollbarOccurrenceResponse>>(
46-
occurrenceUrl,
47-
);
43+
const occurrenceResponse = await makeRollbarRequest<
44+
RollbarApiResponse<RollbarOccurrenceResponse>
45+
>(occurrenceUrl, "get-item-details");
4846

4947
if (occurrenceResponse.err !== 0) {
5048
// We got the item but failed to get occurrence. Return just the item data.

src/tools/get-top-items.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ export function registerGetTopItemsTool(server: McpServer) {
1616
},
1717
async ({ environment }) => {
1818
const reportUrl = `${ROLLBAR_API_BASE}/reports/top_active_items?hours=24&environments=${environment}&sort=occurrences`;
19-
const reportResponse =
20-
await makeRollbarRequest<RollbarApiResponse<RollbarTopItemResponse>>(
21-
reportUrl,
22-
);
19+
const reportResponse = await makeRollbarRequest<
20+
RollbarApiResponse<RollbarTopItemResponse>
21+
>(reportUrl, "get-top-items");
2322

2423
if (reportResponse.err !== 0) {
2524
const errorMessage =

src/tools/get-version.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ export function registerGetVersionTool(server: McpServer) {
1717
},
1818
async ({ version, environment }) => {
1919
const versionsUrl = `${ROLLBAR_API_BASE}/versions/${version}?environment=${environment}`;
20-
const versionsResponse =
21-
await makeRollbarRequest<RollbarApiResponse<RollbarVersionsResponse>>(
22-
versionsUrl,
23-
);
20+
const versionsResponse = await makeRollbarRequest<
21+
RollbarApiResponse<RollbarVersionsResponse>
22+
>(versionsUrl, "get-version");
2423

2524
if (versionsResponse.err !== 0) {
2625
const errorMessage =

src/tools/list-items.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ export function registerListItemsTool(server: McpServer) {
8282

8383
const listUrl = `${ROLLBAR_API_BASE}/items/?${params.toString()}`;
8484

85-
const listResponse =
86-
await makeRollbarRequest<RollbarApiResponse<RollbarListItemsResponse>>(
87-
listUrl,
88-
);
85+
const listResponse = await makeRollbarRequest<
86+
RollbarApiResponse<RollbarListItemsResponse>
87+
>(listUrl, "list-items");
8988

9089
if (listResponse.err !== 0) {
9190
const errorMessage =

src/tools/update-item.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function registerUpdateItemTool(server: McpServer) {
6969
const url = `${ROLLBAR_API_BASE}/item/${itemId}`;
7070
const response = await makeRollbarRequest<RollbarApiResponse<unknown>>(
7171
url,
72+
"update-item",
7273
{
7374
method: "PATCH",
7475
headers: {

src/utils/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { ROLLBAR_ACCESS_TOKEN, USER_AGENT } from "../config.js";
1+
import { ROLLBAR_ACCESS_TOKEN, getUserAgent } from "../config.js";
22

33
// Helper function for making Rollbar API requests
44
export async function makeRollbarRequest<T>(
55
url: string,
6+
toolName: string,
67
options?: RequestInit,
78
): Promise<T> {
89
if (!ROLLBAR_ACCESS_TOKEN) {
910
throw new Error("ROLLBAR_ACCESS_TOKEN environment variable is not set");
1011
}
1112

1213
const headers = {
13-
"User-Agent": USER_AGENT,
14+
"User-Agent": getUserAgent(toolName),
1415
"X-Rollbar-Access-Token": ROLLBAR_ACCESS_TOKEN,
1516
Accept: "application/json",
1617
...options?.headers,

0 commit comments

Comments
 (0)