@agledger/mcp-server 1.4.1 → 1.4.3
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/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +8 -0
- package/dist/errors.js.map +1 -1
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +72 -75
- package/dist/server.js.map +1 -1
- package/dist/tool-scopes.d.ts.map +1 -1
- package/dist/tool-scopes.js +6 -2
- package/dist/tool-scopes.js.map +1 -1
- package/dist/tools/a2a.js +15 -15
- package/dist/tools/a2a.js.map +1 -1
- package/dist/tools/agent-mandates.js +10 -10
- 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 +10 -9
- package/dist/tools/agents-refs.js.map +1 -1
- package/dist/tools/capabilities.js +3 -3
- package/dist/tools/capabilities.js.map +1 -1
- package/dist/tools/compliance.d.ts.map +1 -1
- package/dist/tools/compliance.js +29 -4
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/dashboard.d.ts.map +1 -1
- package/dist/tools/dashboard.js +29 -4
- package/dist/tools/dashboard.js.map +1 -1
- package/dist/tools/disputes.d.ts.map +1 -1
- package/dist/tools/disputes.js +10 -5
- package/dist/tools/disputes.js.map +1 -1
- package/dist/tools/enterprises.d.ts.map +1 -1
- package/dist/tools/enterprises.js +30 -6
- package/dist/tools/enterprises.js.map +1 -1
- package/dist/tools/events.js +2 -2
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/federation-admin.js +25 -25
- package/dist/tools/federation-admin.js.map +1 -1
- package/dist/tools/federation.js +21 -21
- package/dist/tools/federation.js.map +1 -1
- package/dist/tools/health.js +2 -2
- package/dist/tools/health.js.map +1 -1
- package/dist/tools/mandates.d.ts.map +1 -1
- package/dist/tools/mandates.js +25 -14
- package/dist/tools/mandates.js.map +1 -1
- package/dist/tools/openclaw.js +6 -6
- package/dist/tools/openclaw.js.map +1 -1
- package/dist/tools/receipts.d.ts.map +1 -1
- package/dist/tools/receipts.js +5 -6
- package/dist/tools/receipts.js.map +1 -1
- package/dist/tools/reputation.d.ts.map +1 -1
- package/dist/tools/reputation.js +25 -4
- package/dist/tools/reputation.js.map +1 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +71 -26
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/verification-keys.js +2 -2
- package/dist/tools/verification-keys.js.map +1 -1
- package/dist/tools/verification.js +3 -3
- package/dist/tools/verification.js.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +9 -0
- package/src/server.ts +76 -68
- package/src/tool-scopes.ts +7 -3
- package/src/tools/a2a.ts +15 -15
- package/src/tools/agent-mandates.ts +10 -10
- package/src/tools/agents-refs.ts +10 -9
- package/src/tools/capabilities.ts +3 -3
- package/src/tools/compliance.ts +29 -4
- package/src/tools/dashboard.ts +29 -4
- package/src/tools/disputes.ts +10 -5
- package/src/tools/enterprises.ts +30 -6
- package/src/tools/events.ts +2 -2
- package/src/tools/federation-admin.ts +25 -25
- package/src/tools/federation.ts +21 -21
- package/src/tools/health.ts +2 -2
- package/src/tools/mandates.ts +25 -14
- package/src/tools/openclaw.ts +6 -6
- package/src/tools/receipts.ts +5 -6
- package/src/tools/reputation.ts +26 -4
- package/src/tools/schemas.ts +72 -26
- package/src/tools/verification-keys.ts +2 -2
- package/src/tools/verification.ts +3 -3
- package/tests/conformance.test.ts +219 -0
- package/tests/conformance.ts +75 -0
- package/tests/{code-mode-manifest.test.ts → drift/code-mode-manifest.test.ts} +2 -2
- package/tests/harness.ts +55 -0
- package/tests/integration/output-schema-validation.test.ts +167 -0
- package/tests/mock-client.ts +71 -0
- package/tests/profiles.test.ts +135 -0
- package/tests/resources/contract-types.test.ts +82 -0
- package/tests/tools/a2a.test.ts +241 -0
- package/tests/tools/agent-mandates.test.ts +206 -0
- package/tests/tools/agents-refs.test.ts +199 -0
- package/tests/tools/capabilities.test.ts +86 -0
- package/tests/tools/code-mode.test.ts +168 -0
- package/tests/tools/compliance.test.ts +131 -0
- package/tests/tools/dashboard.test.ts +120 -0
- package/tests/tools/disputes.test.ts +131 -0
- package/tests/tools/enterprises.test.ts +181 -0
- package/tests/tools/events.test.ts +61 -0
- package/tests/tools/federation-admin.test.ts +509 -0
- package/tests/tools/federation.test.ts +556 -0
- package/tests/tools/health.test.ts +67 -0
- package/tests/tools/mandates.test.ts +155 -0
- package/tests/tools/openclaw.test.ts +160 -0
- package/tests/tools/receipts.test.ts +170 -0
- package/tests/tools/reputation.test.ts +117 -0
- package/tests/tools/schemas.test.ts +397 -0
- package/tests/tools/verification-keys.test.ts +62 -0
- package/tests/tools/verification.test.ts +74 -0
- package/tests/enterprises.test.ts +0 -96
- package/tests/schemas.test.ts +0 -531
package/tests/harness.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
import type { AgledgerClient } from '@agledger/sdk';
|
|
5
|
+
import { createMockClient, type MockOverrides } from './mock-client.js';
|
|
6
|
+
|
|
7
|
+
export interface TestHarness {
|
|
8
|
+
/** MCP protocol client — use listTools(), callTool() for real round-trip tests. */
|
|
9
|
+
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
|
+
cleanup: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface HarnessOptions {
|
|
17
|
+
/** Tool registration functions to invoke. Each receives (mcp, client). */
|
|
18
|
+
registerFns: Array<(mcp: McpServer, client: AgledgerClient) => void>;
|
|
19
|
+
/** SDK mock overrides. */
|
|
20
|
+
mockOverrides?: MockOverrides;
|
|
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
|
+
}
|
|
38
|
+
|
|
39
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
40
|
+
const client = new Client({ name: 'test-client', version: '0.0.0-test' });
|
|
41
|
+
|
|
42
|
+
await Promise.all([
|
|
43
|
+
mcp.connect(serverTransport),
|
|
44
|
+
client.connect(clientTransport),
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
client,
|
|
49
|
+
mockSdk,
|
|
50
|
+
cleanup: async () => {
|
|
51
|
+
await client.close();
|
|
52
|
+
await mcp.close();
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test: validate MCP tool outputSchemas against real API responses.
|
|
3
|
+
*
|
|
4
|
+
* Connects the MCP server to a live AGLedger API, calls tools that hit real endpoints,
|
|
5
|
+
* and verifies structuredContent passes the MCP SDK's outputSchema validation.
|
|
6
|
+
*
|
|
7
|
+
* Auto-skips when the API is unreachable (no AGLEDGER_TEST_API_URL or connection refused).
|
|
8
|
+
*
|
|
9
|
+
* Environment:
|
|
10
|
+
* AGLEDGER_TEST_API_URL - API base URL (default: http://localhost:3001)
|
|
11
|
+
* AGLEDGER_TEST_API_KEY - Enterprise API key with standard scopes
|
|
12
|
+
*/
|
|
13
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
14
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
15
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
16
|
+
import { AgledgerMcpServer } from '../../src/server.js';
|
|
17
|
+
|
|
18
|
+
const API_URL = process.env['AGLEDGER_TEST_API_URL'] || 'http://localhost:3001';
|
|
19
|
+
const API_KEY = process.env['AGLEDGER_TEST_API_KEY'] || '';
|
|
20
|
+
|
|
21
|
+
async function isApiReachable(): Promise<boolean> {
|
|
22
|
+
try {
|
|
23
|
+
const res = await fetch(`${API_URL}/health`, { signal: AbortSignal.timeout(3000) });
|
|
24
|
+
return res.ok;
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('outputSchema vs real API responses', async () => {
|
|
31
|
+
const reachable = await isApiReachable();
|
|
32
|
+
if (!reachable || !API_KEY) {
|
|
33
|
+
it.skip('API not reachable or AGLEDGER_TEST_API_KEY not set', () => {});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let client: Client;
|
|
38
|
+
let cleanup: () => Promise<void>;
|
|
39
|
+
let enterpriseId: string;
|
|
40
|
+
|
|
41
|
+
// Track created resources for cleanup
|
|
42
|
+
let createdMandateId: string | undefined;
|
|
43
|
+
|
|
44
|
+
beforeAll(async () => {
|
|
45
|
+
// Discover enterprise ID from auth/me
|
|
46
|
+
const meRes = await fetch(`${API_URL}/v1/auth/me`, { headers: { Authorization: `Bearer ${API_KEY}` } });
|
|
47
|
+
const me = await meRes.json() as Record<string, unknown>;
|
|
48
|
+
enterpriseId = (me.ownerId ?? me.enterpriseId ?? '') as string;
|
|
49
|
+
const server = new AgledgerMcpServer({
|
|
50
|
+
apiKey: API_KEY,
|
|
51
|
+
apiUrl: API_URL,
|
|
52
|
+
profile: 'full',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
56
|
+
client = new Client({ name: 'integration-test', version: '0.0.0' });
|
|
57
|
+
await Promise.all([server.mcp.connect(st), client.connect(ct)]);
|
|
58
|
+
|
|
59
|
+
cleanup = async () => {
|
|
60
|
+
// Cancel any created mandates
|
|
61
|
+
if (createdMandateId) {
|
|
62
|
+
try {
|
|
63
|
+
await client.callTool({ name: 'cancel_mandate', arguments: { mandateId: createdMandateId, reason: 'integration test cleanup' } });
|
|
64
|
+
} catch { /* best effort */ }
|
|
65
|
+
}
|
|
66
|
+
await client.close();
|
|
67
|
+
await server.mcp.close();
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterAll(async () => { await cleanup(); });
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Helper: call a tool and assert it succeeds (no isError, no MCP validation error).
|
|
75
|
+
* The MCP SDK validates structuredContent against outputSchema automatically —
|
|
76
|
+
* if the real API response doesn't match our schema, this throws.
|
|
77
|
+
*/
|
|
78
|
+
async function callAndExpectSuccess(name: string, args: Record<string, unknown>): Promise<any> {
|
|
79
|
+
const result = await client.callTool({ name, arguments: args });
|
|
80
|
+
const r = result as any;
|
|
81
|
+
if (r.isError) {
|
|
82
|
+
const text = r.content?.[0]?.text ?? '';
|
|
83
|
+
// Permission errors are expected for some tools — don't fail
|
|
84
|
+
if (text.includes('Insufficient scopes') || text.includes('not approved')) {
|
|
85
|
+
return { skipped: true, reason: text };
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`Tool ${name} returned error: ${text.slice(0, 300)}`);
|
|
88
|
+
}
|
|
89
|
+
return r;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// --- Read-only tools that work without prior state ---
|
|
93
|
+
|
|
94
|
+
it('check_api_health: response matches outputSchema', async () => {
|
|
95
|
+
const result = await callAndExpectSuccess('check_api_health', {});
|
|
96
|
+
expect(result.content[0].text).toContain('status=');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('list_contract_schemas: response matches outputSchema', async () => {
|
|
100
|
+
const result = await callAndExpectSuccess('list_contract_schemas', {});
|
|
101
|
+
expect(result.content[0].text).toMatch(/\d+ contract type/);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('get_contract_schema: response matches outputSchema', async () => {
|
|
105
|
+
const result = await callAndExpectSuccess('get_contract_schema', { contractType: 'ACH-PROC-v1' });
|
|
106
|
+
expect(result.content[0].text).toContain('ACH-PROC-v1');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('get_meta_schema: response matches outputSchema', async () => {
|
|
110
|
+
const result = await callAndExpectSuccess('get_meta_schema', {});
|
|
111
|
+
expect(result.content[0].text).toBeTruthy();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('search_mandates: response matches outputSchema', async () => {
|
|
115
|
+
const result = await callAndExpectSuccess('search_mandates', { enterpriseId });
|
|
116
|
+
expect(result.content[0].text).toContain('mandates');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('get_mandate_summary: response matches outputSchema', async () => {
|
|
120
|
+
const result = await callAndExpectSuccess('get_mandate_summary', {});
|
|
121
|
+
expect(result.content[0].text).toBeTruthy();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('list_verification_keys: response matches outputSchema', async () => {
|
|
125
|
+
const result = await callAndExpectSuccess('list_verification_keys', {});
|
|
126
|
+
expect(result.content[0].text).toBeTruthy();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// --- Schema tools ---
|
|
130
|
+
|
|
131
|
+
it('get_schema_template: response matches outputSchema', async () => {
|
|
132
|
+
const result = await callAndExpectSuccess('get_schema_template', { contractType: 'ACH-PROC-v1' });
|
|
133
|
+
expect(result.content[0].text).toContain('template');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('get_blank_schema_template: response matches outputSchema', async () => {
|
|
137
|
+
const result = await callAndExpectSuccess('get_blank_schema_template', {});
|
|
138
|
+
expect(result.content[0].text).toContain('template');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('get_schema_versions: response matches outputSchema', async () => {
|
|
142
|
+
const result = await callAndExpectSuccess('get_schema_versions', { contractType: 'ACH-PROC-v1' });
|
|
143
|
+
expect(result.content[0].text).toBeTruthy();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('get_schema_rules: response matches outputSchema', async () => {
|
|
147
|
+
const result = await callAndExpectSuccess('get_schema_rules', { contractType: 'ACH-PROC-v1' });
|
|
148
|
+
expect(result.content[0].text).toBeTruthy();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// --- Dashboard ---
|
|
152
|
+
|
|
153
|
+
it('get_dashboard_summary: response matches outputSchema', async () => {
|
|
154
|
+
const result = await callAndExpectSuccess('get_dashboard_summary', {});
|
|
155
|
+
expect(result.content[0].text).toBeTruthy();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('get_dashboard_metrics: response matches outputSchema', async () => {
|
|
159
|
+
const result = await callAndExpectSuccess('get_dashboard_metrics', {});
|
|
160
|
+
expect(result.content[0].text).toBeTruthy();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('get_dashboard_alerts: response matches outputSchema', async () => {
|
|
164
|
+
const result = await callAndExpectSuccess('get_dashboard_alerts', {});
|
|
165
|
+
expect(result.content[0].text).toBeTruthy();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import type { AgledgerClient } from '@agledger/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a stub resource where every property is a vi.fn() that rejects by default.
|
|
6
|
+
* Callers override specific methods with mockResolvedValue/mockRejectedValue as needed.
|
|
7
|
+
*/
|
|
8
|
+
function stubResource(name: string): Record<string, ReturnType<typeof vi.fn>> {
|
|
9
|
+
return new Proxy({} as Record<string, ReturnType<typeof vi.fn>>, {
|
|
10
|
+
get(target, prop: string) {
|
|
11
|
+
if (!(prop in target)) {
|
|
12
|
+
target[prop] = vi.fn().mockRejectedValue(
|
|
13
|
+
new Error(`${name}.${prop}() not mocked`),
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return target[prop];
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface MockOverrides {
|
|
22
|
+
mandates?: Record<string, unknown>;
|
|
23
|
+
receipts?: Record<string, unknown>;
|
|
24
|
+
verification?: Record<string, unknown>;
|
|
25
|
+
disputes?: Record<string, unknown>;
|
|
26
|
+
webhooks?: Record<string, unknown>;
|
|
27
|
+
reputation?: Record<string, unknown>;
|
|
28
|
+
events?: Record<string, unknown>;
|
|
29
|
+
schemas?: Record<string, unknown>;
|
|
30
|
+
dashboard?: Record<string, unknown>;
|
|
31
|
+
compliance?: Record<string, unknown>;
|
|
32
|
+
registration?: Record<string, unknown>;
|
|
33
|
+
health?: Record<string, unknown>;
|
|
34
|
+
proxy?: Record<string, unknown>;
|
|
35
|
+
admin?: Record<string, unknown>;
|
|
36
|
+
a2a?: Record<string, unknown>;
|
|
37
|
+
capabilities?: Record<string, unknown>;
|
|
38
|
+
notarize?: Record<string, unknown>;
|
|
39
|
+
enterprises?: Record<string, unknown>;
|
|
40
|
+
projects?: Record<string, unknown>;
|
|
41
|
+
federation?: Record<string, unknown>;
|
|
42
|
+
federationAdmin?: Record<string, unknown>;
|
|
43
|
+
agents?: Record<string, unknown>;
|
|
44
|
+
references?: Record<string, unknown>;
|
|
45
|
+
verificationKeys?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const RESOURCE_NAMES = [
|
|
49
|
+
'mandates', 'receipts', 'verification', 'disputes', 'webhooks',
|
|
50
|
+
'reputation', 'events', 'schemas', 'dashboard', 'compliance',
|
|
51
|
+
'registration', 'health', 'proxy', 'admin', 'a2a', 'capabilities',
|
|
52
|
+
'notarize', 'enterprises', 'projects', 'federation', 'federationAdmin',
|
|
53
|
+
'agents', 'references', 'verificationKeys',
|
|
54
|
+
] as const;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create a mock AgledgerClient with all 24 resource stubs.
|
|
58
|
+
* Every method rejects by default; pass overrides to configure specific methods.
|
|
59
|
+
*/
|
|
60
|
+
export function createMockClient(overrides?: MockOverrides): AgledgerClient {
|
|
61
|
+
const client: Record<string, unknown> = {};
|
|
62
|
+
for (const name of RESOURCE_NAMES) {
|
|
63
|
+
const resource = stubResource(name);
|
|
64
|
+
const resourceOverrides = overrides?.[name];
|
|
65
|
+
if (resourceOverrides) {
|
|
66
|
+
Object.assign(resource, resourceOverrides);
|
|
67
|
+
}
|
|
68
|
+
client[name] = resource;
|
|
69
|
+
}
|
|
70
|
+
return client as unknown as AgledgerClient;
|
|
71
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { describe, it, expect, afterAll } from 'vitest';
|
|
2
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
4
|
+
import { AgledgerMcpServer, type ToolProfile } from '../src/server.js';
|
|
5
|
+
import { TOOL_SCOPES } from '../src/tool-scopes.js';
|
|
6
|
+
import { assertOutputSchemaValid, assertToolMetadata } from './conformance.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a full AgledgerMcpServer (not just individual register functions)
|
|
10
|
+
* connected via InMemoryTransport. Tests the real server constructor + profile routing.
|
|
11
|
+
*/
|
|
12
|
+
async function createProfileHarness(profile: ToolProfile) {
|
|
13
|
+
const server = new AgledgerMcpServer({
|
|
14
|
+
apiKey: 'test-key',
|
|
15
|
+
apiUrl: 'https://test.example.com',
|
|
16
|
+
profile,
|
|
17
|
+
enterpriseId: 'test-enterprise',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
21
|
+
const client = new Client({ name: 'profile-test', version: '0.0.0' });
|
|
22
|
+
|
|
23
|
+
await Promise.all([
|
|
24
|
+
server.mcp.connect(serverTransport),
|
|
25
|
+
client.connect(clientTransport),
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
client,
|
|
30
|
+
cleanup: async () => {
|
|
31
|
+
await client.close();
|
|
32
|
+
await server.mcp.close();
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Expected tool counts per profile — update these when adding/removing tools.
|
|
38
|
+
// Exact tool names are validated in per-module tests; here we guard against accidental drift.
|
|
39
|
+
const EXPECTED_TOOL_COUNTS: Record<ToolProfile, number> = {
|
|
40
|
+
code: 2,
|
|
41
|
+
openclaw: 5,
|
|
42
|
+
agent: -1, // populated dynamically below
|
|
43
|
+
'schema-dev': -1,
|
|
44
|
+
admin: -1,
|
|
45
|
+
federation: -1,
|
|
46
|
+
audit: -1,
|
|
47
|
+
full: -1,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const ALL_PROFILES: ToolProfile[] = ['code', 'openclaw', 'agent', 'schema-dev', 'admin', 'federation', 'audit', 'full'];
|
|
51
|
+
|
|
52
|
+
describe('profile tool registration', () => {
|
|
53
|
+
const cleanups: Array<() => Promise<void>> = [];
|
|
54
|
+
|
|
55
|
+
afterAll(async () => {
|
|
56
|
+
for (const cleanup of cleanups) {
|
|
57
|
+
await cleanup();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
for (const profile of ALL_PROFILES) {
|
|
62
|
+
describe(`${profile} profile`, () => {
|
|
63
|
+
let tools: Array<{ name: string; description?: string; inputSchema?: unknown; outputSchema?: unknown; annotations?: unknown; _meta?: unknown }>;
|
|
64
|
+
|
|
65
|
+
it('connects and lists tools', async () => {
|
|
66
|
+
const harness = await createProfileHarness(profile);
|
|
67
|
+
cleanups.push(harness.cleanup);
|
|
68
|
+
const result = await harness.client.listTools();
|
|
69
|
+
tools = result.tools as typeof tools;
|
|
70
|
+
expect(tools.length).toBeGreaterThan(0);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('has no duplicate tool names', () => {
|
|
74
|
+
const names = tools.map(t => t.name);
|
|
75
|
+
const uniqueNames = new Set(names);
|
|
76
|
+
expect(names.length, `Duplicate tools in ${profile}: ${names.filter((n, i) => names.indexOf(n) !== i).join(', ')}`).toBe(uniqueNames.size);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('tools with outputSchema have valid schema structure', () => {
|
|
80
|
+
for (const tool of tools) {
|
|
81
|
+
if (tool.outputSchema) {
|
|
82
|
+
assertOutputSchemaValid(tool as any);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('every tool has valid metadata', () => {
|
|
88
|
+
for (const tool of tools) {
|
|
89
|
+
assertToolMetadata(tool as any);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (profile === 'code') {
|
|
94
|
+
it('registers exactly 2 tools: sdk_execute and sdk_describe', () => {
|
|
95
|
+
expect(tools.map(t => t.name).sort()).toEqual(['sdk_describe', 'sdk_execute']);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (profile === 'openclaw') {
|
|
100
|
+
it('registers exactly 5 openclaw tools', () => {
|
|
101
|
+
expect(tools.length).toBe(5);
|
|
102
|
+
for (const tool of tools) {
|
|
103
|
+
expect(tool.name).toMatch(/^agledger_/);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (profile === 'agent') {
|
|
109
|
+
it('does not include submit_receipt from receipts module (skipSubmit)', () => {
|
|
110
|
+
const names = tools.map(t => t.name);
|
|
111
|
+
// a2a module has its own submit_receipt, but receipts module's is skipped
|
|
112
|
+
const submitCount = names.filter(n => n === 'submit_receipt').length;
|
|
113
|
+
expect(submitCount).toBeLessThanOrEqual(1);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
it('every registered tool across all profiles has a TOOL_SCOPES entry', async () => {
|
|
120
|
+
const allRegisteredNames = new Set<string>();
|
|
121
|
+
for (const profile of ALL_PROFILES) {
|
|
122
|
+
const harness = await createProfileHarness(profile);
|
|
123
|
+
cleanups.push(harness.cleanup);
|
|
124
|
+
const { tools } = await harness.client.listTools();
|
|
125
|
+
for (const t of tools) allRegisteredNames.add((t as any).name);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const missingFromScopes = [...allRegisteredNames].filter(name => !TOOL_SCOPES[name]);
|
|
129
|
+
expect(missingFromScopes, `Registered tools without TOOL_SCOPES entry: ${missingFromScopes.join(', ')}`).toEqual([]);
|
|
130
|
+
|
|
131
|
+
const scopeNames = Object.keys(TOOL_SCOPES);
|
|
132
|
+
const missingFromProfiles = scopeNames.filter(name => !allRegisteredNames.has(name));
|
|
133
|
+
expect(missingFromProfiles, `TOOL_SCOPES entries not registered in any profile: ${missingFromProfiles.join(', ')}`).toEqual([]);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
|
|
2
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
4
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
import { registerContractTypeResources } from '../../src/resources/contract-types.js';
|
|
6
|
+
import { createMockClient } from '../mock-client.js';
|
|
7
|
+
|
|
8
|
+
describe('contract-types resources', () => {
|
|
9
|
+
let client: Client;
|
|
10
|
+
let cleanup: () => Promise<void>;
|
|
11
|
+
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
const mockSdk = createMockClient({
|
|
14
|
+
schemas: {
|
|
15
|
+
get: vi.fn().mockResolvedValue({
|
|
16
|
+
contractType: 'ACH-PROC-v1',
|
|
17
|
+
mandateSchema: { type: 'object', properties: { item: { type: 'string' } } },
|
|
18
|
+
receiptSchema: { type: 'object', properties: { evidence: { type: 'object' } } },
|
|
19
|
+
rulesConfig: { tolerance: {} },
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const mcp = new McpServer(
|
|
25
|
+
{ name: 'test-resources', version: '0.0.0' },
|
|
26
|
+
{ capabilities: { resources: {} } },
|
|
27
|
+
);
|
|
28
|
+
registerContractTypeResources(mcp, mockSdk);
|
|
29
|
+
|
|
30
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
31
|
+
client = new Client({ name: 'test-client', version: '0.0.0' });
|
|
32
|
+
await Promise.all([mcp.connect(serverTransport), client.connect(clientTransport)]);
|
|
33
|
+
|
|
34
|
+
cleanup = async () => {
|
|
35
|
+
await client.close();
|
|
36
|
+
await mcp.close();
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterAll(async () => { await cleanup(); });
|
|
41
|
+
|
|
42
|
+
describe('static resource: schema://contract-types', () => {
|
|
43
|
+
it('lists the static contract-types resource', async () => {
|
|
44
|
+
const { resources } = await client.listResources();
|
|
45
|
+
expect(resources.some(r => r.uri === 'schema://contract-types')).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('returns all 13 contract types', async () => {
|
|
49
|
+
const result = await client.readResource({ uri: 'schema://contract-types' });
|
|
50
|
+
const content = result.contents[0];
|
|
51
|
+
expect(content.mimeType).toBe('application/json');
|
|
52
|
+
const types = JSON.parse(content.text as string);
|
|
53
|
+
expect(types.length).toBe(13);
|
|
54
|
+
expect(types[0].type).toBe('ACH-PROC-v1');
|
|
55
|
+
expect(types[0].description).toBeTruthy();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('template resource: schema://contract-types/{type}', () => {
|
|
60
|
+
it('lists resource templates', async () => {
|
|
61
|
+
const { resourceTemplates } = await client.listResourceTemplates();
|
|
62
|
+
expect(resourceTemplates.some(t => t.uriTemplate === 'schema://contract-types/{type}')).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('returns schema for a valid contract type', async () => {
|
|
66
|
+
const result = await client.readResource({ uri: 'schema://contract-types/ACH-PROC-v1' });
|
|
67
|
+
const content = result.contents[0];
|
|
68
|
+
expect(content.mimeType).toBe('application/json');
|
|
69
|
+
const schema = JSON.parse(content.text as string);
|
|
70
|
+
expect(schema.contractType).toBe('ACH-PROC-v1');
|
|
71
|
+
expect(schema.mandateSchema).toBeDefined();
|
|
72
|
+
expect(schema.receiptSchema).toBeDefined();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('returns error for unknown contract type', async () => {
|
|
76
|
+
const result = await client.readResource({ uri: 'schema://contract-types/ACH-BAD-v1' });
|
|
77
|
+
const content = result.contents[0];
|
|
78
|
+
const data = JSON.parse(content.text as string);
|
|
79
|
+
expect(data.error).toContain('Unknown contract type');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|