@backstage/plugin-mcp-actions-backend 0.1.2 → 0.1.3-next.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @backstage/plugin-mcp-actions-backend
|
|
2
2
|
|
|
3
|
+
## 0.1.3-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d08b0c9: The MCP backend will now convert known Backstage errors into textual responses with `isError: true`.
|
|
8
|
+
The error message can be useful for an LLM to understand and maybe give back to the user.
|
|
9
|
+
Previously all errors where thrown out to `@modelcontextprotocol/sdk` which causes a generic 500.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- @backstage/backend-defaults@0.12.1-next.0
|
|
12
|
+
- @backstage/backend-plugin-api@1.4.3-next.0
|
|
13
|
+
- @backstage/plugin-catalog-node@1.18.1-next.0
|
|
14
|
+
|
|
3
15
|
## 0.1.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -4,6 +4,7 @@ var index_js = require('@modelcontextprotocol/sdk/server/index.js');
|
|
|
4
4
|
var types_js = require('@modelcontextprotocol/sdk/types.js');
|
|
5
5
|
var package_json = require('@backstage/plugin-mcp-actions-backend/package.json');
|
|
6
6
|
var errors = require('@backstage/errors');
|
|
7
|
+
var handleErrors = require('./handleErrors.cjs.js');
|
|
7
8
|
|
|
8
9
|
class McpService {
|
|
9
10
|
constructor(actions) {
|
|
@@ -42,29 +43,31 @@ class McpService {
|
|
|
42
43
|
};
|
|
43
44
|
});
|
|
44
45
|
server.setRequestHandler(types_js.CallToolRequestSchema, async ({ params }) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
return handleErrors.handleErrors(async () => {
|
|
47
|
+
const { actions } = await this.actions.list({ credentials });
|
|
48
|
+
const action = actions.find((a) => a.name === params.name);
|
|
49
|
+
if (!action) {
|
|
50
|
+
throw new errors.NotFoundError(`Action "${params.name}" not found`);
|
|
51
|
+
}
|
|
52
|
+
const { output } = await this.actions.invoke({
|
|
53
|
+
id: action.id,
|
|
54
|
+
input: params.arguments,
|
|
55
|
+
credentials
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
// todo(blam): unfortunately structuredContent is not supported by most clients yet.
|
|
59
|
+
// so the validation for the output happens in the default actions registry
|
|
60
|
+
// and we return it as json text instead for now.
|
|
61
|
+
content: [
|
|
62
|
+
{
|
|
63
|
+
type: "text",
|
|
64
|
+
text: ["```json", JSON.stringify(output, null, 2), "```"].join(
|
|
65
|
+
"\n"
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
};
|
|
54
70
|
});
|
|
55
|
-
return {
|
|
56
|
-
// todo(blam): unfortunately structuredContent is not supported by most clients yet.
|
|
57
|
-
// so the validation for the output happens in the default actions registry
|
|
58
|
-
// and we return it as json text instead for now.
|
|
59
|
-
content: [
|
|
60
|
-
{
|
|
61
|
-
type: "text",
|
|
62
|
-
text: ["```json", JSON.stringify(output, null, 2), "```"].join(
|
|
63
|
-
"\n"
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
};
|
|
68
71
|
});
|
|
69
72
|
return server;
|
|
70
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpService.cjs.js","sources":["../../src/services/McpService.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { BackstageCredentials } from '@backstage/backend-plugin-api';\nimport { Server as McpServer } from '@modelcontextprotocol/sdk/server/index.js';\nimport {\n ListToolsRequestSchema,\n CallToolRequestSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { JsonObject } from '@backstage/types';\nimport { ActionsService } from '@backstage/backend-plugin-api/alpha';\nimport { version } from '@backstage/plugin-mcp-actions-backend/package.json';\nimport { NotFoundError } from '@backstage/errors';\n\nexport class McpService {\n constructor(private readonly actions: ActionsService) {}\n\n static async create({ actions }: { actions: ActionsService }) {\n return new McpService(actions);\n }\n\n getServer({ credentials }: { credentials: BackstageCredentials }) {\n const server = new McpServer(\n {\n name: 'backstage',\n // TODO: this version will most likely change in the future.\n version,\n },\n { capabilities: { tools: {} } },\n );\n\n server.setRequestHandler(ListToolsRequestSchema, async () => {\n // TODO: switch this to be configuration based later\n const { actions } = await this.actions.list({ credentials });\n\n return {\n tools: actions.map(action => ({\n inputSchema: action.schema.input,\n // todo(blam): this is unfortunately not supported by most clients yet.\n // When this is provided you need to provide structuredContent instead.\n // outputSchema: action.schema.output,\n name: action.name,\n description: action.description,\n annotations: {\n title: action.title,\n destructiveHint: action.attributes.destructive,\n idempotentHint: action.attributes.idempotent,\n readOnlyHint: action.attributes.readOnly,\n openWorldHint: false,\n },\n })),\n };\n });\n\n server.setRequestHandler(CallToolRequestSchema, async ({ params }) => {\n const { actions } = await this.actions.list({ credentials });\n
|
|
1
|
+
{"version":3,"file":"McpService.cjs.js","sources":["../../src/services/McpService.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { BackstageCredentials } from '@backstage/backend-plugin-api';\nimport { Server as McpServer } from '@modelcontextprotocol/sdk/server/index.js';\nimport {\n ListToolsRequestSchema,\n CallToolRequestSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { JsonObject } from '@backstage/types';\nimport { ActionsService } from '@backstage/backend-plugin-api/alpha';\nimport { version } from '@backstage/plugin-mcp-actions-backend/package.json';\nimport { NotFoundError } from '@backstage/errors';\n\nimport { handleErrors } from './handleErrors';\n\nexport class McpService {\n constructor(private readonly actions: ActionsService) {}\n\n static async create({ actions }: { actions: ActionsService }) {\n return new McpService(actions);\n }\n\n getServer({ credentials }: { credentials: BackstageCredentials }) {\n const server = new McpServer(\n {\n name: 'backstage',\n // TODO: this version will most likely change in the future.\n version,\n },\n { capabilities: { tools: {} } },\n );\n\n server.setRequestHandler(ListToolsRequestSchema, async () => {\n // TODO: switch this to be configuration based later\n const { actions } = await this.actions.list({ credentials });\n\n return {\n tools: actions.map(action => ({\n inputSchema: action.schema.input,\n // todo(blam): this is unfortunately not supported by most clients yet.\n // When this is provided you need to provide structuredContent instead.\n // outputSchema: action.schema.output,\n name: action.name,\n description: action.description,\n annotations: {\n title: action.title,\n destructiveHint: action.attributes.destructive,\n idempotentHint: action.attributes.idempotent,\n readOnlyHint: action.attributes.readOnly,\n openWorldHint: false,\n },\n })),\n };\n });\n\n server.setRequestHandler(CallToolRequestSchema, async ({ params }) => {\n return handleErrors(async () => {\n const { actions } = await this.actions.list({ credentials });\n const action = actions.find(a => a.name === params.name);\n\n if (!action) {\n throw new NotFoundError(`Action \"${params.name}\" not found`);\n }\n\n const { output } = await this.actions.invoke({\n id: action.id,\n input: params.arguments as JsonObject,\n credentials,\n });\n\n return {\n // todo(blam): unfortunately structuredContent is not supported by most clients yet.\n // so the validation for the output happens in the default actions registry\n // and we return it as json text instead for now.\n content: [\n {\n type: 'text',\n text: ['```json', JSON.stringify(output, null, 2), '```'].join(\n '\\n',\n ),\n },\n ],\n };\n });\n });\n\n return server;\n }\n}\n"],"names":["McpServer","version","ListToolsRequestSchema","CallToolRequestSchema","handleErrors","NotFoundError"],"mappings":";;;;;;;;AA4BO,MAAM,UAAA,CAAW;AAAA,EACtB,YAA6B,OAAA,EAAyB;AAAzB,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAAA,EAA0B;AAAA,EAEvD,aAAa,MAAA,CAAO,EAAE,OAAA,EAAQ,EAAgC;AAC5D,IAAA,OAAO,IAAI,WAAW,OAAO,CAAA;AAAA,EAC/B;AAAA,EAEA,SAAA,CAAU,EAAE,WAAA,EAAY,EAA0C;AAChE,IAAA,MAAM,SAAS,IAAIA,eAAA;AAAA,MACjB;AAAA,QACE,IAAA,EAAM,WAAA;AAAA;AAAA,iBAENC;AAAA,OACF;AAAA,MACA,EAAE,YAAA,EAAc,EAAE,KAAA,EAAO,IAAG;AAAE,KAChC;AAEA,IAAA,MAAA,CAAO,iBAAA,CAAkBC,iCAAwB,YAAY;AAE3D,MAAA,MAAM,EAAE,SAAQ,GAAI,MAAM,KAAK,OAAA,CAAQ,IAAA,CAAK,EAAE,WAAA,EAAa,CAAA;AAE3D,MAAA,OAAO;AAAA,QACL,KAAA,EAAO,OAAA,CAAQ,GAAA,CAAI,CAAA,MAAA,MAAW;AAAA,UAC5B,WAAA,EAAa,OAAO,MAAA,CAAO,KAAA;AAAA;AAAA;AAAA;AAAA,UAI3B,MAAM,MAAA,CAAO,IAAA;AAAA,UACb,aAAa,MAAA,CAAO,WAAA;AAAA,UACpB,WAAA,EAAa;AAAA,YACX,OAAO,MAAA,CAAO,KAAA;AAAA,YACd,eAAA,EAAiB,OAAO,UAAA,CAAW,WAAA;AAAA,YACnC,cAAA,EAAgB,OAAO,UAAA,CAAW,UAAA;AAAA,YAClC,YAAA,EAAc,OAAO,UAAA,CAAW,QAAA;AAAA,YAChC,aAAA,EAAe;AAAA;AACjB,SACF,CAAE;AAAA,OACJ;AAAA,IACF,CAAC,CAAA;AAED,IAAA,MAAA,CAAO,iBAAA,CAAkBC,8BAAA,EAAuB,OAAO,EAAE,QAAO,KAAM;AACpE,MAAA,OAAOC,0BAAa,YAAY;AAC9B,QAAA,MAAM,EAAE,SAAQ,GAAI,MAAM,KAAK,OAAA,CAAQ,IAAA,CAAK,EAAE,WAAA,EAAa,CAAA;AAC3D,QAAA,MAAM,SAAS,OAAA,CAAQ,IAAA,CAAK,OAAK,CAAA,CAAE,IAAA,KAAS,OAAO,IAAI,CAAA;AAEvD,QAAA,IAAI,CAAC,MAAA,EAAQ;AACX,UAAA,MAAM,IAAIC,oBAAA,CAAc,CAAA,QAAA,EAAW,MAAA,CAAO,IAAI,CAAA,WAAA,CAAa,CAAA;AAAA,QAC7D;AAEA,QAAA,MAAM,EAAE,MAAA,EAAO,GAAI,MAAM,IAAA,CAAK,QAAQ,MAAA,CAAO;AAAA,UAC3C,IAAI,MAAA,CAAO,EAAA;AAAA,UACX,OAAO,MAAA,CAAO,SAAA;AAAA,UACd;AAAA,SACD,CAAA;AAED,QAAA,OAAO;AAAA;AAAA;AAAA;AAAA,UAIL,OAAA,EAAS;AAAA,YACP;AAAA,cACE,IAAA,EAAM,MAAA;AAAA,cACN,IAAA,EAAM,CAAC,SAAA,EAAW,IAAA,CAAK,SAAA,CAAU,QAAQ,IAAA,EAAM,CAAC,CAAA,EAAG,KAAK,CAAA,CAAE,IAAA;AAAA,gBACxD;AAAA;AACF;AACF;AACF,SACF;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAC,CAAA;AAED,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var errors = require('@backstage/errors');
|
|
4
|
+
|
|
5
|
+
const knownErrors = /* @__PURE__ */ new Set([
|
|
6
|
+
"InputError",
|
|
7
|
+
"AuthenticationError",
|
|
8
|
+
"NotAllowedError",
|
|
9
|
+
"NotFoundError",
|
|
10
|
+
"ConflictError",
|
|
11
|
+
"NotModifiedError",
|
|
12
|
+
"NotImplementedError",
|
|
13
|
+
"ResponseError"
|
|
14
|
+
]);
|
|
15
|
+
function extractCause(err) {
|
|
16
|
+
if ((err.name === "ResponseError" || err instanceof errors.ForwardedError) && errors.isError(err.cause)) {
|
|
17
|
+
return err.cause;
|
|
18
|
+
}
|
|
19
|
+
return err;
|
|
20
|
+
}
|
|
21
|
+
function describeError(err) {
|
|
22
|
+
if (err instanceof Error) {
|
|
23
|
+
const serialized = errors.serializeError(err);
|
|
24
|
+
const { name, message } = extractCause(serialized);
|
|
25
|
+
if (knownErrors.has(name)) {
|
|
26
|
+
return `${name}: ${message}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
async function handleErrors(fn) {
|
|
32
|
+
try {
|
|
33
|
+
return await fn();
|
|
34
|
+
} catch (err) {
|
|
35
|
+
const description = describeError(err);
|
|
36
|
+
return {
|
|
37
|
+
content: [{ type: "text", text: description }],
|
|
38
|
+
isError: true
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.handleErrors = handleErrors;
|
|
44
|
+
//# sourceMappingURL=handleErrors.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleErrors.cjs.js","sources":["../../src/services/handleErrors.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ErrorLike,\n ForwardedError,\n isError,\n serializeError,\n} from '@backstage/errors';\n\nimport { Server as McpServer } from '@modelcontextprotocol/sdk/server/index.js';\n\nconst knownErrors = new Set([\n 'InputError',\n 'AuthenticationError',\n 'NotAllowedError',\n 'NotFoundError',\n 'ConflictError',\n 'NotModifiedError',\n 'NotImplementedError',\n 'ResponseError',\n]);\n\n// Extracts the cause error, if the provided error is `ResponseError` or\n// `ForwardedError` with a cause.\nfunction extractCause(err: ErrorLike): ErrorLike {\n if (\n (err.name === 'ResponseError' || err instanceof ForwardedError) &&\n isError(err.cause)\n ) {\n return err.cause;\n }\n return err;\n}\n\n/**\n * Takes a value expected to be an object, and returns a description of the\n * error to return to the MCP client, if the error is a known Backstage error.\n *\n * Re-throws the original error otherwise\n */\nfunction describeError(err: unknown): string {\n if (err instanceof Error) {\n const serialized = serializeError(err);\n\n const { name, message } = extractCause(serialized);\n\n if (knownErrors.has(name)) {\n return `${name}: ${message}`;\n }\n }\n\n throw err;\n}\n\ntype RequestResultType = ReturnType<\n Parameters<McpServer['setRequestHandler']>[1]\n>;\n/**\n * Wraps a request function with an error handler that turns known Backstage\n * errors into user-friendly messages, instead of failing the request\n * generically with a 500.\n */\nexport async function handleErrors(\n fn: () => RequestResultType | Promise<RequestResultType>,\n): Promise<RequestResultType> {\n try {\n return await fn();\n } catch (err) {\n // This will rethrow if the error is not a known Backstage error\n const description = describeError(err);\n return {\n content: [{ type: 'text', text: description }],\n isError: true,\n };\n }\n}\n"],"names":["ForwardedError","isError","serializeError"],"mappings":";;;;AAyBA,MAAM,WAAA,uBAAkB,GAAA,CAAI;AAAA,EAC1B,YAAA;AAAA,EACA,qBAAA;AAAA,EACA,iBAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,kBAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF,CAAC,CAAA;AAID,SAAS,aAAa,GAAA,EAA2B;AAC/C,EAAA,IAAA,CACG,GAAA,CAAI,SAAS,eAAA,IAAmB,GAAA,YAAeA,0BAChDC,cAAA,CAAQ,GAAA,CAAI,KAAK,CAAA,EACjB;AACA,IAAA,OAAO,GAAA,CAAI,KAAA;AAAA,EACb;AACA,EAAA,OAAO,GAAA;AACT;AAQA,SAAS,cAAc,GAAA,EAAsB;AAC3C,EAAA,IAAI,eAAe,KAAA,EAAO;AACxB,IAAA,MAAM,UAAA,GAAaC,sBAAe,GAAG,CAAA;AAErC,IAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAQ,GAAI,aAAa,UAAU,CAAA;AAEjD,IAAA,IAAI,WAAA,CAAY,GAAA,CAAI,IAAI,CAAA,EAAG;AACzB,MAAA,OAAO,CAAA,EAAG,IAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA;AAAA,IAC5B;AAAA,EACF;AAEA,EAAA,MAAM,GAAA;AACR;AAUA,eAAsB,aACpB,EAAA,EAC4B;AAC5B,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,EAAA,EAAG;AAAA,EAClB,SAAS,GAAA,EAAK;AAEZ,IAAA,MAAM,WAAA,GAAc,cAAc,GAAG,CAAA;AACrC,IAAA,OAAO;AAAA,MACL,SAAS,CAAC,EAAE,MAAM,MAAA,EAAQ,IAAA,EAAM,aAAa,CAAA;AAAA,MAC7C,OAAA,EAAS;AAAA,KACX;AAAA,EACF;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-mcp-actions-backend",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3-next.0",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "backend-plugin",
|
|
6
6
|
"pluginId": "mcp-actions",
|
|
@@ -37,20 +37,20 @@
|
|
|
37
37
|
"test": "backstage-cli package test"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@backstage/backend-defaults": "
|
|
41
|
-
"@backstage/backend-plugin-api": "
|
|
42
|
-
"@backstage/catalog-client": "
|
|
43
|
-
"@backstage/errors": "
|
|
44
|
-
"@backstage/plugin-catalog-node": "
|
|
45
|
-
"@backstage/types": "
|
|
40
|
+
"@backstage/backend-defaults": "0.12.1-next.0",
|
|
41
|
+
"@backstage/backend-plugin-api": "1.4.3-next.0",
|
|
42
|
+
"@backstage/catalog-client": "1.11.0",
|
|
43
|
+
"@backstage/errors": "1.2.7",
|
|
44
|
+
"@backstage/plugin-catalog-node": "1.18.1-next.0",
|
|
45
|
+
"@backstage/types": "1.2.1",
|
|
46
46
|
"@modelcontextprotocol/sdk": "^1.12.3",
|
|
47
47
|
"express": "^4.17.1",
|
|
48
48
|
"express-promise-router": "^4.1.0",
|
|
49
49
|
"zod": "^3.22.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@backstage/backend-test-utils": "
|
|
53
|
-
"@backstage/cli": "
|
|
52
|
+
"@backstage/backend-test-utils": "1.9.0-next.1",
|
|
53
|
+
"@backstage/cli": "0.34.2-next.1",
|
|
54
54
|
"@types/express": "^4.17.6"
|
|
55
55
|
},
|
|
56
56
|
"typesVersions": {
|