@backstage/plugin-mcp-actions-backend 0.1.2-next.0 → 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,27 @@
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
+
15
+ ## 0.1.2
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+ - @backstage/backend-defaults@0.12.0
21
+ - @backstage/catalog-client@1.11.0
22
+ - @backstage/plugin-catalog-node@1.18.0
23
+ - @backstage/backend-plugin-api@1.4.2
24
+
3
25
  ## 0.1.2-next.0
4
26
 
5
27
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.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 {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { json, Router } from 'express';\nimport { McpService } from './services/McpService';\nimport { createStreamableRouter } from './routers/createStreamableRouter';\nimport { createSseRouter } from './routers/createSseRouter';\nimport {\n actionsRegistryServiceRef,\n actionsServiceRef,\n} from '@backstage/backend-plugin-api/alpha';\n\n/**\n * mcpPlugin backend plugin\n *\n * @public\n */\nexport const mcpPlugin = createBackendPlugin({\n pluginId: 'mcp-actions',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n auth: coreServices.auth,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n actions: actionsServiceRef,\n registry: actionsRegistryServiceRef,\n },\n async init({ actions, logger, httpRouter, httpAuth }) {\n const mcpService = await McpService.create({\n actions,\n });\n\n const sseRouter = createSseRouter({\n mcpService,\n httpAuth,\n });\n\n const streamableRouter = createStreamableRouter({\n mcpService,\n httpAuth,\n logger,\n });\n\n const router = Router();\n router.use(json());\n\n router.use('/v1/sse', sseRouter);\n router.use('/v1', streamableRouter);\n\n httpRouter.use(router);\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","actionsServiceRef","actionsRegistryServiceRef","McpService","createSseRouter","createStreamableRouter","Router","json"],"mappings":";;;;;;;;;AAiCO,MAAM,YAAYA,oCAAoB,CAAA;AAAA,EAC3C,QAAU,EAAA,aAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,MAAA;AAAA,QACrB,MAAMA,6BAAa,CAAA,IAAA;AAAA,QACnB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,YAAYA,6BAAa,CAAA,UAAA;AAAA,QACzB,OAAS,EAAAC,uBAAA;AAAA,QACT,QAAU,EAAAC;AAAA,OACZ;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,SAAS,MAAQ,EAAA,UAAA,EAAY,UAAY,EAAA;AACpD,QAAM,MAAA,UAAA,GAAa,MAAMC,qBAAA,CAAW,MAAO,CAAA;AAAA,UACzC;AAAA,SACD,CAAA;AAED,QAAA,MAAM,YAAYC,+BAAgB,CAAA;AAAA,UAChC,UAAA;AAAA,UACA;AAAA,SACD,CAAA;AAED,QAAA,MAAM,mBAAmBC,6CAAuB,CAAA;AAAA,UAC9C,UAAA;AAAA,UACA,QAAA;AAAA,UACA;AAAA,SACD,CAAA;AAED,QAAA,MAAM,SAASC,cAAO,EAAA;AACtB,QAAO,MAAA,CAAA,GAAA,CAAIC,cAAM,CAAA;AAEjB,QAAO,MAAA,CAAA,GAAA,CAAI,WAAW,SAAS,CAAA;AAC/B,QAAO,MAAA,CAAA,GAAA,CAAI,OAAO,gBAAgB,CAAA;AAElC,QAAA,UAAA,CAAW,IAAI,MAAM,CAAA;AAAA;AACvB,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.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 {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { json, Router } from 'express';\nimport { McpService } from './services/McpService';\nimport { createStreamableRouter } from './routers/createStreamableRouter';\nimport { createSseRouter } from './routers/createSseRouter';\nimport {\n actionsRegistryServiceRef,\n actionsServiceRef,\n} from '@backstage/backend-plugin-api/alpha';\n\n/**\n * mcpPlugin backend plugin\n *\n * @public\n */\nexport const mcpPlugin = createBackendPlugin({\n pluginId: 'mcp-actions',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n auth: coreServices.auth,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n actions: actionsServiceRef,\n registry: actionsRegistryServiceRef,\n },\n async init({ actions, logger, httpRouter, httpAuth }) {\n const mcpService = await McpService.create({\n actions,\n });\n\n const sseRouter = createSseRouter({\n mcpService,\n httpAuth,\n });\n\n const streamableRouter = createStreamableRouter({\n mcpService,\n httpAuth,\n logger,\n });\n\n const router = Router();\n router.use(json());\n\n router.use('/v1/sse', sseRouter);\n router.use('/v1', streamableRouter);\n\n httpRouter.use(router);\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","actionsServiceRef","actionsRegistryServiceRef","McpService","createSseRouter","createStreamableRouter","Router","json"],"mappings":";;;;;;;;;AAiCO,MAAM,YAAYA,oCAAA,CAAoB;AAAA,EAC3C,QAAA,EAAU,aAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,QAAQC,6BAAA,CAAa,MAAA;AAAA,QACrB,MAAMA,6BAAA,CAAa,IAAA;AAAA,QACnB,UAAUA,6BAAA,CAAa,QAAA;AAAA,QACvB,YAAYA,6BAAA,CAAa,UAAA;AAAA,QACzB,OAAA,EAASC,uBAAA;AAAA,QACT,QAAA,EAAUC;AAAA,OACZ;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,SAAS,MAAA,EAAQ,UAAA,EAAY,UAAS,EAAG;AACpD,QAAA,MAAM,UAAA,GAAa,MAAMC,qBAAA,CAAW,MAAA,CAAO;AAAA,UACzC;AAAA,SACD,CAAA;AAED,QAAA,MAAM,YAAYC,+BAAA,CAAgB;AAAA,UAChC,UAAA;AAAA,UACA;AAAA,SACD,CAAA;AAED,QAAA,MAAM,mBAAmBC,6CAAA,CAAuB;AAAA,UAC9C,UAAA;AAAA,UACA,QAAA;AAAA,UACA;AAAA,SACD,CAAA;AAED,QAAA,MAAM,SAASC,cAAA,EAAO;AACtB,QAAA,MAAA,CAAO,GAAA,CAAIC,cAAM,CAAA;AAEjB,QAAA,MAAA,CAAO,GAAA,CAAI,WAAW,SAAS,CAAA;AAC/B,QAAA,MAAA,CAAO,GAAA,CAAI,OAAO,gBAAgB,CAAA;AAElC,QAAA,UAAA,CAAW,IAAI,MAAM,CAAA;AAAA,MACvB;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createSseRouter.cjs.js","sources":["../../src/routers/createSseRouter.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 PromiseRouter from 'express-promise-router';\nimport { Router } from 'express';\nimport { McpService } from '../services/McpService';\nimport { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';\nimport { HttpAuthService } from '@backstage/backend-plugin-api';\n\n/**\n * Legacy SSE endpoint for older clients, hopefully will not be needed for much longer.\n */\nexport const createSseRouter = ({\n mcpService,\n httpAuth,\n}: {\n mcpService: McpService;\n httpAuth: HttpAuthService;\n}): Router => {\n const router = PromiseRouter();\n const transportsToSessionId = new Map<string, SSEServerTransport>();\n\n router.get('/', async (req, res) => {\n const server = mcpService.getServer({\n credentials: await httpAuth.credentials(req),\n });\n\n const transport = new SSEServerTransport(\n `${req.originalUrl}/messages`,\n res,\n );\n\n transportsToSessionId.set(transport.sessionId, transport);\n\n res.on('close', () => {\n transportsToSessionId.delete(transport.sessionId);\n });\n\n await server.connect(transport);\n });\n\n router.post('/messages', async (req, res) => {\n const sessionId = req.query.sessionId as string;\n\n if (!sessionId) {\n res.status(400).contentType('text/plain').write('sessionId is required');\n return;\n }\n\n const transport = transportsToSessionId.get(sessionId);\n if (transport) {\n await transport.handlePostMessage(req, res, req.body);\n } else {\n res\n .status(400)\n .contentType('text/plain')\n .write(`No transport found for sessionId \"${sessionId}\"`);\n }\n });\n return router;\n};\n"],"names":["PromiseRouter","SSEServerTransport"],"mappings":";;;;;;;;;AAwBO,MAAM,kBAAkB,CAAC;AAAA,EAC9B,UAAA;AAAA,EACA;AACF,CAGc,KAAA;AACZ,EAAA,MAAM,SAASA,8BAAc,EAAA;AAC7B,EAAM,MAAA,qBAAA,uBAA4B,GAAgC,EAAA;AAElE,EAAA,MAAA,CAAO,GAAI,CAAA,GAAA,EAAK,OAAO,GAAA,EAAK,GAAQ,KAAA;AAClC,IAAM,MAAA,MAAA,GAAS,WAAW,SAAU,CAAA;AAAA,MAClC,WAAa,EAAA,MAAM,QAAS,CAAA,WAAA,CAAY,GAAG;AAAA,KAC5C,CAAA;AAED,IAAA,MAAM,YAAY,IAAIC,yBAAA;AAAA,MACpB,CAAA,EAAG,IAAI,WAAW,CAAA,SAAA,CAAA;AAAA,MAClB;AAAA,KACF;AAEA,IAAsB,qBAAA,CAAA,GAAA,CAAI,SAAU,CAAA,SAAA,EAAW,SAAS,CAAA;AAExD,IAAI,GAAA,CAAA,EAAA,CAAG,SAAS,MAAM;AACpB,MAAsB,qBAAA,CAAA,MAAA,CAAO,UAAU,SAAS,CAAA;AAAA,KACjD,CAAA;AAED,IAAM,MAAA,MAAA,CAAO,QAAQ,SAAS,CAAA;AAAA,GAC/B,CAAA;AAED,EAAA,MAAA,CAAO,IAAK,CAAA,WAAA,EAAa,OAAO,GAAA,EAAK,GAAQ,KAAA;AAC3C,IAAM,MAAA,SAAA,GAAY,IAAI,KAAM,CAAA,SAAA;AAE5B,IAAA,IAAI,CAAC,SAAW,EAAA;AACd,MAAA,GAAA,CAAI,OAAO,GAAG,CAAA,CAAE,YAAY,YAAY,CAAA,CAAE,MAAM,uBAAuB,CAAA;AACvE,MAAA;AAAA;AAGF,IAAM,MAAA,SAAA,GAAY,qBAAsB,CAAA,GAAA,CAAI,SAAS,CAAA;AACrD,IAAA,IAAI,SAAW,EAAA;AACb,MAAA,MAAM,SAAU,CAAA,iBAAA,CAAkB,GAAK,EAAA,GAAA,EAAK,IAAI,IAAI,CAAA;AAAA,KAC/C,MAAA;AACL,MACG,GAAA,CAAA,MAAA,CAAO,GAAG,CACV,CAAA,WAAA,CAAY,YAAY,CACxB,CAAA,KAAA,CAAM,CAAqC,kCAAA,EAAA,SAAS,CAAG,CAAA,CAAA,CAAA;AAAA;AAC5D,GACD,CAAA;AACD,EAAO,OAAA,MAAA;AACT;;;;"}
1
+ {"version":3,"file":"createSseRouter.cjs.js","sources":["../../src/routers/createSseRouter.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 PromiseRouter from 'express-promise-router';\nimport { Router } from 'express';\nimport { McpService } from '../services/McpService';\nimport { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';\nimport { HttpAuthService } from '@backstage/backend-plugin-api';\n\n/**\n * Legacy SSE endpoint for older clients, hopefully will not be needed for much longer.\n */\nexport const createSseRouter = ({\n mcpService,\n httpAuth,\n}: {\n mcpService: McpService;\n httpAuth: HttpAuthService;\n}): Router => {\n const router = PromiseRouter();\n const transportsToSessionId = new Map<string, SSEServerTransport>();\n\n router.get('/', async (req, res) => {\n const server = mcpService.getServer({\n credentials: await httpAuth.credentials(req),\n });\n\n const transport = new SSEServerTransport(\n `${req.originalUrl}/messages`,\n res,\n );\n\n transportsToSessionId.set(transport.sessionId, transport);\n\n res.on('close', () => {\n transportsToSessionId.delete(transport.sessionId);\n });\n\n await server.connect(transport);\n });\n\n router.post('/messages', async (req, res) => {\n const sessionId = req.query.sessionId as string;\n\n if (!sessionId) {\n res.status(400).contentType('text/plain').write('sessionId is required');\n return;\n }\n\n const transport = transportsToSessionId.get(sessionId);\n if (transport) {\n await transport.handlePostMessage(req, res, req.body);\n } else {\n res\n .status(400)\n .contentType('text/plain')\n .write(`No transport found for sessionId \"${sessionId}\"`);\n }\n });\n return router;\n};\n"],"names":["PromiseRouter","SSEServerTransport"],"mappings":";;;;;;;;;AAwBO,MAAM,kBAAkB,CAAC;AAAA,EAC9B,UAAA;AAAA,EACA;AACF,CAAA,KAGc;AACZ,EAAA,MAAM,SAASA,8BAAA,EAAc;AAC7B,EAAA,MAAM,qBAAA,uBAA4B,GAAA,EAAgC;AAElE,EAAA,MAAA,CAAO,GAAA,CAAI,GAAA,EAAK,OAAO,GAAA,EAAK,GAAA,KAAQ;AAClC,IAAA,MAAM,MAAA,GAAS,WAAW,SAAA,CAAU;AAAA,MAClC,WAAA,EAAa,MAAM,QAAA,CAAS,WAAA,CAAY,GAAG;AAAA,KAC5C,CAAA;AAED,IAAA,MAAM,YAAY,IAAIC,yBAAA;AAAA,MACpB,CAAA,EAAG,IAAI,WAAW,CAAA,SAAA,CAAA;AAAA,MAClB;AAAA,KACF;AAEA,IAAA,qBAAA,CAAsB,GAAA,CAAI,SAAA,CAAU,SAAA,EAAW,SAAS,CAAA;AAExD,IAAA,GAAA,CAAI,EAAA,CAAG,SAAS,MAAM;AACpB,MAAA,qBAAA,CAAsB,MAAA,CAAO,UAAU,SAAS,CAAA;AAAA,IAClD,CAAC,CAAA;AAED,IAAA,MAAM,MAAA,CAAO,QAAQ,SAAS,CAAA;AAAA,EAChC,CAAC,CAAA;AAED,EAAA,MAAA,CAAO,IAAA,CAAK,WAAA,EAAa,OAAO,GAAA,EAAK,GAAA,KAAQ;AAC3C,IAAA,MAAM,SAAA,GAAY,IAAI,KAAA,CAAM,SAAA;AAE5B,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA,GAAA,CAAI,OAAO,GAAG,CAAA,CAAE,YAAY,YAAY,CAAA,CAAE,MAAM,uBAAuB,CAAA;AACvE,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,SAAA,GAAY,qBAAA,CAAsB,GAAA,CAAI,SAAS,CAAA;AACrD,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,MAAM,SAAA,CAAU,iBAAA,CAAkB,GAAA,EAAK,GAAA,EAAK,IAAI,IAAI,CAAA;AAAA,IACtD,CAAA,MAAO;AACL,MAAA,GAAA,CACG,MAAA,CAAO,GAAG,CAAA,CACV,WAAA,CAAY,YAAY,CAAA,CACxB,KAAA,CAAM,CAAA,kCAAA,EAAqC,SAAS,CAAA,CAAA,CAAG,CAAA;AAAA,IAC5D;AAAA,EACF,CAAC,CAAA;AACD,EAAA,OAAO,MAAA;AACT;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createStreamableRouter.cjs.js","sources":["../../src/routers/createStreamableRouter.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 PromiseRouter from 'express-promise-router';\nimport { Router } from 'express';\nimport { McpService } from '../services/McpService';\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport { HttpAuthService, LoggerService } from '@backstage/backend-plugin-api';\nimport { isError } from '@backstage/errors';\n\nexport const createStreamableRouter = ({\n mcpService,\n httpAuth,\n logger,\n}: {\n mcpService: McpService;\n logger: LoggerService;\n httpAuth: HttpAuthService;\n}): Router => {\n const router = PromiseRouter();\n\n router.post('/', async (req, res) => {\n try {\n const server = mcpService.getServer({\n credentials: await httpAuth.credentials(req),\n });\n\n const transport = new StreamableHTTPServerTransport({\n // stateless implementation for now, so that we can support multiple\n // instances of the server backend, and avoid sticky sessions.\n sessionIdGenerator: undefined,\n });\n\n await server.connect(transport);\n await transport.handleRequest(req, res, req.body);\n\n res.on('close', () => {\n transport.close();\n server.close();\n });\n } catch (error) {\n if (isError(error)) {\n logger.error(error.message);\n }\n\n if (!res.headersSent) {\n res.status(500).json({\n jsonrpc: '2.0',\n error: {\n code: -32603,\n message: 'Internal server error',\n },\n id: null,\n });\n }\n }\n });\n\n router.get('/', async (_, res) => {\n // We only support POST requests, so we return a 405 error for all other methods.\n res.writeHead(405).end(\n JSON.stringify({\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Method not allowed.',\n },\n id: null,\n }),\n );\n });\n\n router.delete('/', async (_, res) => {\n // We only support POST requests, so we return a 405 error for all other methods.\n res.writeHead(405).end(\n JSON.stringify({\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Method not allowed.',\n },\n id: null,\n }),\n );\n });\n\n return router;\n};\n"],"names":["PromiseRouter","StreamableHTTPServerTransport","isError"],"mappings":";;;;;;;;;;AAsBO,MAAM,yBAAyB,CAAC;AAAA,EACrC,UAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAIc,KAAA;AACZ,EAAA,MAAM,SAASA,8BAAc,EAAA;AAE7B,EAAA,MAAA,CAAO,IAAK,CAAA,GAAA,EAAK,OAAO,GAAA,EAAK,GAAQ,KAAA;AACnC,IAAI,IAAA;AACF,MAAM,MAAA,MAAA,GAAS,WAAW,SAAU,CAAA;AAAA,QAClC,WAAa,EAAA,MAAM,QAAS,CAAA,WAAA,CAAY,GAAG;AAAA,OAC5C,CAAA;AAED,MAAM,MAAA,SAAA,GAAY,IAAIC,+CAA8B,CAAA;AAAA;AAAA;AAAA,QAGlD,kBAAoB,EAAA,KAAA;AAAA,OACrB,CAAA;AAED,MAAM,MAAA,MAAA,CAAO,QAAQ,SAAS,CAAA;AAC9B,MAAA,MAAM,SAAU,CAAA,aAAA,CAAc,GAAK,EAAA,GAAA,EAAK,IAAI,IAAI,CAAA;AAEhD,MAAI,GAAA,CAAA,EAAA,CAAG,SAAS,MAAM;AACpB,QAAA,SAAA,CAAU,KAAM,EAAA;AAChB,QAAA,MAAA,CAAO,KAAM,EAAA;AAAA,OACd,CAAA;AAAA,aACM,KAAO,EAAA;AACd,MAAI,IAAAC,cAAA,CAAQ,KAAK,CAAG,EAAA;AAClB,QAAO,MAAA,CAAA,KAAA,CAAM,MAAM,OAAO,CAAA;AAAA;AAG5B,MAAI,IAAA,CAAC,IAAI,WAAa,EAAA;AACpB,QAAI,GAAA,CAAA,MAAA,CAAO,GAAG,CAAA,CAAE,IAAK,CAAA;AAAA,UACnB,OAAS,EAAA,KAAA;AAAA,UACT,KAAO,EAAA;AAAA,YACL,IAAM,EAAA,CAAA,KAAA;AAAA,YACN,OAAS,EAAA;AAAA,WACX;AAAA,UACA,EAAI,EAAA;AAAA,SACL,CAAA;AAAA;AACH;AACF,GACD,CAAA;AAED,EAAA,MAAA,CAAO,GAAI,CAAA,GAAA,EAAK,OAAO,CAAA,EAAG,GAAQ,KAAA;AAEhC,IAAI,GAAA,CAAA,SAAA,CAAU,GAAG,CAAE,CAAA,GAAA;AAAA,MACjB,KAAK,SAAU,CAAA;AAAA,QACb,OAAS,EAAA,KAAA;AAAA,QACT,KAAO,EAAA;AAAA,UACL,IAAM,EAAA,CAAA,IAAA;AAAA,UACN,OAAS,EAAA;AAAA,SACX;AAAA,QACA,EAAI,EAAA;AAAA,OACL;AAAA,KACH;AAAA,GACD,CAAA;AAED,EAAA,MAAA,CAAO,MAAO,CAAA,GAAA,EAAK,OAAO,CAAA,EAAG,GAAQ,KAAA;AAEnC,IAAI,GAAA,CAAA,SAAA,CAAU,GAAG,CAAE,CAAA,GAAA;AAAA,MACjB,KAAK,SAAU,CAAA;AAAA,QACb,OAAS,EAAA,KAAA;AAAA,QACT,KAAO,EAAA;AAAA,UACL,IAAM,EAAA,CAAA,IAAA;AAAA,UACN,OAAS,EAAA;AAAA,SACX;AAAA,QACA,EAAI,EAAA;AAAA,OACL;AAAA,KACH;AAAA,GACD,CAAA;AAED,EAAO,OAAA,MAAA;AACT;;;;"}
1
+ {"version":3,"file":"createStreamableRouter.cjs.js","sources":["../../src/routers/createStreamableRouter.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 PromiseRouter from 'express-promise-router';\nimport { Router } from 'express';\nimport { McpService } from '../services/McpService';\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport { HttpAuthService, LoggerService } from '@backstage/backend-plugin-api';\nimport { isError } from '@backstage/errors';\n\nexport const createStreamableRouter = ({\n mcpService,\n httpAuth,\n logger,\n}: {\n mcpService: McpService;\n logger: LoggerService;\n httpAuth: HttpAuthService;\n}): Router => {\n const router = PromiseRouter();\n\n router.post('/', async (req, res) => {\n try {\n const server = mcpService.getServer({\n credentials: await httpAuth.credentials(req),\n });\n\n const transport = new StreamableHTTPServerTransport({\n // stateless implementation for now, so that we can support multiple\n // instances of the server backend, and avoid sticky sessions.\n sessionIdGenerator: undefined,\n });\n\n await server.connect(transport);\n await transport.handleRequest(req, res, req.body);\n\n res.on('close', () => {\n transport.close();\n server.close();\n });\n } catch (error) {\n if (isError(error)) {\n logger.error(error.message);\n }\n\n if (!res.headersSent) {\n res.status(500).json({\n jsonrpc: '2.0',\n error: {\n code: -32603,\n message: 'Internal server error',\n },\n id: null,\n });\n }\n }\n });\n\n router.get('/', async (_, res) => {\n // We only support POST requests, so we return a 405 error for all other methods.\n res.writeHead(405).end(\n JSON.stringify({\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Method not allowed.',\n },\n id: null,\n }),\n );\n });\n\n router.delete('/', async (_, res) => {\n // We only support POST requests, so we return a 405 error for all other methods.\n res.writeHead(405).end(\n JSON.stringify({\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Method not allowed.',\n },\n id: null,\n }),\n );\n });\n\n return router;\n};\n"],"names":["PromiseRouter","StreamableHTTPServerTransport","isError"],"mappings":";;;;;;;;;;AAsBO,MAAM,yBAAyB,CAAC;AAAA,EACrC,UAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAA,KAIc;AACZ,EAAA,MAAM,SAASA,8BAAA,EAAc;AAE7B,EAAA,MAAA,CAAO,IAAA,CAAK,GAAA,EAAK,OAAO,GAAA,EAAK,GAAA,KAAQ;AACnC,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,GAAS,WAAW,SAAA,CAAU;AAAA,QAClC,WAAA,EAAa,MAAM,QAAA,CAAS,WAAA,CAAY,GAAG;AAAA,OAC5C,CAAA;AAED,MAAA,MAAM,SAAA,GAAY,IAAIC,+CAAA,CAA8B;AAAA;AAAA;AAAA,QAGlD,kBAAA,EAAoB,KAAA;AAAA,OACrB,CAAA;AAED,MAAA,MAAM,MAAA,CAAO,QAAQ,SAAS,CAAA;AAC9B,MAAA,MAAM,SAAA,CAAU,aAAA,CAAc,GAAA,EAAK,GAAA,EAAK,IAAI,IAAI,CAAA;AAEhD,MAAA,GAAA,CAAI,EAAA,CAAG,SAAS,MAAM;AACpB,QAAA,SAAA,CAAU,KAAA,EAAM;AAChB,QAAA,MAAA,CAAO,KAAA,EAAM;AAAA,MACf,CAAC,CAAA;AAAA,IACH,SAAS,KAAA,EAAO;AACd,MAAA,IAAIC,cAAA,CAAQ,KAAK,CAAA,EAAG;AAClB,QAAA,MAAA,CAAO,KAAA,CAAM,MAAM,OAAO,CAAA;AAAA,MAC5B;AAEA,MAAA,IAAI,CAAC,IAAI,WAAA,EAAa;AACpB,QAAA,GAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK;AAAA,UACnB,OAAA,EAAS,KAAA;AAAA,UACT,KAAA,EAAO;AAAA,YACL,IAAA,EAAM,MAAA;AAAA,YACN,OAAA,EAAS;AAAA,WACX;AAAA,UACA,EAAA,EAAI;AAAA,SACL,CAAA;AAAA,MACH;AAAA,IACF;AAAA,EACF,CAAC,CAAA;AAED,EAAA,MAAA,CAAO,GAAA,CAAI,GAAA,EAAK,OAAO,CAAA,EAAG,GAAA,KAAQ;AAEhC,IAAA,GAAA,CAAI,SAAA,CAAU,GAAG,CAAA,CAAE,GAAA;AAAA,MACjB,KAAK,SAAA,CAAU;AAAA,QACb,OAAA,EAAS,KAAA;AAAA,QACT,KAAA,EAAO;AAAA,UACL,IAAA,EAAM,KAAA;AAAA,UACN,OAAA,EAAS;AAAA,SACX;AAAA,QACA,EAAA,EAAI;AAAA,OACL;AAAA,KACH;AAAA,EACF,CAAC,CAAA;AAED,EAAA,MAAA,CAAO,MAAA,CAAO,GAAA,EAAK,OAAO,CAAA,EAAG,GAAA,KAAQ;AAEnC,IAAA,GAAA,CAAI,SAAA,CAAU,GAAG,CAAA,CAAE,GAAA;AAAA,MACjB,KAAK,SAAA,CAAU;AAAA,QACb,OAAA,EAAS,KAAA;AAAA,QACT,KAAA,EAAO;AAAA,UACL,IAAA,EAAM,KAAA;AAAA,UACN,OAAA,EAAS;AAAA,SACX;AAAA,QACA,EAAA,EAAI;AAAA,OACL;AAAA,KACH;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;;;;"}
@@ -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
- const { actions } = await this.actions.list({ credentials });
46
- const action = actions.find((a) => a.name === params.name);
47
- if (!action) {
48
- throw new errors.NotFoundError(`Action "${params.name}" not found`);
49
- }
50
- const { output } = await this.actions.invoke({
51
- id: action.id,
52
- input: params.arguments,
53
- credentials
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 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 return server;\n }\n}\n"],"names":["McpServer","version","ListToolsRequestSchema","CallToolRequestSchema","NotFoundError"],"mappings":";;;;;;;AA0BO,MAAM,UAAW,CAAA;AAAA,EACtB,YAA6B,OAAyB,EAAA;AAAzB,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAAA;AAA0B,EAEvD,aAAa,MAAA,CAAO,EAAE,OAAA,EAAwC,EAAA;AAC5D,IAAO,OAAA,IAAI,WAAW,OAAO,CAAA;AAAA;AAC/B,EAEA,SAAA,CAAU,EAAE,WAAA,EAAsD,EAAA;AAChE,IAAA,MAAM,SAAS,IAAIA,eAAA;AAAA,MACjB;AAAA,QACE,IAAM,EAAA,WAAA;AAAA;AAAA,iBAENC;AAAA,OACF;AAAA,MACA,EAAE,YAAc,EAAA,EAAE,KAAO,EAAA,IAAK;AAAA,KAChC;AAEA,IAAO,MAAA,CAAA,iBAAA,CAAkBC,iCAAwB,YAAY;AAE3D,MAAM,MAAA,EAAE,SAAY,GAAA,MAAM,KAAK,OAAQ,CAAA,IAAA,CAAK,EAAE,WAAA,EAAa,CAAA;AAE3D,MAAO,OAAA;AAAA,QACL,KAAA,EAAO,OAAQ,CAAA,GAAA,CAAI,CAAW,MAAA,MAAA;AAAA,UAC5B,WAAA,EAAa,OAAO,MAAO,CAAA,KAAA;AAAA;AAAA;AAAA;AAAA,UAI3B,MAAM,MAAO,CAAA,IAAA;AAAA,UACb,aAAa,MAAO,CAAA,WAAA;AAAA,UACpB,WAAa,EAAA;AAAA,YACX,OAAO,MAAO,CAAA,KAAA;AAAA,YACd,eAAA,EAAiB,OAAO,UAAW,CAAA,WAAA;AAAA,YACnC,cAAA,EAAgB,OAAO,UAAW,CAAA,UAAA;AAAA,YAClC,YAAA,EAAc,OAAO,UAAW,CAAA,QAAA;AAAA,YAChC,aAAe,EAAA;AAAA;AACjB,SACA,CAAA;AAAA,OACJ;AAAA,KACD,CAAA;AAED,IAAA,MAAA,CAAO,iBAAkB,CAAAC,8BAAA,EAAuB,OAAO,EAAE,QAAa,KAAA;AACpE,MAAM,MAAA,EAAE,SAAY,GAAA,MAAM,KAAK,OAAQ,CAAA,IAAA,CAAK,EAAE,WAAA,EAAa,CAAA;AAC3D,MAAA,MAAM,SAAS,OAAQ,CAAA,IAAA,CAAK,OAAK,CAAE,CAAA,IAAA,KAAS,OAAO,IAAI,CAAA;AAEvD,MAAA,IAAI,CAAC,MAAQ,EAAA;AACX,QAAA,MAAM,IAAIC,oBAAA,CAAc,CAAW,QAAA,EAAA,MAAA,CAAO,IAAI,CAAa,WAAA,CAAA,CAAA;AAAA;AAG7D,MAAA,MAAM,EAAE,MAAO,EAAA,GAAI,MAAM,IAAA,CAAK,QAAQ,MAAO,CAAA;AAAA,QAC3C,IAAI,MAAO,CAAA,EAAA;AAAA,QACX,OAAO,MAAO,CAAA,SAAA;AAAA,QACd;AAAA,OACD,CAAA;AAED,MAAO,OAAA;AAAA;AAAA;AAAA;AAAA,QAIL,OAAS,EAAA;AAAA,UACP;AAAA,YACE,IAAM,EAAA,MAAA;AAAA,YACN,IAAA,EAAM,CAAC,SAAA,EAAW,IAAK,CAAA,SAAA,CAAU,QAAQ,IAAM,EAAA,CAAC,CAAG,EAAA,KAAK,CAAE,CAAA,IAAA;AAAA,cACxD;AAAA;AACF;AACF;AACF,OACF;AAAA,KACD,CAAA;AAED,IAAO,OAAA,MAAA;AAAA;AAEX;;;;"}
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.2-next.0",
3
+ "version": "0.1.3-next.0",
4
4
  "backstage": {
5
5
  "role": "backend-plugin",
6
6
  "pluginId": "mcp-actions",
@@ -37,11 +37,11 @@
37
37
  "test": "backstage-cli package test"
38
38
  },
39
39
  "dependencies": {
40
- "@backstage/backend-defaults": "0.11.2-next.0",
41
- "@backstage/backend-plugin-api": "1.4.2-next.0",
42
- "@backstage/catalog-client": "1.11.0-next.0",
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
43
  "@backstage/errors": "1.2.7",
44
- "@backstage/plugin-catalog-node": "1.18.0-next.0",
44
+ "@backstage/plugin-catalog-node": "1.18.1-next.0",
45
45
  "@backstage/types": "1.2.1",
46
46
  "@modelcontextprotocol/sdk": "^1.12.3",
47
47
  "express": "^4.17.1",
@@ -49,8 +49,8 @@
49
49
  "zod": "^3.22.4"
50
50
  },
51
51
  "devDependencies": {
52
- "@backstage/backend-test-utils": "1.7.1-next.0",
53
- "@backstage/cli": "0.33.2-next.0",
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": {