一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
44 行
1.4 KiB
TypeScript
44 行
1.4 KiB
TypeScript
import Setting from '../../../models/Setting';
|
|
import { setupDatabaseAndSynchronizer, switchClient } from '../../../testing/test-utils';
|
|
import { Request, RequestMethod } from '../Api';
|
|
import ApiResponse from '../ApiResponse';
|
|
import route_mcp from './mcp';
|
|
|
|
const makeRequest = (body: unknown) => {
|
|
return {
|
|
method: RequestMethod.POST,
|
|
body: JSON.stringify(body),
|
|
} as Request;
|
|
};
|
|
|
|
describe('routes/mcp', () => {
|
|
|
|
beforeEach(async () => {
|
|
await setupDatabaseAndSynchronizer(1);
|
|
await switchClient(1);
|
|
Setting.setValue('mcp.enabled', true);
|
|
});
|
|
|
|
test.each([
|
|
['single notification', { jsonrpc: '2.0', method: 'notifications/initialized' }],
|
|
['batch of notifications', [{ jsonrpc: '2.0', method: 'notifications/initialized' }]],
|
|
])('should acknowledge %s with an empty 202', async (_description, payload) => {
|
|
const response = await route_mcp(makeRequest(payload));
|
|
|
|
// Strict MCP clients close the transport if this is a 200.
|
|
expect(response).toBeInstanceOf(ApiResponse);
|
|
expect((response as ApiResponse).status).toBe(202);
|
|
expect((response as ApiResponse).body).toBe('');
|
|
});
|
|
|
|
test('should return the response body for regular requests', async () => {
|
|
const response = await route_mcp(makeRequest({
|
|
jsonrpc: '2.0', id: 1, method: 'initialize', params: {},
|
|
}));
|
|
|
|
expect(response).not.toBeInstanceOf(ApiResponse);
|
|
expect((response as { id: number }).id).toBe(1);
|
|
});
|
|
|
|
});
|