@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,56 +0,0 @@
1
- import { z } from 'zod';
2
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult, toStructuredContent } from '../errors.js';
5
- import { toolMeta } from '../tool-scopes.js';
6
-
7
- const VerificationKeySchema = z.object({
8
- keyId: z.string().describe('Unique key identifier'),
9
- algorithm: z.string().describe('Signing algorithm (e.g. Ed25519)'),
10
- publicKey: z.string().describe('Base64-encoded public key'),
11
- status: z.string().describe('Key status: active or retired'),
12
- activatedAt: z.string().describe('Date the key was activated (YYYY-MM-DD)'),
13
- retiredAt: z.string().nullable().describe('Date the key was retired, or null if active'),
14
- });
15
-
16
- const VerificationKeysOutputSchema = z.object({
17
- data: z.array(VerificationKeySchema).describe('Vault signing public keys'),
18
- canonicalization: z.string().describe('Canonicalization standard (e.g. RFC8785)'),
19
- hashAlgorithm: z.string().describe('Hash algorithm used in audit chain'),
20
- signatureAlgorithm: z.string().describe('Signature algorithm for audit entries'),
21
- }).describe('Vault signing public keys for independent audit chain verification');
22
-
23
- export function registerVerificationKeysTools(mcp: McpServer, client: AgledgerClient): void {
24
- mcp.registerTool(
25
- 'list_verification_keys',
26
- {
27
- title: 'List Verification Keys',
28
- description:
29
- 'List all vault signing public keys (active and retired) for independent audit chain verification. ' +
30
- 'No authentication required. Use these keys to verify Ed25519 signatures on audit chain exports. ' +
31
- 'Next step: fetch an audit export with `export_mandate_audit` and verify signatures locally.',
32
- inputSchema: {},
33
- outputSchema: VerificationKeysOutputSchema,
34
- annotations: {
35
- readOnlyHint: true,
36
- destructiveHint: false,
37
- idempotentHint: true,
38
- openWorldHint: true,
39
- },
40
- _meta: toolMeta('list_verification_keys'),
41
- },
42
- async () => {
43
- try {
44
- const result = await client.verificationKeys.list();
45
- const count = result.data.length;
46
- const active = result.data.filter((k) => k.status === 'active').length;
47
- return {
48
- content: [{ type: 'text', text: `${count} verification key(s): ${active} active, ${count - active} retired. Algorithm: ${result.signatureAlgorithm}.` }],
49
- structuredContent: toStructuredContent(result),
50
- };
51
- } catch (err) {
52
- return apiErrorResult(err);
53
- }
54
- },
55
- );
56
- }
@@ -1,86 +0,0 @@
1
- import { z } from 'zod';
2
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import type { AgledgerClient } from '@agledger/sdk';
4
- import { apiErrorResult, toStructuredContent } from '../errors.js';
5
- import { VerificationOutcomeEnum } from '../enums.js';
6
- import { toolMeta } from '../tool-scopes.js';
7
-
8
- const VerificationResultOutputSchema = z.object({
9
- mandateId: z.string().describe('Mandate UUID that was verified'),
10
- receipts: z.array(z.object({
11
- receiptId: z.string().describe('Receipt UUID'),
12
- phase1Result: z.record(z.string(), z.unknown()).optional().describe('Phase 1 (sync) verification result'),
13
- phase2Result: z.record(z.string(), z.unknown()).optional().describe('Phase 2 (async) verification result'),
14
- })).describe('Per-receipt verification results'),
15
- overallStatus: VerificationOutcomeEnum.describe('Overall verification outcome: PASS, FAIL, or REVIEW_REQUIRED'),
16
- }).passthrough().describe('Mandate verification result');
17
-
18
- const VerificationStatusOutputSchema = z.object({
19
- mandateId: z.string().describe('Mandate UUID'),
20
- phase1Status: z.string().describe('Phase 1 (sync rules) verification status'),
21
- phase2Status: z.string().describe('Phase 2 (async rules) verification status'),
22
- lastVerifiedAt: z.string().nullable().optional().describe('ISO 8601 timestamp of last verification'),
23
- pendingRules: z.array(z.string()).nullable().optional().describe('Rule IDs still pending verification'),
24
- }).passthrough().describe('Current verification status for a mandate');
25
-
26
- export function registerVerificationTools(mcp: McpServer, client: AgledgerClient): void {
27
- mcp.registerTool(
28
- 'verify_mandate',
29
- {
30
- title: 'Verify Mandate',
31
- description: 'Trigger verification of a mandate against its submitted receipts. Runs all sync and async verification rules.',
32
- inputSchema: {
33
- mandateId: z.string().describe('UUID of the mandate to verify'),
34
- },
35
- outputSchema: VerificationResultOutputSchema,
36
- annotations: {
37
- readOnlyHint: false,
38
- destructiveHint: false,
39
- idempotentHint: true,
40
- openWorldHint: true,
41
- },
42
- _meta: toolMeta('verify_mandate'),
43
- },
44
- async (args) => {
45
- try {
46
- const result = await client.verification.verify(args.mandateId);
47
- return {
48
- content: [{ type: 'text', text: `Verification for mandate ${result.mandateId}: ${result.overallStatus}. ${result.receipts.length} receipt(s) evaluated.` }],
49
- structuredContent: toStructuredContent(result),
50
- };
51
- } catch (err) {
52
- return apiErrorResult(err);
53
- }
54
- },
55
- );
56
-
57
- mcp.registerTool(
58
- 'get_verification_status',
59
- {
60
- title: 'Get Verification Status',
61
- description: 'Get the current verification status for a mandate, including phase 1/2 progress and pending rules.',
62
- inputSchema: {
63
- mandateId: z.string().describe('UUID of the mandate to check verification status for'),
64
- },
65
- outputSchema: VerificationStatusOutputSchema,
66
- annotations: {
67
- readOnlyHint: true,
68
- destructiveHint: false,
69
- idempotentHint: true,
70
- openWorldHint: true,
71
- },
72
- _meta: toolMeta('get_verification_status'),
73
- },
74
- async (args) => {
75
- try {
76
- const status = await client.verification.getStatus(args.mandateId);
77
- return {
78
- content: [{ type: 'text', text: `Verification status for ${status.mandateId}: phase1=${status.phase1Status}, phase2=${status.phase2Status}.` }],
79
- structuredContent: toStructuredContent(status),
80
- };
81
- } catch (err) {
82
- return apiErrorResult(err);
83
- }
84
- },
85
- );
86
- }
@@ -1,219 +0,0 @@
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 { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
- import { AgledgerMcpServer } from '../src/server.js';
6
- import { getProfileRegistry } from '../src/server.js';
7
- import { TOOL_SCOPES } from '../src/tool-scopes.js';
8
- import { createMockClient } from './mock-client.js';
9
-
10
- /**
11
- * Global conformance tests — validate structural invariants across ALL tools.
12
- * Uses the full profile to exercise every tool module.
13
- */
14
- describe('global conformance', () => {
15
- let client: Client;
16
- let cleanup: () => Promise<void>;
17
- let tools: Array<{
18
- name: string;
19
- description?: string;
20
- inputSchema?: Record<string, unknown>;
21
- outputSchema?: Record<string, unknown>;
22
- annotations?: Record<string, unknown>;
23
- _meta?: Record<string, unknown>;
24
- }>;
25
-
26
- beforeAll(async () => {
27
- const server = new AgledgerMcpServer({
28
- apiKey: 'test-key',
29
- apiUrl: 'https://test.example.com',
30
- profile: 'full',
31
- });
32
-
33
- const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
34
- client = new Client({ name: 'conformance-test', version: '0.0.0' });
35
-
36
- await Promise.all([
37
- server.mcp.connect(serverTransport),
38
- client.connect(clientTransport),
39
- ]);
40
-
41
- cleanup = async () => {
42
- await client.close();
43
- await server.mcp.close();
44
- };
45
-
46
- const result = await client.listTools();
47
- tools = result.tools as typeof tools;
48
- });
49
-
50
- afterAll(async () => {
51
- await cleanup();
52
- });
53
-
54
- it('registers at least 100 tools in full profile', () => {
55
- expect(tools.length).toBeGreaterThanOrEqual(100);
56
- });
57
-
58
- it('no duplicate tool names', () => {
59
- const names = tools.map(t => t.name);
60
- const dupes = names.filter((n, i) => names.indexOf(n) !== i);
61
- expect(dupes, `Duplicate tools: ${dupes.join(', ')}`).toEqual([]);
62
- });
63
-
64
- describe('outputSchema', () => {
65
- it('tools with outputSchema have type:"object" at root', () => {
66
- const violations: string[] = [];
67
- for (const tool of tools) {
68
- if (tool.outputSchema && tool.outputSchema.type !== 'object') {
69
- violations.push(`${tool.name}: type="${tool.outputSchema.type}"`);
70
- }
71
- }
72
- expect(violations, `outputSchema type violations: ${violations.join(', ')}`).toEqual([]);
73
- });
74
-
75
- it('every tool has outputSchema', () => {
76
- const missing = tools.filter(t => !t.outputSchema).map(t => t.name);
77
- expect(missing, `Tools missing outputSchema: ${missing.join(', ')}`).toEqual([]);
78
- });
79
- });
80
-
81
- describe('inputSchema', () => {
82
- it('every tool has an inputSchema', () => {
83
- const missing = tools.filter(t => !t.inputSchema).map(t => t.name);
84
- expect(missing, `Tools missing inputSchema: ${missing.join(', ')}`).toEqual([]);
85
- });
86
- });
87
-
88
- describe('descriptions', () => {
89
- it('every tool has a non-empty description', () => {
90
- const missing = tools.filter(t => !t.description).map(t => t.name);
91
- expect(missing, `Tools missing description: ${missing.join(', ')}`).toEqual([]);
92
- });
93
- });
94
-
95
- describe('annotations', () => {
96
- it('tools with annotations have all 4 hint fields', () => {
97
- const hints = ['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint'];
98
- const violations: string[] = [];
99
- for (const tool of tools) {
100
- if (tool.annotations) {
101
- for (const hint of hints) {
102
- if (!(hint in tool.annotations)) {
103
- violations.push(`${tool.name}: missing ${hint}`);
104
- }
105
- }
106
- }
107
- }
108
- expect(violations).toEqual([]);
109
- });
110
-
111
- it('every tool has annotations', () => {
112
- const missing = tools.filter(t => !t.annotations).map(t => t.name);
113
- expect(missing, `Tools missing annotations: ${missing.join(', ')}`).toEqual([]);
114
- });
115
- });
116
-
117
- describe('scope coverage', () => {
118
- it('every registered tool has a TOOL_SCOPES entry', () => {
119
- const missing = tools.filter(t => !(t.name in TOOL_SCOPES)).map(t => t.name);
120
- expect(missing, `Tools without TOOL_SCOPES entry: ${missing.join(', ')}`).toEqual([]);
121
- });
122
-
123
- it('every TOOL_SCOPES entry with non-empty scopes has _meta on its tool', () => {
124
- const violations: string[] = [];
125
- for (const tool of tools) {
126
- const scopes = TOOL_SCOPES[tool.name];
127
- if (scopes && scopes.length > 0) {
128
- const meta = tool._meta as Record<string, unknown> | undefined;
129
- if (!meta || !meta.requiredScopes) {
130
- violations.push(tool.name);
131
- }
132
- }
133
- }
134
- expect(violations, `Tools with scopes but no _meta.requiredScopes: ${violations.join(', ')}`).toEqual([]);
135
- });
136
- });
137
- });
138
-
139
- /**
140
- * Error + outputSchema interaction test.
141
- *
142
- * Known MCP SDK issue: when a tool has outputSchema and returns isError: true,
143
- * the SDK may validate the error content against the outputSchema and block it.
144
- * This test verifies every tool can still surface errors correctly.
145
- *
146
- * Strategy: create a server where ALL SDK methods throw, then call every tool.
147
- * Every call should return isError: true with a readable error message (not an
148
- * outputSchema validation error or a thrown exception).
149
- */
150
- describe('error + outputSchema interaction', () => {
151
- let errorClient: Client;
152
- let errorCleanup: () => Promise<void>;
153
- let toolNames: string[];
154
-
155
- beforeAll(async () => {
156
- // Create a mock client where every method throws — no overrides
157
- const mockSdk = createMockClient();
158
-
159
- const mcp = new McpServer(
160
- { name: 'error-test', version: '0.0.0' },
161
- { capabilities: { tools: {}, resources: {} } },
162
- );
163
-
164
- // Register all tools from the full profile
165
- const registry = getProfileRegistry();
166
- for (const fn of registry.full) {
167
- fn(mcp, mockSdk);
168
- }
169
-
170
- const [ct, st] = InMemoryTransport.createLinkedPair();
171
- errorClient = new Client({ name: 'error-test-client', version: '0.0.0' });
172
- await Promise.all([mcp.connect(st), errorClient.connect(ct)]);
173
-
174
- const { tools } = await errorClient.listTools();
175
- toolNames = tools.map((t: any) => t.name);
176
-
177
- errorCleanup = async () => {
178
- await errorClient.close();
179
- await mcp.close();
180
- };
181
- });
182
-
183
- afterAll(async () => { await errorCleanup(); });
184
-
185
- it('every tool with outputSchema can return errors without being blocked', async () => {
186
- const blocked: string[] = [];
187
- const thrown: string[] = [];
188
-
189
- for (const name of toolNames) {
190
- // Build minimal valid arguments (empty object works for most; SDK error happens before arg validation matters)
191
- try {
192
- const result = await errorClient.callTool({ name, arguments: {} });
193
- const r = result as any;
194
- if (r.isError) {
195
- // Good — error came through
196
- const text = r.content?.[0]?.text ?? '';
197
- if (text.includes('Output validation error') || text.includes('Invalid structured content')) {
198
- blocked.push(`${name}: outputSchema blocked error response`);
199
- }
200
- }
201
- // If isError is false, the tool might have succeeded with empty args (e.g., health check with mock).
202
- // That's fine — the mock throws "not mocked" so most will error.
203
- } catch (err: any) {
204
- // MCP client threw instead of returning an error result — this is the bug
205
- const msg = err?.message ?? String(err);
206
- if (msg.includes('Output validation') || msg.includes('Invalid structured content')) {
207
- blocked.push(`${name}: outputSchema validation threw instead of returning error`);
208
- } else if (msg.includes('Input validation')) {
209
- // Tool requires specific input args — skip, not an outputSchema issue
210
- } else {
211
- thrown.push(`${name}: ${msg.slice(0, 100)}`);
212
- }
213
- }
214
- }
215
-
216
- expect(blocked, `Tools where outputSchema blocks error responses:\n${blocked.join('\n')}`).toEqual([]);
217
- // thrown is informational — some tools may throw for input validation, that's expected
218
- });
219
- });
@@ -1,75 +0,0 @@
1
- import { expect } from 'vitest';
2
- import { TOOL_SCOPES } from '../src/tool-scopes.js';
3
-
4
- interface ToolDefinition {
5
- name: string;
6
- description?: string;
7
- inputSchema?: Record<string, unknown>;
8
- outputSchema?: Record<string, unknown>;
9
- annotations?: Record<string, unknown>;
10
- _meta?: Record<string, unknown>;
11
- }
12
-
13
- interface CallToolResult {
14
- content: Array<{ type: string; text?: string }>;
15
- structuredContent?: Record<string, unknown>;
16
- isError?: boolean;
17
- }
18
-
19
- /**
20
- * Assert a tool's outputSchema is valid:
21
- * - Has type: "object" at root (required by Claude Desktop and other MCP clients)
22
- * - Has at least one property or uses passthrough
23
- */
24
- export function assertOutputSchemaValid(tool: ToolDefinition): void {
25
- expect(tool.outputSchema, `${tool.name}: missing outputSchema`).toBeDefined();
26
- const schema = tool.outputSchema!;
27
- expect(schema.type, `${tool.name}: outputSchema must have type:"object" at root`).toBe('object');
28
- }
29
-
30
- /**
31
- * Assert tool metadata follows conventions:
32
- * - Non-empty description
33
- * - All 4 annotation hints present
34
- * - _meta.requiredScopes matches TOOL_SCOPES (if tool is in the scope map)
35
- */
36
- export function assertToolMetadata(tool: ToolDefinition): void {
37
- expect(tool.description, `${tool.name}: missing description`).toBeTruthy();
38
-
39
- if (tool.annotations) {
40
- const hints = ['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint'];
41
- for (const hint of hints) {
42
- expect(
43
- hint in tool.annotations,
44
- `${tool.name}: missing annotation ${hint}`,
45
- ).toBe(true);
46
- }
47
- }
48
-
49
- const expectedScopes = TOOL_SCOPES[tool.name];
50
- if (expectedScopes && tool._meta) {
51
- const meta = tool._meta as Record<string, unknown>;
52
- if (meta.requiredScopes) {
53
- expect(meta.requiredScopes, `${tool.name}: _meta.requiredScopes mismatch`).toEqual(expectedScopes);
54
- }
55
- }
56
- }
57
-
58
- /**
59
- * Assert a callTool result is an error result with the expected shape.
60
- */
61
- export function assertErrorResult(result: CallToolResult): void {
62
- expect(result.isError, 'Expected isError to be true').toBe(true);
63
- expect(result.content.length).toBeGreaterThan(0);
64
- expect(result.content[0].type).toBe('text');
65
- expect(result.content[0].text).toMatch(/^Error:/);
66
- }
67
-
68
- /**
69
- * Assert a callTool result is a success result with structured content.
70
- */
71
- export function assertSuccessResult(result: CallToolResult): void {
72
- expect(result.isError).toBeFalsy();
73
- expect(result.content.length).toBeGreaterThan(0);
74
- expect(result.content[0].type).toBe('text');
75
- }
@@ -1,144 +0,0 @@
1
- /**
2
- * RESOURCE_MANIFEST drift test
3
- *
4
- * Verifies that the RESOURCE_MANIFEST in code-mode.ts stays in sync with the
5
- * actual AgledgerClient resource properties. If a resource is added to or
6
- * removed from the SDK client, this test will fail until the manifest is updated.
7
- */
8
-
9
- import { describe, it, expect } from 'vitest';
10
- import { readFileSync } from 'node:fs';
11
- import { resolve, dirname } from 'node:path';
12
- import { fileURLToPath } from 'node:url';
13
-
14
- const __dirname = dirname(fileURLToPath(import.meta.url));
15
-
16
- // ---------------------------------------------------------------------------
17
- // Extract resource names from the SDK client source
18
- // ---------------------------------------------------------------------------
19
-
20
- function getClientResourceNames(): string[] {
21
- const clientPath = resolve(__dirname, '../../../../agledger-sdk/src/client.ts');
22
- const source = readFileSync(clientPath, 'utf8');
23
-
24
- // Match "readonly <name>: <Type>Resource" property declarations
25
- const pattern = /^\s+readonly\s+(\w+)\s*:\s+\w+Resource/gm;
26
- const names: string[] = [];
27
- let match: RegExpExecArray | null;
28
- while ((match = pattern.exec(source)) !== null) {
29
- names.push(match[1]);
30
- }
31
- return names.sort();
32
- }
33
-
34
- // ---------------------------------------------------------------------------
35
- // Extract resource names from the RESOURCE_MANIFEST in code-mode.ts
36
- // ---------------------------------------------------------------------------
37
-
38
- function getManifestResourceNames(): string[] {
39
- const codePath = resolve(__dirname, '../../src/tools/code-mode.ts');
40
- const source = readFileSync(codePath, 'utf8');
41
-
42
- // The manifest is defined as: const RESOURCE_MANIFEST: Record<string, string> = { key: `...`, ... };
43
- // Extract the keys by finding the block between the opening { and closing };
44
- const startMarker = 'const RESOURCE_MANIFEST: Record<string, string> = {';
45
- const startIdx = source.indexOf(startMarker);
46
- if (startIdx === -1) {
47
- throw new Error('Could not find RESOURCE_MANIFEST in code-mode.ts');
48
- }
49
-
50
- // Find matching closing brace by counting depth
51
- let depth = 0;
52
- let inString = false;
53
- let stringChar = '';
54
- let endIdx = -1;
55
-
56
- for (let i = startIdx + startMarker.length - 1; i < source.length; i++) {
57
- const ch = source[i];
58
- const prev = i > 0 ? source[i - 1] : '';
59
-
60
- if (inString) {
61
- if (ch === stringChar && prev !== '\\') {
62
- inString = false;
63
- }
64
- continue;
65
- }
66
-
67
- if (ch === '`' || ch === '"' || ch === "'") {
68
- inString = true;
69
- stringChar = ch;
70
- continue;
71
- }
72
-
73
- if (ch === '{') depth++;
74
- if (ch === '}') {
75
- depth--;
76
- if (depth === 0) {
77
- endIdx = i;
78
- break;
79
- }
80
- }
81
- }
82
-
83
- if (endIdx === -1) {
84
- throw new Error('Could not parse RESOURCE_MANIFEST block');
85
- }
86
-
87
- const block = source.slice(startIdx + startMarker.length, endIdx);
88
-
89
- // Extract top-level keys: lines matching " <key>: `" at the start
90
- const keyPattern = /^\s+(\w+)\s*:\s*`/gm;
91
- const names: string[] = [];
92
- let m: RegExpExecArray | null;
93
- while ((m = keyPattern.exec(block)) !== null) {
94
- names.push(m[1]);
95
- }
96
- return names.sort();
97
- }
98
-
99
- // ---------------------------------------------------------------------------
100
- // Tests
101
- // ---------------------------------------------------------------------------
102
-
103
- describe('RESOURCE_MANIFEST ↔ SDK Client drift', () => {
104
- const clientResources = getClientResourceNames();
105
- const manifestResources = getManifestResourceNames();
106
-
107
- it('SDK client has at least one resource', () => {
108
- expect(clientResources.length).toBeGreaterThan(0);
109
- });
110
-
111
- it('RESOURCE_MANIFEST has at least one resource', () => {
112
- expect(manifestResources.length).toBeGreaterThan(0);
113
- });
114
-
115
- it('every SDK resource is present in RESOURCE_MANIFEST', () => {
116
- const missing = clientResources.filter((r) => !manifestResources.includes(r));
117
- if (missing.length > 0) {
118
- expect.fail(
119
- `${missing.length} SDK resource(s) missing from RESOURCE_MANIFEST in code-mode.ts:\n` +
120
- missing.map((r) => ` - ${r}`).join('\n') +
121
- '\n\nFix: add entries to RESOURCE_MANIFEST for these resources.',
122
- );
123
- }
124
- });
125
-
126
- it('every RESOURCE_MANIFEST entry corresponds to an SDK resource', () => {
127
- const extra = manifestResources.filter((r) => !clientResources.includes(r));
128
- if (extra.length > 0) {
129
- expect.fail(
130
- `${extra.length} RESOURCE_MANIFEST entry/entries have no corresponding SDK resource:\n` +
131
- extra.map((r) => ` - ${r}`).join('\n') +
132
- '\n\nFix: remove stale entries from RESOURCE_MANIFEST, or add missing resources to the SDK client.',
133
- );
134
- }
135
- });
136
-
137
- it('resource counts match exactly', () => {
138
- expect(manifestResources.length).toBe(clientResources.length);
139
- });
140
-
141
- it('resource names match exactly (sorted)', () => {
142
- expect(manifestResources).toEqual(clientResources);
143
- });
144
- });