@agledger/mcp-server 1.4.1 → 1.5.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/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/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +6 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +71 -76
- package/dist/server.js.map +1 -1
- package/dist/tool-scopes.js +3 -2
- package/dist/tool-scopes.js.map +1 -1
- package/dist/tools/a2a.d.ts.map +1 -1
- package/dist/tools/a2a.js +22 -222
- package/dist/tools/a2a.js.map +1 -1
- package/dist/tools/agent-mandates.d.ts.map +1 -1
- package/dist/tools/agent-mandates.js +11 -75
- 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 -61
- package/dist/tools/agents-refs.js.map +1 -1
- package/dist/tools/capabilities.d.ts.map +1 -1
- package/dist/tools/capabilities.js +3 -15
- 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 +4 -13
- package/dist/tools/compliance.js.map +1 -1
- package/dist/tools/dashboard.d.ts.map +1 -1
- package/dist/tools/dashboard.js +4 -13
- package/dist/tools/dashboard.js.map +1 -1
- package/dist/tools/disputes.d.ts.map +1 -1
- package/dist/tools/disputes.js +5 -37
- package/dist/tools/disputes.js.map +1 -1
- package/dist/tools/enterprises.d.ts.map +1 -1
- package/dist/tools/enterprises.js +7 -39
- package/dist/tools/enterprises.js.map +1 -1
- package/dist/tools/events.d.ts.map +1 -1
- package/dist/tools/events.js +2 -20
- package/dist/tools/events.js.map +1 -1
- package/dist/tools/federation-admin.d.ts.map +1 -1
- package/dist/tools/federation-admin.js +25 -257
- package/dist/tools/federation-admin.js.map +1 -1
- package/dist/tools/federation.d.ts.map +1 -1
- package/dist/tools/federation.js +21 -198
- package/dist/tools/federation.js.map +1 -1
- package/dist/tools/health.d.ts.map +1 -1
- package/dist/tools/health.js +2 -14
- package/dist/tools/health.js.map +1 -1
- package/dist/tools/mandates.d.ts.map +1 -1
- package/dist/tools/mandates.js +11 -83
- package/dist/tools/mandates.js.map +1 -1
- package/dist/tools/openclaw.d.ts.map +1 -1
- package/dist/tools/openclaw.js +6 -33
- package/dist/tools/openclaw.js.map +1 -1
- package/dist/tools/receipts.d.ts.map +1 -1
- package/dist/tools/receipts.js +5 -96
- package/dist/tools/receipts.js.map +1 -1
- package/dist/tools/reputation.d.ts.map +1 -1
- package/dist/tools/reputation.js +4 -13
- package/dist/tools/reputation.js.map +1 -1
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +34 -159
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/verification-keys.d.ts.map +1 -1
- package/dist/tools/verification-keys.js +2 -23
- package/dist/tools/verification-keys.js.map +1 -1
- package/dist/tools/verification.d.ts.map +1 -1
- package/dist/tools/verification.js +3 -28
- package/dist/tools/verification.js.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +9 -0
- package/src/index.ts +1 -3
- package/src/server.ts +77 -71
- package/src/tool-scopes.ts +3 -3
- package/src/tools/a2a.ts +22 -235
- package/src/tools/agent-mandates.ts +11 -77
- package/src/tools/agents-refs.ts +10 -65
- package/src/tools/capabilities.ts +3 -16
- package/src/tools/compliance.ts +4 -13
- package/src/tools/dashboard.ts +4 -13
- package/src/tools/disputes.ts +5 -38
- package/src/tools/enterprises.ts +7 -39
- package/src/tools/events.ts +2 -21
- package/src/tools/federation-admin.ts +25 -282
- package/src/tools/federation.ts +21 -218
- package/src/tools/health.ts +2 -15
- package/src/tools/mandates.ts +11 -85
- package/src/tools/openclaw.ts +6 -52
- package/src/tools/receipts.ts +5 -97
- package/src/tools/reputation.ts +4 -13
- package/src/tools/schemas.ts +34 -166
- package/src/tools/verification-keys.ts +2 -25
- package/src/tools/verification.ts +3 -30
- package/tests/conformance.test.ts +197 -0
- package/tests/conformance.ts +65 -0
- package/tests/harness.ts +55 -0
- package/tests/mock-client.ts +71 -0
- package/tests/profiles.test.ts +120 -0
- package/tests/resources/contract-types.test.ts +82 -0
- package/tests/tools/a2a.test.ts +213 -0
- package/tests/tools/agent-mandates.test.ts +196 -0
- package/tests/tools/agents-refs.test.ts +190 -0
- package/tests/tools/capabilities.test.ts +80 -0
- package/tests/tools/compliance.test.ts +123 -0
- package/tests/tools/dashboard.test.ts +111 -0
- package/tests/tools/disputes.test.ts +123 -0
- package/tests/tools/enterprises.test.ts +171 -0
- package/tests/tools/events.test.ts +56 -0
- package/tests/tools/federation-admin.test.ts +468 -0
- package/tests/tools/federation.test.ts +522 -0
- package/tests/tools/health.test.ts +56 -0
- package/tests/tools/mandates.test.ts +143 -0
- package/tests/tools/openclaw.test.ts +148 -0
- package/tests/tools/receipts.test.ts +157 -0
- package/tests/tools/reputation.test.ts +108 -0
- package/tests/tools/schemas.test.ts +374 -0
- package/tests/tools/verification-keys.test.ts +56 -0
- package/tests/tools/verification.test.ts +64 -0
- package/src/tools/code-mode.ts +0 -461
- package/tests/code-mode-manifest.test.ts +0 -144
- package/tests/enterprises.test.ts +0 -96
- package/tests/schemas.test.ts +0 -531
|
@@ -0,0 +1,197 @@
|
|
|
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('inputSchema', () => {
|
|
65
|
+
it('every tool has an inputSchema', () => {
|
|
66
|
+
const missing = tools.filter(t => !t.inputSchema).map(t => t.name);
|
|
67
|
+
expect(missing, `Tools missing inputSchema: ${missing.join(', ')}`).toEqual([]);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('descriptions', () => {
|
|
72
|
+
it('every tool has a non-empty description', () => {
|
|
73
|
+
const missing = tools.filter(t => !t.description).map(t => t.name);
|
|
74
|
+
expect(missing, `Tools missing description: ${missing.join(', ')}`).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('annotations', () => {
|
|
79
|
+
it('tools with annotations have all 4 hint fields', () => {
|
|
80
|
+
const hints = ['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint'];
|
|
81
|
+
const violations: string[] = [];
|
|
82
|
+
for (const tool of tools) {
|
|
83
|
+
if (tool.annotations) {
|
|
84
|
+
for (const hint of hints) {
|
|
85
|
+
if (!(hint in tool.annotations)) {
|
|
86
|
+
violations.push(`${tool.name}: missing ${hint}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
expect(violations).toEqual([]);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('every tool has annotations', () => {
|
|
95
|
+
const missing = tools.filter(t => !t.annotations).map(t => t.name);
|
|
96
|
+
expect(missing, `Tools missing annotations: ${missing.join(', ')}`).toEqual([]);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('scope coverage', () => {
|
|
101
|
+
it('every registered tool has a TOOL_SCOPES entry', () => {
|
|
102
|
+
const missing = tools.filter(t => !(t.name in TOOL_SCOPES)).map(t => t.name);
|
|
103
|
+
expect(missing, `Tools without TOOL_SCOPES entry: ${missing.join(', ')}`).toEqual([]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('every TOOL_SCOPES entry with non-empty scopes has _meta on its tool', () => {
|
|
107
|
+
const violations: string[] = [];
|
|
108
|
+
for (const tool of tools) {
|
|
109
|
+
const scopes = TOOL_SCOPES[tool.name];
|
|
110
|
+
if (scopes && scopes.length > 0) {
|
|
111
|
+
const meta = tool._meta as Record<string, unknown> | undefined;
|
|
112
|
+
if (!meta || !meta.requiredScopes) {
|
|
113
|
+
violations.push(tool.name);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
expect(violations, `Tools with scopes but no _meta.requiredScopes: ${violations.join(', ')}`).toEqual([]);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Error handling test.
|
|
124
|
+
*
|
|
125
|
+
* Strategy: create a server where ALL SDK methods throw, then call every tool.
|
|
126
|
+
* Every call should return isError: true with a readable error message.
|
|
127
|
+
*/
|
|
128
|
+
describe('error handling', () => {
|
|
129
|
+
let errorClient: Client;
|
|
130
|
+
let errorCleanup: () => Promise<void>;
|
|
131
|
+
let toolNames: string[];
|
|
132
|
+
|
|
133
|
+
beforeAll(async () => {
|
|
134
|
+
// Create a mock client where every method throws — no overrides
|
|
135
|
+
const mockSdk = createMockClient();
|
|
136
|
+
|
|
137
|
+
const mcp = new McpServer(
|
|
138
|
+
{ name: 'error-test', version: '0.0.0' },
|
|
139
|
+
{ capabilities: { tools: {}, resources: {} } },
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
// Register all tools from the full profile
|
|
143
|
+
const registry = getProfileRegistry();
|
|
144
|
+
for (const fn of registry.full) {
|
|
145
|
+
fn(mcp, mockSdk);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
149
|
+
errorClient = new Client({ name: 'error-test-client', version: '0.0.0' });
|
|
150
|
+
await Promise.all([mcp.connect(st), errorClient.connect(ct)]);
|
|
151
|
+
|
|
152
|
+
const { tools } = await errorClient.listTools();
|
|
153
|
+
toolNames = tools.map((t: any) => t.name);
|
|
154
|
+
|
|
155
|
+
errorCleanup = async () => {
|
|
156
|
+
await errorClient.close();
|
|
157
|
+
await mcp.close();
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
afterAll(async () => { await errorCleanup(); });
|
|
162
|
+
|
|
163
|
+
it('every tool returns structured errors when SDK throws', async () => {
|
|
164
|
+
const blocked: string[] = [];
|
|
165
|
+
const thrown: string[] = [];
|
|
166
|
+
|
|
167
|
+
for (const name of toolNames) {
|
|
168
|
+
// Build minimal valid arguments (empty object works for most; SDK error happens before arg validation matters)
|
|
169
|
+
try {
|
|
170
|
+
const result = await errorClient.callTool({ name, arguments: {} });
|
|
171
|
+
const r = result as any;
|
|
172
|
+
if (r.isError) {
|
|
173
|
+
// Good — error came through
|
|
174
|
+
const text = r.content?.[0]?.text ?? '';
|
|
175
|
+
if (text.includes('Output validation error') || text.includes('Invalid structured content')) {
|
|
176
|
+
blocked.push(`${name}: outputSchema blocked error response`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// If isError is false, the tool might have succeeded with empty args (e.g., health check with mock).
|
|
180
|
+
// That's fine — the mock throws "not mocked" so most will error.
|
|
181
|
+
} catch (err: any) {
|
|
182
|
+
// MCP client threw instead of returning an error result — this is the bug
|
|
183
|
+
const msg = err?.message ?? String(err);
|
|
184
|
+
if (msg.includes('Output validation') || msg.includes('Invalid structured content')) {
|
|
185
|
+
blocked.push(`${name}: outputSchema validation threw instead of returning error`);
|
|
186
|
+
} else if (msg.includes('Input validation')) {
|
|
187
|
+
// Tool requires specific input args — skip, not an outputSchema issue
|
|
188
|
+
} else {
|
|
189
|
+
thrown.push(`${name}: ${msg.slice(0, 100)}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
expect(blocked, `Tools where outputSchema blocks error responses:\n${blocked.join('\n')}`).toEqual([]);
|
|
195
|
+
// thrown is informational — some tools may throw for input validation, that's expected
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
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 tool metadata follows conventions:
|
|
21
|
+
* - Non-empty description
|
|
22
|
+
* - All 4 annotation hints present
|
|
23
|
+
* - _meta.requiredScopes matches TOOL_SCOPES (if tool is in the scope map)
|
|
24
|
+
*/
|
|
25
|
+
export function assertToolMetadata(tool: ToolDefinition): void {
|
|
26
|
+
expect(tool.description, `${tool.name}: missing description`).toBeTruthy();
|
|
27
|
+
|
|
28
|
+
if (tool.annotations) {
|
|
29
|
+
const hints = ['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint'];
|
|
30
|
+
for (const hint of hints) {
|
|
31
|
+
expect(
|
|
32
|
+
hint in tool.annotations,
|
|
33
|
+
`${tool.name}: missing annotation ${hint}`,
|
|
34
|
+
).toBe(true);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const expectedScopes = TOOL_SCOPES[tool.name];
|
|
39
|
+
if (expectedScopes && tool._meta) {
|
|
40
|
+
const meta = tool._meta as Record<string, unknown>;
|
|
41
|
+
if (meta.requiredScopes) {
|
|
42
|
+
expect(meta.requiredScopes, `${tool.name}: _meta.requiredScopes mismatch`).toEqual(expectedScopes);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Assert a callTool result is an error result with the expected shape.
|
|
49
|
+
*/
|
|
50
|
+
export function assertErrorResult(result: CallToolResult): void {
|
|
51
|
+
expect(result.isError, 'Expected isError to be true').toBe(true);
|
|
52
|
+
expect(result.content.length).toBeGreaterThan(0);
|
|
53
|
+
expect(result.content[0].type).toBe('text');
|
|
54
|
+
expect(result.content[0].text).toMatch(/^Error:/);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Assert a callTool result is a success result with structured content.
|
|
59
|
+
*/
|
|
60
|
+
export function assertSuccessResult(result: CallToolResult): void {
|
|
61
|
+
expect(result.isError).toBeFalsy();
|
|
62
|
+
const hasContent = result.content.length > 0;
|
|
63
|
+
const hasStructured = result.structuredContent != null;
|
|
64
|
+
expect(hasContent || hasStructured).toBe(true);
|
|
65
|
+
}
|
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,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,120 @@
|
|
|
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 { 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
|
+
openclaw: 5,
|
|
41
|
+
agent: -1, // populated dynamically below
|
|
42
|
+
'schema-dev': -1,
|
|
43
|
+
admin: -1,
|
|
44
|
+
federation: -1,
|
|
45
|
+
audit: -1,
|
|
46
|
+
full: -1,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const ALL_PROFILES: ToolProfile[] = ['openclaw', 'agent', 'schema-dev', 'admin', 'federation', 'audit', 'full'];
|
|
50
|
+
|
|
51
|
+
describe('profile tool registration', () => {
|
|
52
|
+
const cleanups: Array<() => Promise<void>> = [];
|
|
53
|
+
|
|
54
|
+
afterAll(async () => {
|
|
55
|
+
for (const cleanup of cleanups) {
|
|
56
|
+
await cleanup();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
for (const profile of ALL_PROFILES) {
|
|
61
|
+
describe(`${profile} profile`, () => {
|
|
62
|
+
let tools: Array<{ name: string; description?: string; inputSchema?: unknown; outputSchema?: unknown; annotations?: unknown; _meta?: unknown }>;
|
|
63
|
+
|
|
64
|
+
it('connects and lists tools', async () => {
|
|
65
|
+
const harness = await createProfileHarness(profile);
|
|
66
|
+
cleanups.push(harness.cleanup);
|
|
67
|
+
const result = await harness.client.listTools();
|
|
68
|
+
tools = result.tools as typeof tools;
|
|
69
|
+
expect(tools.length).toBeGreaterThan(0);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('has no duplicate tool names', () => {
|
|
73
|
+
const names = tools.map(t => t.name);
|
|
74
|
+
const uniqueNames = new Set(names);
|
|
75
|
+
expect(names.length, `Duplicate tools in ${profile}: ${names.filter((n, i) => names.indexOf(n) !== i).join(', ')}`).toBe(uniqueNames.size);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('every tool has valid metadata', () => {
|
|
79
|
+
for (const tool of tools) {
|
|
80
|
+
assertToolMetadata(tool as any);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (profile === 'openclaw') {
|
|
85
|
+
it('registers exactly 5 openclaw tools', () => {
|
|
86
|
+
expect(tools.length).toBe(5);
|
|
87
|
+
for (const tool of tools) {
|
|
88
|
+
expect(tool.name).toMatch(/^agledger_/);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (profile === 'agent') {
|
|
94
|
+
it('does not include submit_receipt from receipts module (skipSubmit)', () => {
|
|
95
|
+
const names = tools.map(t => t.name);
|
|
96
|
+
// a2a module has its own submit_receipt, but receipts module's is skipped
|
|
97
|
+
const submitCount = names.filter(n => n === 'submit_receipt').length;
|
|
98
|
+
expect(submitCount).toBeLessThanOrEqual(1);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
it('every registered tool across all profiles has a TOOL_SCOPES entry', async () => {
|
|
105
|
+
const allRegisteredNames = new Set<string>();
|
|
106
|
+
for (const profile of ALL_PROFILES) {
|
|
107
|
+
const harness = await createProfileHarness(profile);
|
|
108
|
+
cleanups.push(harness.cleanup);
|
|
109
|
+
const { tools } = await harness.client.listTools();
|
|
110
|
+
for (const t of tools) allRegisteredNames.add((t as any).name);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const missingFromScopes = [...allRegisteredNames].filter(name => !TOOL_SCOPES[name]);
|
|
114
|
+
expect(missingFromScopes, `Registered tools without TOOL_SCOPES entry: ${missingFromScopes.join(', ')}`).toEqual([]);
|
|
115
|
+
|
|
116
|
+
const scopeNames = Object.keys(TOOL_SCOPES);
|
|
117
|
+
const missingFromProfiles = scopeNames.filter(name => !allRegisteredNames.has(name));
|
|
118
|
+
expect(missingFromProfiles, `TOOL_SCOPES entries not registered in any profile: ${missingFromProfiles.join(', ')}`).toEqual([]);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -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
|
+
});
|