Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 50 additions & 32 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
}
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.20.2",
"@modelcontextprotocol/sdk": "^1.24.2",
"@ui5/linter": "^1.20.5",
"@ui5/logger": "^4.0.2",
"@ui5/project": "^4.0.9",
Expand Down
23 changes: 14 additions & 9 deletions src/registerTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ export default function (server: McpServer, context: Context, options: Options)
// @ts-expect-error -- Generic type handling
return server.registerTool(name, config, async (...args) => {
try {
const res = await Promise.resolve(callback(...args));
return _processResponse(res, options);
// @ts-expect-error -- Generic type handling
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- Generic type handling
const toolResult = callback(...args);
const response = await Promise.resolve(toolResult);
return _processResponse(response, options);
} catch (error) {
handleError(error);
}
Expand Down Expand Up @@ -57,14 +60,16 @@ export function _processResponse({content, structuredContent}: CallToolResult, o
if (!options.useResourcesInResponse) {
content = content.map((item) => {
if (item.type === "resource") {
let text = item.resource.text as string;
if (item.resource.title && typeof item.resource.title === "string") {
text = `# ${item.resource.title}\n\n${text}`;
if ("text" in item.resource && typeof item.resource.text === "string") {
return {
type: "text" as const,
text: item.resource.text,
};
} else {
throw new Error(
`Unable to convert resource without text content to text content: ${JSON.stringify(item)}`
);
}
return {
type: "text",
text,
};
}
return item;
});
Expand Down
1 change: 1 addition & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class Server {
this.server = new McpServer({
name: "UI5",
version: PKG_VERSION,
}, {
capabilities: {
tools: {},
},
Expand Down
4 changes: 1 addition & 3 deletions src/tools/run_ui5_linter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ export default function registerTool(registerTool: RegisterTool, context: Contex
content.push({
type: "resource",
resource: {
title: migrationGuide.title,
text: migrationGuide.text,
uri: migrationGuide.uri,
mimeType: "text/markdown",
},
});
};
}
for (const doc of documentationResources) {
content.push({
type: "resource",
resource: {
title: doc.title,
text: doc.text,
uri: doc.uri,
mimeType: "text/markdown",
Expand Down
5 changes: 1 addition & 4 deletions test/lib/registerTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ test("processResponse: Default behavior", (t) => {
type: "resource",
resource: {
uri: pathToFileURL(path.join("/", "path", "to", "resource")).toString(),
title: "Resource Title",
text: "This is the resource content.",
mimeType: "text/plain",
},
Expand Down Expand Up @@ -198,8 +197,7 @@ test("processResponse: Do not use resources", (t) => {
type: "resource",
resource: {
uri: pathToFileURL(path.join("/", "path", "to", "resource")).toString(),
title: "Resource Title",
text: "This is the resource content.",
text: "# Resource Title\n\nThis is the resource content.",
mimeType: "text/plain",
},
},
Expand Down Expand Up @@ -255,7 +253,6 @@ test("processResponse: Do not use structured content", (t) => {
type: "resource",
resource: {
uri: pathToFileURL(path.join("/", "path", "to", "resource")).toString(),
title: "Resource Title",
text: "This is the resource content.",
mimeType: "text/plain",
},
Expand Down
8 changes: 4 additions & 4 deletions test/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ test("Server constructor initializes with correct configuration", (t) => {

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

t.deepEqual(registerToolsStub.firstCall.args[2], {
useStructuredContentInResponse: true,
Expand Down
2 changes: 0 additions & 2 deletions test/lib/tools/run_ui5_linter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ test("run_ui5_linter tool returns linting results with context information", asy
t.deepEqual(result.content[2], {
type: "resource",
resource: {
title: sampleResults.contextInformation.migrationGuides[0].title,
text: sampleResults.contextInformation.migrationGuides[0].text,
uri: sampleResults.contextInformation.migrationGuides[0].uri,
mimeType: "text/markdown",
Expand All @@ -243,7 +242,6 @@ test("run_ui5_linter tool returns linting results with context information", asy
t.deepEqual(result.content[3], {
type: "resource",
resource: {
title: sampleResults.contextInformation.documentationResources[0].title,
text: sampleResults.contextInformation.documentationResources[0].text,
uri: sampleResults.contextInformation.documentationResources[0].uri,
mimeType: "text/markdown",
Expand Down
5 changes: 5 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@

// Generate d.ts files
"declaration": true,

// Needed as workaround for the missing module error
// of the optional peer dependency "@cfworker/json-schema" in
// node_modules/@modelcontextprotocol/sdk/dist/esm/validation/types.d.ts
"skipLibCheck": true,
}
}