@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.
Files changed (133) hide show
  1. package/dist/api-client.d.ts +16 -0
  2. package/dist/api-client.d.ts.map +1 -0
  3. package/dist/api-client.js +52 -0
  4. package/dist/api-client.js.map +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +17 -60
  7. package/dist/index.js.map +1 -1
  8. package/dist/server.d.ts +2 -13
  9. package/dist/server.d.ts.map +1 -1
  10. package/dist/server.js +113 -111
  11. package/dist/server.js.map +1 -1
  12. package/dist/tool-scopes.d.ts.map +1 -1
  13. package/dist/tool-scopes.js +0 -3
  14. package/dist/tool-scopes.js.map +1 -1
  15. package/dist/tools/a2a.d.ts.map +1 -1
  16. package/dist/tools/a2a.js +20 -220
  17. package/dist/tools/a2a.js.map +1 -1
  18. package/dist/tools/agent-mandates.d.ts.map +1 -1
  19. package/dist/tools/agent-mandates.js +10 -74
  20. package/dist/tools/agent-mandates.js.map +1 -1
  21. package/dist/tools/agents-refs.d.ts.map +1 -1
  22. package/dist/tools/agents-refs.js +9 -61
  23. package/dist/tools/agents-refs.js.map +1 -1
  24. package/dist/tools/capabilities.d.ts.map +1 -1
  25. package/dist/tools/capabilities.js +2 -14
  26. package/dist/tools/capabilities.js.map +1 -1
  27. package/dist/tools/code-mode.d.ts.map +1 -1
  28. package/dist/tools/code-mode.js +4 -35
  29. package/dist/tools/code-mode.js.map +1 -1
  30. package/dist/tools/compliance.d.ts.map +1 -1
  31. package/dist/tools/compliance.js +3 -37
  32. package/dist/tools/compliance.js.map +1 -1
  33. package/dist/tools/dashboard.d.ts.map +1 -1
  34. package/dist/tools/dashboard.js +3 -37
  35. package/dist/tools/dashboard.js.map +1 -1
  36. package/dist/tools/disputes.d.ts.map +1 -1
  37. package/dist/tools/disputes.js +4 -41
  38. package/dist/tools/disputes.js.map +1 -1
  39. package/dist/tools/enterprises.d.ts.map +1 -1
  40. package/dist/tools/enterprises.js +6 -62
  41. package/dist/tools/enterprises.js.map +1 -1
  42. package/dist/tools/events.d.ts.map +1 -1
  43. package/dist/tools/events.js +1 -19
  44. package/dist/tools/events.js.map +1 -1
  45. package/dist/tools/federation-admin.d.ts.map +1 -1
  46. package/dist/tools/federation-admin.js +24 -256
  47. package/dist/tools/federation-admin.js.map +1 -1
  48. package/dist/tools/federation.d.ts.map +1 -1
  49. package/dist/tools/federation.js +20 -197
  50. package/dist/tools/federation.js.map +1 -1
  51. package/dist/tools/health.d.ts.map +1 -1
  52. package/dist/tools/health.js +1 -13
  53. package/dist/tools/health.js.map +1 -1
  54. package/dist/tools/mandates.d.ts.map +1 -1
  55. package/dist/tools/mandates.js +10 -93
  56. package/dist/tools/mandates.js.map +1 -1
  57. package/dist/tools/openclaw.d.ts.map +1 -1
  58. package/dist/tools/openclaw.js +5 -32
  59. package/dist/tools/openclaw.js.map +1 -1
  60. package/dist/tools/receipts.d.ts.map +1 -1
  61. package/dist/tools/receipts.js +4 -94
  62. package/dist/tools/receipts.js.map +1 -1
  63. package/dist/tools/reputation.d.ts.map +1 -1
  64. package/dist/tools/reputation.js +3 -33
  65. package/dist/tools/reputation.js.map +1 -1
  66. package/dist/tools/schemas.d.ts.map +1 -1
  67. package/dist/tools/schemas.js +16 -186
  68. package/dist/tools/schemas.js.map +1 -1
  69. package/dist/tools/verification-keys.d.ts.map +1 -1
  70. package/dist/tools/verification-keys.js +1 -22
  71. package/dist/tools/verification-keys.js.map +1 -1
  72. package/dist/tools/verification.d.ts.map +1 -1
  73. package/dist/tools/verification.js +2 -27
  74. package/dist/tools/verification.js.map +1 -1
  75. package/package.json +2 -3
  76. package/src/api-client.ts +72 -0
  77. package/src/index.ts +27 -62
  78. package/src/server.ts +136 -122
  79. package/tests/api-client.test.ts +147 -0
  80. package/tests/harness.ts +8 -35
  81. package/tests/integration.test.ts +373 -0
  82. package/tests/server.test.ts +286 -0
  83. package/src/enums.ts +0 -47
  84. package/src/errors.ts +0 -44
  85. package/src/resources/contract-types.ts +0 -130
  86. package/src/tool-scopes.ts +0 -184
  87. package/src/tools/a2a.ts +0 -643
  88. package/src/tools/agent-mandates.ts +0 -325
  89. package/src/tools/agents-refs.ts +0 -288
  90. package/src/tools/capabilities.ts +0 -76
  91. package/src/tools/code-mode.ts +0 -461
  92. package/src/tools/compliance.ts +0 -104
  93. package/src/tools/dashboard.ts +0 -98
  94. package/src/tools/disputes.ts +0 -159
  95. package/src/tools/enterprises.ts +0 -259
  96. package/src/tools/events.ts +0 -52
  97. package/src/tools/federation-admin.ts +0 -922
  98. package/src/tools/federation.ts +0 -784
  99. package/src/tools/health.ts +0 -43
  100. package/src/tools/mandates.ts +0 -349
  101. package/src/tools/openclaw.ts +0 -168
  102. package/src/tools/receipts.ts +0 -225
  103. package/src/tools/reputation.ts +0 -100
  104. package/src/tools/schemas.ts +0 -713
  105. package/src/tools/verification-keys.ts +0 -56
  106. package/src/tools/verification.ts +0 -86
  107. package/tests/conformance.test.ts +0 -219
  108. package/tests/conformance.ts +0 -75
  109. package/tests/drift/code-mode-manifest.test.ts +0 -144
  110. package/tests/integration/output-schema-validation.test.ts +0 -167
  111. package/tests/mock-client.ts +0 -71
  112. package/tests/profiles.test.ts +0 -135
  113. package/tests/resources/contract-types.test.ts +0 -82
  114. package/tests/tools/a2a.test.ts +0 -241
  115. package/tests/tools/agent-mandates.test.ts +0 -206
  116. package/tests/tools/agents-refs.test.ts +0 -199
  117. package/tests/tools/capabilities.test.ts +0 -86
  118. package/tests/tools/code-mode.test.ts +0 -168
  119. package/tests/tools/compliance.test.ts +0 -131
  120. package/tests/tools/dashboard.test.ts +0 -120
  121. package/tests/tools/disputes.test.ts +0 -131
  122. package/tests/tools/enterprises.test.ts +0 -181
  123. package/tests/tools/events.test.ts +0 -61
  124. package/tests/tools/federation-admin.test.ts +0 -509
  125. package/tests/tools/federation.test.ts +0 -556
  126. package/tests/tools/health.test.ts +0 -67
  127. package/tests/tools/mandates.test.ts +0 -155
  128. package/tests/tools/openclaw.test.ts +0 -160
  129. package/tests/tools/receipts.test.ts +0 -170
  130. package/tests/tools/reputation.test.ts +0 -117
  131. package/tests/tools/schemas.test.ts +0 -397
  132. package/tests/tools/verification-keys.test.ts +0 -62
  133. package/tests/tools/verification.test.ts +0 -74
@@ -1,167 +0,0 @@
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
- });
@@ -1,71 +0,0 @@
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
- }
@@ -1,135 +0,0 @@
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
- });
@@ -1,82 +0,0 @@
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
- });