Skip to content

Commit 4b64244

Browse files
authored
feat: Improve context parameter with detailed instructions (#8)
1 parent 8767ff2 commit 4b64244

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcpcat",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Analytics tool for MCP (Model Context Protocol) servers - tracks tool usage patterns and provides insights",
55
"type": "module",
66
"main": "dist/index.js",
@@ -10,7 +10,7 @@
1010
".": {
1111
"types": "./dist/index.d.ts",
1212
"import": "./dist/index.mjs",
13-
"require": "./dist/index.js"
13+
"require": "./dist/index.cjs"
1414
}
1515
},
1616
"scripts": {

src/modules/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
// MCPCat Settings
22
export const INACTIVITY_TIMEOUT_IN_MINUTES = 30;
3-
export const DEFAULT_CONTEXT_PARAMETER_DESCRIPTION =
4-
"Describe why you are calling this tool and how it fits into your overall task";
3+
export const DEFAULT_CONTEXT_PARAMETER_DESCRIPTION = `Explain why you are calling this tool and how it fits into the user's overall goal. This parameter is used for analytics and user intent tracking. YOU MUST provide 15-25 words (count carefully). NEVER use first person ('I', 'we', 'you') - maintain third-person perspective. NEVER include sensitive information such as credentials, passwords, or personal data. Example (20 words): "Searching across the organization's repositories to find all open issues related to performance complaints and latency issues for team prioritization."`;

src/tests/context-parameters.test.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ describe("Context Parameters", () => {
253253
});
254254

255255
// Call list_todos without context - should fail
256-
await expect(
257-
client.request(
256+
// Note: SDK <1.21.0 throws exceptions, SDK >=1.21.0 returns error responses
257+
try {
258+
const result1 = await client.request(
258259
{
259260
method: "tools/call",
260261
params: {
@@ -263,12 +264,17 @@ describe("Context Parameters", () => {
263264
},
264265
},
265266
CallToolResultSchema,
266-
),
267-
).rejects.toThrow();
267+
);
268+
// SDK 1.21.0+ behavior: returns error response
269+
expect(result1.isError).toBe(true);
270+
} catch (error) {
271+
// SDK <1.21.0 behavior: throws exception
272+
expect(error).toBeDefined();
273+
}
268274

269275
// Call with empty context - should also fail
270-
await expect(
271-
client.request(
276+
try {
277+
const result2 = await client.request(
272278
{
273279
method: "tools/call",
274280
params: {
@@ -277,8 +283,13 @@ describe("Context Parameters", () => {
277283
},
278284
},
279285
CallToolResultSchema,
280-
),
281-
).rejects.toThrow();
286+
);
287+
// SDK 1.21.0+ behavior: returns error response
288+
expect(result2.isError).toBe(true);
289+
} catch (error) {
290+
// SDK <1.21.0 behavior: throws exception
291+
expect(error).toBeDefined();
292+
}
282293

283294
// Call with valid context - should succeed
284295
const result = await client.request(

src/tests/context-preservation.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, it, expect } from "vitest";
22
import { addContextParameterToTool } from "../modules/context-parameters";
33
import { RegisteredTool } from "../types";
4+
import { DEFAULT_CONTEXT_PARAMETER_DESCRIPTION } from "../modules/constants";
45

56
describe("Context Parameter Preservation", () => {
67
it("should preserve existing context parameter with custom description", () => {
@@ -29,7 +30,7 @@ describe("Context Parameter Preservation", () => {
2930

3031
// It should NOT be replaced with the default description
3132
expect(result.inputSchema.properties.context.description).not.toBe(
32-
"Describe why you are calling this tool and how it fits into your overall task",
33+
DEFAULT_CONTEXT_PARAMETER_DESCRIPTION,
3334
);
3435
});
3536

@@ -51,7 +52,7 @@ describe("Context Parameter Preservation", () => {
5152
// Context should be added with default description
5253
expect(result.inputSchema.properties.context).toBeDefined();
5354
expect(result.inputSchema.properties.context.description).toBe(
54-
"Describe why you are calling this tool and how it fits into your overall task",
55+
DEFAULT_CONTEXT_PARAMETER_DESCRIPTION,
5556
);
5657
});
5758
});

src/tests/report-missing.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { EventCapture } from "./test-utils";
1212
import { PublishEventRequestEventTypeEnum } from "mcpcat-api";
1313
import { getServerTrackingData } from "../modules/internal";
1414
import { randomUUID } from "node:crypto";
15+
import { DEFAULT_CONTEXT_PARAMETER_DESCRIPTION } from "../modules/constants";
1516

1617
describe("Report Missing Tool", () => {
1718
let server: any;
@@ -118,8 +119,7 @@ describe("Report Missing Tool", () => {
118119
);
119120
expect(addTodoTool.inputSchema.properties.context).toEqual({
120121
type: "string",
121-
description:
122-
"Describe why you are calling this tool and how it fits into your overall task",
122+
description: DEFAULT_CONTEXT_PARAMETER_DESCRIPTION,
123123
});
124124
expect(addTodoTool.inputSchema.required).toContain("context");
125125
});

0 commit comments

Comments
 (0)