Skip to content

Commit 0aefaa8

Browse files
author
Lasim
committed
refactor: enhance MCP categories API with security and error handling
1 parent c981448 commit 0aefaa8

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

services/backend/api-spec.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12170,6 +12170,11 @@
1217012170
"MCP Categories"
1217112171
],
1217212172
"description": "Retrieve all available MCP server categories for organization. No Content-Type header required for this GET request.",
12173+
"security": [
12174+
{
12175+
"cookieAuth": []
12176+
}
12177+
],
1217312178
"responses": {
1217412179
"200": {
1217512180
"description": "Default Response",
@@ -12243,6 +12248,62 @@
1224312248
}
1224412249
}
1224512250
},
12251+
"401": {
12252+
"description": "Default Response",
12253+
"content": {
12254+
"application/json": {
12255+
"schema": {
12256+
"schema": {
12257+
"description": "Unauthorized - Authentication required",
12258+
"type": "object",
12259+
"properties": {
12260+
"success": {
12261+
"default": false,
12262+
"type": "boolean"
12263+
},
12264+
"error": {
12265+
"type": "string"
12266+
}
12267+
},
12268+
"required": [
12269+
"success",
12270+
"error"
12271+
],
12272+
"additionalProperties": false
12273+
},
12274+
"components": {}
12275+
}
12276+
}
12277+
}
12278+
},
12279+
"403": {
12280+
"description": "Default Response",
12281+
"content": {
12282+
"application/json": {
12283+
"schema": {
12284+
"schema": {
12285+
"description": "Forbidden - Insufficient permissions",
12286+
"type": "object",
12287+
"properties": {
12288+
"success": {
12289+
"default": false,
12290+
"type": "boolean"
12291+
},
12292+
"error": {
12293+
"type": "string"
12294+
}
12295+
},
12296+
"required": [
12297+
"success",
12298+
"error"
12299+
],
12300+
"additionalProperties": false
12301+
},
12302+
"components": {}
12303+
}
12304+
}
12305+
}
12306+
},
1224612307
"500": {
1224712308
"description": "Default Response",
1224812309
"content": {

services/backend/api-spec.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8389,6 +8389,8 @@ paths:
83898389
- MCP Categories
83908390
description: Retrieve all available MCP server categories for organization. No
83918391
Content-Type header required for this GET request.
8392+
security:
8393+
- cookieAuth: []
83928394
responses:
83938395
"200":
83948396
description: Default Response
@@ -8434,6 +8436,44 @@ paths:
84348436
- data
84358437
additionalProperties: false
84368438
components: {}
8439+
"401":
8440+
description: Default Response
8441+
content:
8442+
application/json:
8443+
schema:
8444+
schema:
8445+
description: Unauthorized - Authentication required
8446+
type: object
8447+
properties:
8448+
success:
8449+
default: false
8450+
type: boolean
8451+
error:
8452+
type: string
8453+
required:
8454+
- success
8455+
- error
8456+
additionalProperties: false
8457+
components: {}
8458+
"403":
8459+
description: Default Response
8460+
content:
8461+
application/json:
8462+
schema:
8463+
schema:
8464+
description: Forbidden - Insufficient permissions
8465+
type: object
8466+
properties:
8467+
success:
8468+
default: false
8469+
type: boolean
8470+
error:
8471+
type: string
8472+
required:
8473+
- success
8474+
- error
8475+
additionalProperties: false
8476+
components: {}
84378477
"500":
84388478
description: Default Response
84398479
content:

services/backend/src/permissions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const ROLE_DEFINITIONS = {
5151
'teams.delete',
5252
'team.members.view',
5353
'mcp.servers.read',
54+
'mcp.categories.view',
5455
],
5556
team_admin: [
5657
'teams.view',

services/backend/src/routes/mcp/categories/list.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { z } from 'zod';
33
import { createSchema } from 'zod-openapi';
44
import { McpCategoriesService } from '../../../services/mcpCategoriesService';
55
import { getDb } from '../../../db';
6+
import { requirePermission } from '../../../middleware/roleMiddleware';
67

78
// Response schema
89
const categorySchema = z.object({
@@ -30,11 +31,15 @@ export default async function listCategories(server: FastifyInstance) {
3031
tags: ['MCP Categories'],
3132
summary: 'List all MCP server categories',
3233
description: 'Retrieve all available MCP server categories for organization. No Content-Type header required for this GET request.',
34+
security: [{ cookieAuth: [] }],
3335
response: {
3436
200: createSchema(listCategoriesResponseSchema),
37+
401: createSchema(errorResponseSchema.describe('Unauthorized - Authentication required')),
38+
403: createSchema(errorResponseSchema.describe('Forbidden - Insufficient permissions')),
3539
500: createSchema(errorResponseSchema)
3640
}
37-
}
41+
},
42+
preValidation: requirePermission('mcp.categories.view')
3843
}, async (request, reply) => {
3944
try {
4045
const db = getDb();

0 commit comments

Comments
 (0)