Skip to content

Commit a4e228c

Browse files
matz3github-actions[bot]
authored andcommitted
refactor: Adjust code / types to work with latest MCP SDK
1 parent 3e44813 commit a4e228c

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed

src/registerTools.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ export default function (server: McpServer, context: Context, options: Options)
2828
// @ts-expect-error -- Generic type handling
2929
return server.registerTool(name, config, async (...args) => {
3030
try {
31-
const res = await Promise.resolve(callback(...args));
32-
return _processResponse(res, options);
31+
// @ts-expect-error -- Generic type handling
32+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- Generic type handling
33+
const toolResult = callback(...args);
34+
const response = await Promise.resolve(toolResult);
35+
return _processResponse(response, options);
3336
} catch (error) {
3437
handleError(error);
3538
}
@@ -57,14 +60,16 @@ export function _processResponse({content, structuredContent}: CallToolResult, o
5760
if (!options.useResourcesInResponse) {
5861
content = content.map((item) => {
5962
if (item.type === "resource") {
60-
let text = item.resource.text as string;
61-
if (item.resource.title && typeof item.resource.title === "string") {
62-
text = `# ${item.resource.title}\n\n${text}`;
63+
if ("text" in item.resource && typeof item.resource.text === "string") {
64+
return {
65+
type: "text" as const,
66+
text: item.resource.text,
67+
};
68+
} else {
69+
throw new Error(
70+
`Unable to convert resource without text content to text content: ${JSON.stringify(item)}`
71+
);
6372
}
64-
return {
65-
type: "text",
66-
text,
67-
};
6873
}
6974
return item;
7075
});

src/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default class Server {
2929
this.server = new McpServer({
3030
name: "UI5",
3131
version: PKG_VERSION,
32+
}, {
3233
capabilities: {
3334
tools: {},
3435
},

src/tools/run_ui5_linter/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,16 @@ export default function registerTool(registerTool: RegisterTool, context: Contex
5858
content.push({
5959
type: "resource",
6060
resource: {
61-
title: migrationGuide.title,
6261
text: migrationGuide.text,
6362
uri: migrationGuide.uri,
6463
mimeType: "text/markdown",
6564
},
6665
});
67-
};
66+
}
6867
for (const doc of documentationResources) {
6968
content.push({
7069
type: "resource",
7170
resource: {
72-
title: doc.title,
7371
text: doc.text,
7472
uri: doc.uri,
7573
mimeType: "text/markdown",

test/lib/registerTools.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ test("processResponse: Default behavior", (t) => {
144144
type: "resource",
145145
resource: {
146146
uri: pathToFileURL(path.join("/", "path", "to", "resource")).toString(),
147-
title: "Resource Title",
148147
text: "This is the resource content.",
149148
mimeType: "text/plain",
150149
},
@@ -198,8 +197,7 @@ test("processResponse: Do not use resources", (t) => {
198197
type: "resource",
199198
resource: {
200199
uri: pathToFileURL(path.join("/", "path", "to", "resource")).toString(),
201-
title: "Resource Title",
202-
text: "This is the resource content.",
200+
text: "# Resource Title\n\nThis is the resource content.",
203201
mimeType: "text/plain",
204202
},
205203
},
@@ -255,7 +253,6 @@ test("processResponse: Do not use structured content", (t) => {
255253
type: "resource",
256254
resource: {
257255
uri: pathToFileURL(path.join("/", "path", "to", "resource")).toString(),
258-
title: "Resource Title",
259256
text: "This is the resource content.",
260257
mimeType: "text/plain",
261258
},

test/lib/server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ test("Server constructor initializes with correct configuration", (t) => {
106106

107107
// Verify McpServer was initialized with correct parameters
108108
t.is(constructorStub.callCount, 1);
109-
const constructorArgs = constructorStub.firstCall.args[0];
110-
t.is(constructorArgs.name, "UI5");
111-
t.is(constructorArgs.version, PKG_VERSION);
112-
t.deepEqual(constructorArgs.capabilities, {tools: {}});
109+
const constructorArgs = constructorStub.firstCall.args;
110+
t.is(constructorArgs[0].name, "UI5");
111+
t.is(constructorArgs[0].version, PKG_VERSION);
112+
t.deepEqual(constructorArgs[1].capabilities, {tools: {}});
113113

114114
t.deepEqual(registerToolsStub.firstCall.args[2], {
115115
useStructuredContentInResponse: true,

test/lib/tools/run_ui5_linter/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ test("run_ui5_linter tool returns linting results with context information", asy
232232
t.deepEqual(result.content[2], {
233233
type: "resource",
234234
resource: {
235-
title: sampleResults.contextInformation.migrationGuides[0].title,
236235
text: sampleResults.contextInformation.migrationGuides[0].text,
237236
uri: sampleResults.contextInformation.migrationGuides[0].uri,
238237
mimeType: "text/markdown",
@@ -243,7 +242,6 @@ test("run_ui5_linter tool returns linting results with context information", asy
243242
t.deepEqual(result.content[3], {
244243
type: "resource",
245244
resource: {
246-
title: sampleResults.contextInformation.documentationResources[0].title,
247245
text: sampleResults.contextInformation.documentationResources[0].text,
248246
uri: sampleResults.contextInformation.documentationResources[0].uri,
249247
mimeType: "text/markdown",

tsconfig.base.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@
1111

1212
// Generate d.ts files
1313
"declaration": true,
14+
15+
// Needed as workaround for the missing module error
16+
// of the optional peer dependency "@cfworker/json-schema" in
17+
// node_modules/@modelcontextprotocol/sdk/dist/esm/validation/types.d.ts
18+
"skipLibCheck": true,
1419
}
1520
}

0 commit comments

Comments
 (0)