@agledger/mcp-server 1.4.3 → 2.0.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/dist/api-client.d.ts +16 -0
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +52 -0
- package/dist/api-client.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -60
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +2 -13
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +113 -111
- package/dist/server.js.map +1 -1
- package/dist/tool-scopes.d.ts.map +1 -1
- package/dist/tool-scopes.js +0 -3
- package/dist/tool-scopes.js.map +1 -1
- package/dist/tools/a2a.d.ts.map +1 -1
- package/dist/tools/a2a.js +20 -220
- package/dist/tools/a2a.js.map +1 -1
- package/dist/tools/agent-mandates.d.ts.map +1 -1
- package/dist/tools/agent-mandates.js +10 -74
- package/dist/tools/agent-mandates.js.map +1 -1
- package/dist/tools/agents-refs.d.ts.map +1 -1
- package/dist/tools/agents-refs.js +9 -61
- package/dist/tools/agents-refs.js.map +1 -1
- package/dist/tools/capabilities.d.ts.map +1 -1
- package/dist/tools/capabilities.js +2 -14
- package/dist/tools/capabilities.js.map +1 -1
- package/dist/tools/code-mode.d.ts.map +1 -1
- package/dist/tools/code-mode.js +4 -35
- package/dist/tools/code-mode.js.map +1 -1
- package/dist/tools/compliance.d.ts.map +1 -1
- package/dist/tools/compliance.js +3 -37
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/dashboard.d.ts.map +1 -1
- package/dist/tools/dashboard.js +3 -37
- package/dist/tools/dashboard.js.map +1 -1
- package/dist/tools/disputes.d.ts.map +1 -1
- package/dist/tools/disputes.js +4 -41
- package/dist/tools/disputes.js.map +1 -1
- package/dist/tools/enterprises.d.ts.map +1 -1
- package/dist/tools/enterprises.js +6 -62
- package/dist/tools/enterprises.js.map +1 -1
- package/dist/tools/events.d.ts.map +1 -1
- package/dist/tools/events.js +1 -19
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/federation-admin.d.ts.map +1 -1
- package/dist/tools/federation-admin.js +24 -256
- package/dist/tools/federation-admin.js.map +1 -1
- package/dist/tools/federation.d.ts.map +1 -1
- package/dist/tools/federation.js +20 -197
- package/dist/tools/federation.js.map +1 -1
- package/dist/tools/health.d.ts.map +1 -1
- package/dist/tools/health.js +1 -13
- package/dist/tools/health.js.map +1 -1
- package/dist/tools/mandates.d.ts.map +1 -1
- package/dist/tools/mandates.js +10 -93
- package/dist/tools/mandates.js.map +1 -1
- package/dist/tools/openclaw.d.ts.map +1 -1
- package/dist/tools/openclaw.js +5 -32
- package/dist/tools/openclaw.js.map +1 -1
- package/dist/tools/receipts.d.ts.map +1 -1
- package/dist/tools/receipts.js +4 -94
- package/dist/tools/receipts.js.map +1 -1
- package/dist/tools/reputation.d.ts.map +1 -1
- package/dist/tools/reputation.js +3 -33
- package/dist/tools/reputation.js.map +1 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +16 -186
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/verification-keys.d.ts.map +1 -1
- package/dist/tools/verification-keys.js +1 -22
- package/dist/tools/verification-keys.js.map +1 -1
- package/dist/tools/verification.d.ts.map +1 -1
- package/dist/tools/verification.js +2 -27
- package/dist/tools/verification.js.map +1 -1
- package/package.json +2 -3
- package/src/api-client.ts +72 -0
- package/src/index.ts +27 -62
- package/src/server.ts +136 -122
- package/tests/api-client.test.ts +147 -0
- package/tests/harness.ts +8 -35
- package/tests/integration.test.ts +373 -0
- package/tests/server.test.ts +286 -0
- package/src/enums.ts +0 -47
- package/src/errors.ts +0 -44
- package/src/resources/contract-types.ts +0 -130
- package/src/tool-scopes.ts +0 -184
- package/src/tools/a2a.ts +0 -643
- package/src/tools/agent-mandates.ts +0 -325
- package/src/tools/agents-refs.ts +0 -288
- package/src/tools/capabilities.ts +0 -76
- package/src/tools/code-mode.ts +0 -461
- package/src/tools/compliance.ts +0 -104
- package/src/tools/dashboard.ts +0 -98
- package/src/tools/disputes.ts +0 -159
- package/src/tools/enterprises.ts +0 -259
- package/src/tools/events.ts +0 -52
- package/src/tools/federation-admin.ts +0 -922
- package/src/tools/federation.ts +0 -784
- package/src/tools/health.ts +0 -43
- package/src/tools/mandates.ts +0 -349
- package/src/tools/openclaw.ts +0 -168
- package/src/tools/receipts.ts +0 -225
- package/src/tools/reputation.ts +0 -100
- package/src/tools/schemas.ts +0 -713
- package/src/tools/verification-keys.ts +0 -56
- package/src/tools/verification.ts +0 -86
- package/tests/conformance.test.ts +0 -219
- package/tests/conformance.ts +0 -75
- package/tests/drift/code-mode-manifest.test.ts +0 -144
- package/tests/integration/output-schema-validation.test.ts +0 -167
- package/tests/mock-client.ts +0 -71
- package/tests/profiles.test.ts +0 -135
- package/tests/resources/contract-types.test.ts +0 -82
- package/tests/tools/a2a.test.ts +0 -241
- package/tests/tools/agent-mandates.test.ts +0 -206
- package/tests/tools/agents-refs.test.ts +0 -199
- package/tests/tools/capabilities.test.ts +0 -86
- package/tests/tools/code-mode.test.ts +0 -168
- package/tests/tools/compliance.test.ts +0 -131
- package/tests/tools/dashboard.test.ts +0 -120
- package/tests/tools/disputes.test.ts +0 -131
- package/tests/tools/enterprises.test.ts +0 -181
- package/tests/tools/events.test.ts +0 -61
- package/tests/tools/federation-admin.test.ts +0 -509
- package/tests/tools/federation.test.ts +0 -556
- package/tests/tools/health.test.ts +0 -67
- package/tests/tools/mandates.test.ts +0 -155
- package/tests/tools/openclaw.test.ts +0 -160
- package/tests/tools/receipts.test.ts +0 -170
- package/tests/tools/reputation.test.ts +0 -117
- package/tests/tools/schemas.test.ts +0 -397
- package/tests/tools/verification-keys.test.ts +0 -62
- package/tests/tools/verification.test.ts +0 -74
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach, vi } from 'vitest';
|
|
2
|
+
import { ApiClient } from '../src/api-client.js';
|
|
3
|
+
|
|
4
|
+
afterEach(() => {
|
|
5
|
+
vi.unstubAllGlobals();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
describe('ApiClient', () => {
|
|
9
|
+
it('sends authorization header', async () => {
|
|
10
|
+
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
11
|
+
new Response(JSON.stringify({ ok: true }), {
|
|
12
|
+
status: 200,
|
|
13
|
+
headers: { 'content-type': 'application/json' },
|
|
14
|
+
}),
|
|
15
|
+
);
|
|
16
|
+
vi.stubGlobal('fetch', mockFetch);
|
|
17
|
+
|
|
18
|
+
const client = new ApiClient('https://api.test.com', 'my-secret-key');
|
|
19
|
+
await client.request('GET', '/health');
|
|
20
|
+
|
|
21
|
+
const [, options] = mockFetch.mock.calls[0] as [string, RequestInit];
|
|
22
|
+
const headers = options.headers as Record<string, string>;
|
|
23
|
+
expect(headers.Authorization).toBe('Bearer my-secret-key');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('appends query params for GET', async () => {
|
|
27
|
+
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
28
|
+
new Response(JSON.stringify({}), {
|
|
29
|
+
status: 200,
|
|
30
|
+
headers: { 'content-type': 'application/json' },
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
vi.stubGlobal('fetch', mockFetch);
|
|
34
|
+
|
|
35
|
+
const client = new ApiClient('https://api.test.com', 'key');
|
|
36
|
+
await client.request('GET', '/search', { query: { q: 'test', limit: 10 } });
|
|
37
|
+
|
|
38
|
+
const url = new URL(mockFetch.mock.calls[0][0] as string);
|
|
39
|
+
expect(url.searchParams.get('q')).toBe('test');
|
|
40
|
+
expect(url.searchParams.get('limit')).toBe('10');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('skips undefined query params', async () => {
|
|
44
|
+
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
45
|
+
new Response(JSON.stringify({}), {
|
|
46
|
+
status: 200,
|
|
47
|
+
headers: { 'content-type': 'application/json' },
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
vi.stubGlobal('fetch', mockFetch);
|
|
51
|
+
|
|
52
|
+
const client = new ApiClient('https://api.test.com', 'key');
|
|
53
|
+
await client.request('GET', '/search', { query: { q: 'test', missing: undefined } });
|
|
54
|
+
|
|
55
|
+
const url = new URL(mockFetch.mock.calls[0][0] as string);
|
|
56
|
+
expect(url.searchParams.has('missing')).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('sends JSON body for POST', async () => {
|
|
60
|
+
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
61
|
+
new Response(JSON.stringify({ id: '1' }), {
|
|
62
|
+
status: 201,
|
|
63
|
+
headers: { 'content-type': 'application/json' },
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
vi.stubGlobal('fetch', mockFetch);
|
|
67
|
+
|
|
68
|
+
const client = new ApiClient('https://api.test.com', 'key');
|
|
69
|
+
await client.request('POST', '/mandates', { body: { contractType: 'ACH-PROC-v1' } });
|
|
70
|
+
|
|
71
|
+
const [, options] = mockFetch.mock.calls[0] as [string, RequestInit];
|
|
72
|
+
const headers = options.headers as Record<string, string>;
|
|
73
|
+
expect(headers['Content-Type']).toBe('application/json');
|
|
74
|
+
expect(JSON.parse(options.body as string)).toEqual({ contractType: 'ACH-PROC-v1' });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('handles non-JSON responses', async () => {
|
|
78
|
+
vi.stubGlobal(
|
|
79
|
+
'fetch',
|
|
80
|
+
vi.fn().mockResolvedValueOnce(
|
|
81
|
+
new Response('Service Unavailable', {
|
|
82
|
+
status: 503,
|
|
83
|
+
headers: { 'content-type': 'text/plain' },
|
|
84
|
+
}),
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const client = new ApiClient('https://api.test.com', 'key');
|
|
89
|
+
const result = await client.request('GET', '/health');
|
|
90
|
+
|
|
91
|
+
expect(result.ok).toBe(false);
|
|
92
|
+
expect(result.status).toBe(503);
|
|
93
|
+
expect((result.body as Record<string, unknown>)._raw).toBe('Service Unavailable');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('strips trailing slash from base URL', async () => {
|
|
97
|
+
const mockFetch = vi.fn().mockResolvedValueOnce(
|
|
98
|
+
new Response(JSON.stringify({}), {
|
|
99
|
+
status: 200,
|
|
100
|
+
headers: { 'content-type': 'application/json' },
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
vi.stubGlobal('fetch', mockFetch);
|
|
104
|
+
|
|
105
|
+
const client = new ApiClient('https://api.test.com/', 'key');
|
|
106
|
+
await client.request('GET', '/health');
|
|
107
|
+
|
|
108
|
+
const url = mockFetch.mock.calls[0][0] as string;
|
|
109
|
+
expect(url).toBe('https://api.test.com/health');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('sets ok=true for 2xx responses', async () => {
|
|
113
|
+
vi.stubGlobal(
|
|
114
|
+
'fetch',
|
|
115
|
+
vi.fn().mockResolvedValueOnce(
|
|
116
|
+
new Response(JSON.stringify({ id: '1' }), {
|
|
117
|
+
status: 201,
|
|
118
|
+
headers: { 'content-type': 'application/json' },
|
|
119
|
+
}),
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const client = new ApiClient('https://api.test.com', 'key');
|
|
124
|
+
const result = await client.request('POST', '/mandates', { body: {} });
|
|
125
|
+
|
|
126
|
+
expect(result.ok).toBe(true);
|
|
127
|
+
expect(result.status).toBe(201);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('sets ok=false for 4xx/5xx responses', async () => {
|
|
131
|
+
vi.stubGlobal(
|
|
132
|
+
'fetch',
|
|
133
|
+
vi.fn().mockResolvedValueOnce(
|
|
134
|
+
new Response(JSON.stringify({ message: 'Not found' }), {
|
|
135
|
+
status: 404,
|
|
136
|
+
headers: { 'content-type': 'application/json' },
|
|
137
|
+
}),
|
|
138
|
+
),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const client = new ApiClient('https://api.test.com', 'key');
|
|
142
|
+
const result = await client.request('GET', '/mandates/bad');
|
|
143
|
+
|
|
144
|
+
expect(result.ok).toBe(false);
|
|
145
|
+
expect(result.status).toBe(404);
|
|
146
|
+
});
|
|
147
|
+
});
|
package/tests/harness.ts
CHANGED
|
@@ -1,55 +1,28 @@
|
|
|
1
1
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
2
|
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
3
|
-
import {
|
|
4
|
-
import type { AgledgerClient } from '@agledger/sdk';
|
|
5
|
-
import { createMockClient, type MockOverrides } from './mock-client.js';
|
|
3
|
+
import { AgledgerMcpServer } from '../src/server.js';
|
|
6
4
|
|
|
7
5
|
export interface TestHarness {
|
|
8
|
-
/** MCP protocol client — use listTools(), callTool() for real round-trip tests. */
|
|
9
6
|
client: Client;
|
|
10
|
-
/** The mocked SDK client — use for configuring return values and verifying calls. */
|
|
11
|
-
mockSdk: AgledgerClient;
|
|
12
|
-
/** Disconnect both transports. Call in afterAll/afterEach. */
|
|
13
7
|
cleanup: () => Promise<void>;
|
|
14
8
|
}
|
|
15
9
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Create a full MCP Client <-> Server round-trip test harness.
|
|
25
|
-
* Uses InMemoryTransport — no network, no subprocess, full protocol stack.
|
|
26
|
-
*/
|
|
27
|
-
export async function createTestHarness(options: HarnessOptions): Promise<TestHarness> {
|
|
28
|
-
const mockSdk = createMockClient(options.mockOverrides);
|
|
29
|
-
|
|
30
|
-
const mcp = new McpServer(
|
|
31
|
-
{ name: 'test-agledger-mcp', version: '0.0.0-test' },
|
|
32
|
-
{ capabilities: { tools: {}, resources: {} } },
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
for (const fn of options.registerFns) {
|
|
36
|
-
fn(mcp, mockSdk);
|
|
37
|
-
}
|
|
10
|
+
export async function createTestHarness(): Promise<TestHarness> {
|
|
11
|
+
const server = new AgledgerMcpServer({
|
|
12
|
+
apiKey: 'test-key',
|
|
13
|
+
apiUrl: 'https://test.agledger.example.com',
|
|
14
|
+
});
|
|
38
15
|
|
|
39
16
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
40
17
|
const client = new Client({ name: 'test-client', version: '0.0.0-test' });
|
|
41
18
|
|
|
42
|
-
await Promise.all([
|
|
43
|
-
mcp.connect(serverTransport),
|
|
44
|
-
client.connect(clientTransport),
|
|
45
|
-
]);
|
|
19
|
+
await Promise.all([server.mcp.connect(serverTransport), client.connect(clientTransport)]);
|
|
46
20
|
|
|
47
21
|
return {
|
|
48
22
|
client,
|
|
49
|
-
mockSdk,
|
|
50
23
|
cleanup: async () => {
|
|
51
24
|
await client.close();
|
|
52
|
-
await mcp.close();
|
|
25
|
+
await server.mcp.close();
|
|
53
26
|
},
|
|
54
27
|
};
|
|
55
28
|
}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
4
|
+
import { AgledgerMcpServer } from '../src/server.js';
|
|
5
|
+
|
|
6
|
+
const API_URL = process.env.AGLEDGER_API_URL ?? 'http://localhost:3001';
|
|
7
|
+
const API_KEY =
|
|
8
|
+
process.env.AGLEDGER_API_KEY ?? 'ach_age_LduM4xPbgrQZjg_B-SK147ah2gskEN-8d-5xwG8ismM';
|
|
9
|
+
|
|
10
|
+
let client: Client;
|
|
11
|
+
let cleanup: () => Promise<void>;
|
|
12
|
+
let apiReachable = false;
|
|
13
|
+
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
try {
|
|
16
|
+
const res = await fetch(`${API_URL}/health`, { signal: AbortSignal.timeout(3000) });
|
|
17
|
+
apiReachable = res.ok;
|
|
18
|
+
} catch {
|
|
19
|
+
apiReachable = false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!apiReachable) return;
|
|
23
|
+
|
|
24
|
+
const server = new AgledgerMcpServer({ apiKey: API_KEY, apiUrl: API_URL });
|
|
25
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
26
|
+
client = new Client({ name: 'integration-test', version: '0.0.0-test' });
|
|
27
|
+
|
|
28
|
+
await Promise.all([server.mcp.connect(serverTransport), client.connect(clientTransport)]);
|
|
29
|
+
|
|
30
|
+
cleanup = async () => {
|
|
31
|
+
await client.close();
|
|
32
|
+
await server.mcp.close();
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterAll(async () => {
|
|
37
|
+
if (cleanup) await cleanup();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function skipIfNoApi() {
|
|
41
|
+
if (!apiReachable) {
|
|
42
|
+
console.log('Skipping: API not reachable at', API_URL);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('agledger_discover (live)', () => {
|
|
49
|
+
it('returns health and identity', async () => {
|
|
50
|
+
if (skipIfNoApi()) return;
|
|
51
|
+
|
|
52
|
+
const result = await client.callTool({ name: 'agledger_discover', arguments: {} });
|
|
53
|
+
|
|
54
|
+
expect(result.isError).toBeFalsy();
|
|
55
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
56
|
+
|
|
57
|
+
expect(content.health).toBeDefined();
|
|
58
|
+
const health = content.health as Record<string, unknown>;
|
|
59
|
+
expect(health.status).toBe('ok');
|
|
60
|
+
expect(health.version).toBeDefined();
|
|
61
|
+
|
|
62
|
+
expect(content.identity).toBeDefined();
|
|
63
|
+
const identity = content.identity as Record<string, unknown>;
|
|
64
|
+
expect(identity.role).toBeDefined();
|
|
65
|
+
expect(identity.ownerId).toBeDefined();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('enterprise key (live)', () => {
|
|
70
|
+
let entClient: Client;
|
|
71
|
+
let entCleanup: () => Promise<void>;
|
|
72
|
+
|
|
73
|
+
beforeAll(async () => {
|
|
74
|
+
if (!apiReachable) return;
|
|
75
|
+
const entKey = 'ach_ent_sVPW_3Em_nZbX-il0akyT7MKHO5OZI2eKEcaIn6XCMY';
|
|
76
|
+
const server = new AgledgerMcpServer({ apiKey: entKey, apiUrl: API_URL });
|
|
77
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
78
|
+
entClient = new Client({ name: 'ent-test', version: '0.0.0-test' });
|
|
79
|
+
await Promise.all([server.mcp.connect(st), entClient.connect(ct)]);
|
|
80
|
+
entCleanup = async () => {
|
|
81
|
+
await entClient.close();
|
|
82
|
+
await server.mcp.close();
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
afterAll(async () => {
|
|
87
|
+
if (entCleanup) await entCleanup();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('discover works with enterprise key', async () => {
|
|
91
|
+
if (skipIfNoApi()) return;
|
|
92
|
+
const result = await entClient.callTool({ name: 'agledger_discover', arguments: {} });
|
|
93
|
+
expect(result.isError).toBeFalsy();
|
|
94
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
95
|
+
const identity = content.identity as Record<string, unknown>;
|
|
96
|
+
expect(identity.role).toBe('enterprise');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('can list mandates with enterprise key', async () => {
|
|
100
|
+
if (skipIfNoApi()) return;
|
|
101
|
+
const result = await entClient.callTool({
|
|
102
|
+
name: 'agledger_api',
|
|
103
|
+
arguments: { method: 'GET', path: '/v1/mandates', params: { limit: 1 } },
|
|
104
|
+
});
|
|
105
|
+
expect(result.isError).toBeFalsy();
|
|
106
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
107
|
+
expect(content.data).toBeDefined();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('agledger_api (live)', () => {
|
|
112
|
+
it('GET /health', async () => {
|
|
113
|
+
if (skipIfNoApi()) return;
|
|
114
|
+
|
|
115
|
+
const result = await client.callTool({
|
|
116
|
+
name: 'agledger_api',
|
|
117
|
+
arguments: { method: 'GET', path: '/health' },
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(result.isError).toBeFalsy();
|
|
121
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
122
|
+
expect(content.status).toBe('ok');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('GET /v1/auth/me returns identity', async () => {
|
|
126
|
+
if (skipIfNoApi()) return;
|
|
127
|
+
|
|
128
|
+
const result = await client.callTool({
|
|
129
|
+
name: 'agledger_api',
|
|
130
|
+
arguments: { method: 'GET', path: '/v1/auth/me' },
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect(result.isError).toBeFalsy();
|
|
134
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
135
|
+
expect(content.role).toBeDefined();
|
|
136
|
+
expect(content.ownerId).toBeDefined();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('GET /v1/schemas lists contract types', async () => {
|
|
140
|
+
if (skipIfNoApi()) return;
|
|
141
|
+
|
|
142
|
+
const result = await client.callTool({
|
|
143
|
+
name: 'agledger_api',
|
|
144
|
+
arguments: { method: 'GET', path: '/v1/schemas' },
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
expect(result.isError).toBeFalsy();
|
|
148
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
149
|
+
expect(content.data).toBeDefined();
|
|
150
|
+
expect(Array.isArray(content.data)).toBe(true);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('GET /v1/mandates lists mandates', async () => {
|
|
154
|
+
if (skipIfNoApi()) return;
|
|
155
|
+
|
|
156
|
+
const result = await client.callTool({
|
|
157
|
+
name: 'agledger_api',
|
|
158
|
+
arguments: { method: 'GET', path: '/v1/mandates', params: { limit: 5 } },
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
expect(result.isError).toBeFalsy();
|
|
162
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
163
|
+
expect(content.data).toBeDefined();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('POST /v1/mandates/agent creates a mandate', async () => {
|
|
167
|
+
if (skipIfNoApi()) return;
|
|
168
|
+
|
|
169
|
+
const result = await client.callTool({
|
|
170
|
+
name: 'agledger_api',
|
|
171
|
+
arguments: {
|
|
172
|
+
method: 'POST',
|
|
173
|
+
path: '/v1/mandates/agent',
|
|
174
|
+
params: {
|
|
175
|
+
contractType: 'ACH-PROC-v1',
|
|
176
|
+
platform: 'mcp-integration-test',
|
|
177
|
+
criteria: {
|
|
178
|
+
item_spec: 'integration-test-resource',
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(result.isError).toBeFalsy();
|
|
185
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
186
|
+
expect(content.id).toBeDefined();
|
|
187
|
+
expect(content.contractType).toBe('ACH-PROC-v1');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('returns structured error for not-found mandate', async () => {
|
|
191
|
+
if (skipIfNoApi()) return;
|
|
192
|
+
|
|
193
|
+
const result = await client.callTool({
|
|
194
|
+
name: 'agledger_api',
|
|
195
|
+
arguments: { method: 'GET', path: '/v1/mandates/nonexistent-id' },
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
expect(result.isError).toBe(true);
|
|
199
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
200
|
+
expect(content.error ?? content.message).toBeDefined();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('returns structured error with schema help for bad criteria', async () => {
|
|
204
|
+
if (skipIfNoApi()) return;
|
|
205
|
+
|
|
206
|
+
const result = await client.callTool({
|
|
207
|
+
name: 'agledger_api',
|
|
208
|
+
arguments: {
|
|
209
|
+
method: 'POST',
|
|
210
|
+
path: '/v1/mandates/agent',
|
|
211
|
+
params: {
|
|
212
|
+
contractType: 'ACH-PROC-v1',
|
|
213
|
+
platform: 'test',
|
|
214
|
+
criteria: { bad_field: 'wrong' },
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
expect(result.isError).toBe(true);
|
|
220
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
221
|
+
expect(content.requiredFields).toBeDefined();
|
|
222
|
+
expect(content.examplePayload).toBeDefined();
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe('full mandate lifecycle (live)', () => {
|
|
227
|
+
let mandateId: string;
|
|
228
|
+
|
|
229
|
+
it('step 1: create mandate with autoActivate', async () => {
|
|
230
|
+
if (skipIfNoApi()) return;
|
|
231
|
+
|
|
232
|
+
const result = await client.callTool({
|
|
233
|
+
name: 'agledger_api',
|
|
234
|
+
arguments: {
|
|
235
|
+
method: 'POST',
|
|
236
|
+
path: '/v1/mandates/agent',
|
|
237
|
+
params: {
|
|
238
|
+
contractType: 'ACH-PROC-v1',
|
|
239
|
+
platform: 'mcp-lifecycle-test',
|
|
240
|
+
autoActivate: true,
|
|
241
|
+
criteria: {
|
|
242
|
+
item_spec: 'lifecycle-test-widget',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
expect(result.isError).toBeFalsy();
|
|
249
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
250
|
+
mandateId = content.id as string;
|
|
251
|
+
expect(mandateId).toBeDefined();
|
|
252
|
+
expect(content.status).toBe('ACTIVE');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('step 2: get mandate to confirm state', async () => {
|
|
256
|
+
if (skipIfNoApi() || !mandateId) return;
|
|
257
|
+
|
|
258
|
+
const result = await client.callTool({
|
|
259
|
+
name: 'agledger_api',
|
|
260
|
+
arguments: { method: 'GET', path: `/v1/mandates/${mandateId}` },
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
expect(result.isError).toBeFalsy();
|
|
264
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
265
|
+
expect(content.id).toBe(mandateId);
|
|
266
|
+
expect(content.status).toBe('ACTIVE');
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('step 3: submit receipt', async () => {
|
|
270
|
+
if (skipIfNoApi() || !mandateId) return;
|
|
271
|
+
|
|
272
|
+
const result = await client.callTool({
|
|
273
|
+
name: 'agledger_api',
|
|
274
|
+
arguments: {
|
|
275
|
+
method: 'POST',
|
|
276
|
+
path: `/v1/mandates/${mandateId}/receipts`,
|
|
277
|
+
params: {
|
|
278
|
+
evidence: {
|
|
279
|
+
item_secured: 'Lifecycle test widget delivered',
|
|
280
|
+
quantity: 1,
|
|
281
|
+
total_cost: { amount: 10, currency: 'USD' },
|
|
282
|
+
supplier: { id: 'SUP-TEST', name: 'Test Supplier' },
|
|
283
|
+
confirmation_ref: 'MCP-LIFECYCLE-001',
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
expect(result.isError).toBeFalsy();
|
|
290
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
291
|
+
expect(content.id).toBeDefined();
|
|
292
|
+
expect(content.mandateId).toBe(mandateId);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('step 4: check mandate reached terminal state', async () => {
|
|
296
|
+
if (skipIfNoApi() || !mandateId) return;
|
|
297
|
+
|
|
298
|
+
const result = await client.callTool({
|
|
299
|
+
name: 'agledger_api',
|
|
300
|
+
arguments: { method: 'GET', path: `/v1/mandates/${mandateId}` },
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
expect(result.isError).toBeFalsy();
|
|
304
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
305
|
+
const status = content.status as string;
|
|
306
|
+
expect(['FULFILLED', 'VERIFIED_FAIL', 'PROCESSING']).toContain(status);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('step 5: list receipts for mandate', async () => {
|
|
310
|
+
if (skipIfNoApi() || !mandateId) return;
|
|
311
|
+
|
|
312
|
+
const result = await client.callTool({
|
|
313
|
+
name: 'agledger_api',
|
|
314
|
+
arguments: { method: 'GET', path: `/v1/mandates/${mandateId}/receipts` },
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
expect(result.isError).toBeFalsy();
|
|
318
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
319
|
+
const data = content.data as Array<Record<string, unknown>>;
|
|
320
|
+
expect(data.length).toBeGreaterThanOrEqual(1);
|
|
321
|
+
expect(data[0].mandateId).toBe(mandateId);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('step 6: check events for mandate', async () => {
|
|
325
|
+
if (skipIfNoApi() || !mandateId) return;
|
|
326
|
+
|
|
327
|
+
const result = await client.callTool({
|
|
328
|
+
name: 'agledger_api',
|
|
329
|
+
arguments: {
|
|
330
|
+
method: 'GET',
|
|
331
|
+
path: '/v1/events',
|
|
332
|
+
params: { mandateId, limit: 10, since: '2020-01-01T00:00:00Z' },
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
expect(result.isError).toBeFalsy();
|
|
337
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
338
|
+
const data = content.data as Array<Record<string, unknown>>;
|
|
339
|
+
expect(data.length).toBeGreaterThanOrEqual(1);
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe('HTTP method coverage (live)', () => {
|
|
344
|
+
it('DELETE returns structured error for nonexistent webhook', async () => {
|
|
345
|
+
if (skipIfNoApi()) return;
|
|
346
|
+
|
|
347
|
+
const result = await client.callTool({
|
|
348
|
+
name: 'agledger_api',
|
|
349
|
+
arguments: { method: 'DELETE', path: '/v1/webhooks/nonexistent-id' },
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
expect(result.isError).toBe(true);
|
|
353
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
354
|
+
expect(content.error ?? content.message).toBeDefined();
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('PATCH returns structured error for invalid mandate update', async () => {
|
|
358
|
+
if (skipIfNoApi()) return;
|
|
359
|
+
|
|
360
|
+
const result = await client.callTool({
|
|
361
|
+
name: 'agledger_api',
|
|
362
|
+
arguments: {
|
|
363
|
+
method: 'PATCH',
|
|
364
|
+
path: '/v1/mandates/nonexistent-id',
|
|
365
|
+
params: { platform: 'updated' },
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
expect(result.isError).toBe(true);
|
|
370
|
+
const content = result.structuredContent as Record<string, unknown>;
|
|
371
|
+
expect(content.error ?? content.message).toBeDefined();
|
|
372
|
+
});
|
|
373
|
+
});
|