-
Notifications
You must be signed in to change notification settings - Fork 13.8k
feat(api): native MCP (Model Context Protocol) server #41082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
328a8db
feat(api): native MCP (Model Context Protocol) server
rodrigok 7e30323
feat(authorization): require access-mcp permission for the MCP endpoint
rodrigok c8d0ccf
Merge branch 'develop' into feat/native-mcp-server
Dnouv 1f55bdf
feat(mcp): harden native server integration
Dnouv 35b43aa
fix(mcp): publish valid tool schemas
Dnouv 1699ab5
fix(mcp): harden HTTP transport
Dnouv c275cdd
Merge remote-tracking branch 'origin/develop' into feat/native-mcp-se…
Dnouv f78c18c
chore(mcp): refine alpha messaging
Dnouv 0d1c5b7
fix(mcp): address protocol review feedback
Dnouv a06ad40
Merge remote-tracking branch 'origin/develop' into feat/native-mcp-se…
Dnouv 92320bb
fix(mcp): bound batched response memory
Dnouv 241c18c
fix(mcp): limit batch dispatch concurrency
Dnouv ce3dafb
refactor(mcp): align protocol route with server patterns
Dnouv d9d046a
fix(mcp): preserve tools and limit protocol requests
Dnouv 19e39e9
fix(mcp): align HTTP transport with protocol revisions
Dnouv 3089fd1
fix(mcp): process legacy batch entries independently
Dnouv 26d7fc3
fix(mcp): normalize Hono route permissions
Dnouv 265deb9
fix(mcp): preserve required variant fields
Dnouv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@rocket.chat/i18n': minor | ||
| '@rocket.chat/meteor': minor | ||
| '@rocket.chat/rest-typings': minor | ||
| --- | ||
|
|
||
| Adds an AI add-on-gated native Model Context Protocol endpoint and its administration controls in AI Center |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| import { getCuratedTools, getExtendedTools } from './catalog'; | ||
|
|
||
| jest.mock('../../../../server/api', () => ({ | ||
| API: { | ||
| api: { | ||
| typedRoutes: { | ||
| '/api/v1/chat.postMessage': { | ||
| post: { | ||
| tags: ['Chat'], | ||
| requestBody: { | ||
| content: { | ||
| 'application/json': { | ||
| schema: { | ||
| oneOf: [ | ||
| { | ||
| type: 'object', | ||
| description: 'Post by room id', | ||
| properties: { roomId: { type: 'string' }, text: { type: 'string', nullable: true } }, | ||
| required: ['roomId'], | ||
| }, | ||
| { | ||
| type: 'object', | ||
| description: 'Post by channel', | ||
| properties: { channel: { type: 'string' }, text: { type: 'string', nullable: true } }, | ||
| required: ['channel'], | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| '/api/v1/rooms.get': { | ||
| get: { | ||
| tags: ['Rooms'], | ||
| parameters: [ | ||
| { | ||
| schema: { | ||
| type: 'object', | ||
| properties: { updatedSince: { type: 'string' } }, | ||
| additionalProperties: { type: 'string', nullable: true }, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| '/api/v1/channels.create': { | ||
| post: { | ||
| tags: ['Missing Documentation'], | ||
| requestBody: { | ||
| content: { | ||
| 'application/json': { | ||
| schema: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'] }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| '/api/v1/channels.list.joined': { | ||
| get: { | ||
| tags: ['Missing Documentation'], | ||
| parameters: [{ schema: { type: 'object', properties: { count: { type: 'number' } } } }], | ||
| }, | ||
| }, | ||
| '/api/v1/rooms.isMember': { | ||
| get: { | ||
| tags: ['Rooms'], | ||
| parameters: [ | ||
| { | ||
| schema: { | ||
| type: 'object', | ||
| properties: { | ||
| roomId: { type: 'string' }, | ||
| userId: { type: 'string' }, | ||
| username: { type: 'string' }, | ||
| }, | ||
| oneOf: [ | ||
| { type: 'object', required: ['roomId', 'userId'] }, | ||
| { type: 'object', required: ['roomId', 'username'] }, | ||
| ], | ||
| additionalProperties: false, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| '/api/v1/teams.listRoomsOfUser': { | ||
| get: { | ||
| tags: ['Teams'], | ||
| parameters: [ | ||
| { | ||
| schema: { | ||
| type: 'object', | ||
| properties: { | ||
| teamId: { type: 'string' }, | ||
| teamName: { type: 'string' }, | ||
| userId: { type: 'string' }, | ||
| }, | ||
| oneOf: [ | ||
| { type: 'object', required: ['teamId'] }, | ||
| { type: 'object', required: ['teamName'] }, | ||
| ], | ||
| required: ['userId'], | ||
| additionalProperties: false, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| '/api/v1/dm.files': { | ||
| get: { | ||
| tags: ['DM'], | ||
| parameters: [ | ||
| { | ||
| schema: { | ||
| oneOf: [ | ||
| { | ||
| type: 'object', | ||
| properties: { thisIsAnExtremelyLongDiscriminatorNameThatEndsInAlpha: { type: 'string' } }, | ||
| required: ['thisIsAnExtremelyLongDiscriminatorNameThatEndsInAlpha'], | ||
| }, | ||
| { | ||
| type: 'object', | ||
| properties: { thisIsAnExtremelyLongDiscriminatorNameThatEndsInBeta: { type: 'string' } }, | ||
| required: ['thisIsAnExtremelyLongDiscriminatorNameThatEndsInBeta'], | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| '/api/v1/users.delete': { | ||
| post: { | ||
| tags: ['Users'], | ||
| requestBody: { content: { 'application/json': { schema: { type: 'object' } } } }, | ||
| }, | ||
| }, | ||
| '/api/v1/users.register': { | ||
| post: { | ||
| tags: ['Users'], | ||
| requestBody: { | ||
| content: { | ||
| 'application/json': { | ||
| schema: { type: 'object', properties: { username: { type: 'string' } }, required: ['username'] }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| describe('MCP tool catalog', () => { | ||
| it('creates one curated tool per discriminated request variant', () => { | ||
| const tools = getCuratedTools(); | ||
|
|
||
| expect(tools.map(({ name }) => name)).toEqual([ | ||
| 'post_chat_postMessage_by_roomId', | ||
| 'post_chat_postMessage_by_channel', | ||
| 'post_channels_create', | ||
| 'get_channels_list_joined', | ||
| 'get_rooms_get', | ||
| ]); | ||
| expect(tools[0]?.inputSchema).toEqual({ | ||
| type: 'object', | ||
| description: 'Post by room id', | ||
| properties: { roomId: { type: 'string' }, text: { type: 'string' } }, | ||
| required: ['roomId'], | ||
| }); | ||
| expect(tools[4]?.inputSchema).toMatchObject({ additionalProperties: { type: 'string' } }); | ||
| }); | ||
|
|
||
| it('only exposes allow-listed routes in the extended catalog', () => { | ||
| const tools = getExtendedTools(); | ||
|
|
||
| expect(tools.map(({ name }) => name)).toEqual( | ||
| expect.arrayContaining([ | ||
| 'post_chat_postMessage_by_roomId', | ||
| 'post_chat_postMessage_by_channel', | ||
| 'post_channels_create', | ||
| 'get_channels_list_joined', | ||
| 'get_rooms_get', | ||
| 'get_rooms_isMember_by_roomId_userId', | ||
| 'get_rooms_isMember_by_roomId_username', | ||
| ]), | ||
| ); | ||
| expect(tools.some(({ name }) => name.includes('users_delete'))).toBe(false); | ||
| expect(tools.some(({ name }) => name.includes('users_register'))).toBe(false); | ||
| }); | ||
|
|
||
| it('keeps curated tool names stable when the extended catalog is enabled', () => { | ||
| const extendedNames = new Set(getExtendedTools().map(({ name }) => name)); | ||
|
|
||
| expect(getCuratedTools().every(({ name }) => extendedNames.has(name))).toBe(true); | ||
|
Dnouv marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| it('generates unique valid names when variant discriminators exceed the MCP limit', () => { | ||
| const tools = getExtendedTools(); | ||
| const names = tools.map(({ name }) => name); | ||
| const dmFileNames = tools.filter(({ path }) => path === '/api/v1/dm.files').map(({ name }) => name); | ||
|
|
||
| expect(dmFileNames).toHaveLength(2); | ||
| expect(new Set(names).size).toBe(names.length); | ||
| expect(names.every((name) => name.length <= 64 && /^[a-zA-Z0-9_-]+$/.test(name))).toBe(true); | ||
| }); | ||
|
|
||
| it('preserves parent properties when variants only declare required fields', () => { | ||
| const tools = getExtendedTools().filter(({ name }) => name.startsWith('get_rooms_isMember')); | ||
|
|
||
| for (const { inputSchema } of tools) { | ||
| const properties = inputSchema.properties as Record<string, unknown>; | ||
| for (const requiredProperty of inputSchema.required as string[]) { | ||
| expect(properties).toHaveProperty(requiredProperty); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| it('preserves shared required fields without changing variant discriminators', () => { | ||
| const tools = getExtendedTools().filter(({ name }) => name.startsWith('get_teams_listRoomsOfUser')); | ||
|
|
||
| expect(tools.map(({ name }) => name)).toEqual(['get_teams_listRoomsOfUser_by_teamId', 'get_teams_listRoomsOfUser_by_teamName']); | ||
| for (const { inputSchema } of tools) { | ||
| expect(inputSchema.required).toEqual(expect.arrayContaining(['userId'])); | ||
| } | ||
| }); | ||
|
|
||
| it('reuses the generated catalogs between requests', () => { | ||
| expect(getCuratedTools()).toBe(getCuratedTools()); | ||
| expect(getExtendedTools()).toBe(getExtendedTools()); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.