@agledger/mcp-server 1.5.0 → 2.0.1

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 (162) 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 -58
  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 -109
  11. package/dist/server.js.map +1 -1
  12. package/package.json +2 -3
  13. package/src/api-client.ts +72 -0
  14. package/src/index.ts +27 -60
  15. package/src/server.ts +136 -120
  16. package/tests/api-client.test.ts +147 -0
  17. package/tests/harness.ts +8 -35
  18. package/tests/integration.test.ts +373 -0
  19. package/tests/server.test.ts +286 -0
  20. package/dist/enums.d.ts +0 -110
  21. package/dist/enums.d.ts.map +0 -1
  22. package/dist/enums.js +0 -42
  23. package/dist/enums.js.map +0 -1
  24. package/dist/errors.d.ts +0 -10
  25. package/dist/errors.d.ts.map +0 -1
  26. package/dist/errors.js +0 -49
  27. package/dist/errors.js.map +0 -1
  28. package/dist/resources/contract-types.d.ts +0 -4
  29. package/dist/resources/contract-types.d.ts.map +0 -1
  30. package/dist/resources/contract-types.js +0 -104
  31. package/dist/resources/contract-types.js.map +0 -1
  32. package/dist/tool-scopes.d.ts +0 -11
  33. package/dist/tool-scopes.d.ts.map +0 -1
  34. package/dist/tool-scopes.js +0 -164
  35. package/dist/tool-scopes.js.map +0 -1
  36. package/dist/tools/a2a.d.ts +0 -8
  37. package/dist/tools/a2a.d.ts.map +0 -1
  38. package/dist/tools/a2a.js +0 -360
  39. package/dist/tools/a2a.js.map +0 -1
  40. package/dist/tools/agent-mandates.d.ts +0 -4
  41. package/dist/tools/agent-mandates.d.ts.map +0 -1
  42. package/dist/tools/agent-mandates.js +0 -222
  43. package/dist/tools/agent-mandates.js.map +0 -1
  44. package/dist/tools/agents-refs.d.ts +0 -4
  45. package/dist/tools/agents-refs.d.ts.map +0 -1
  46. package/dist/tools/agents-refs.js +0 -196
  47. package/dist/tools/agents-refs.js.map +0 -1
  48. package/dist/tools/capabilities.d.ts +0 -4
  49. package/dist/tools/capabilities.d.ts.map +0 -1
  50. package/dist/tools/capabilities.js +0 -54
  51. package/dist/tools/capabilities.js.map +0 -1
  52. package/dist/tools/code-mode.d.ts +0 -4
  53. package/dist/tools/code-mode.d.ts.map +0 -1
  54. package/dist/tools/code-mode.js +0 -389
  55. package/dist/tools/code-mode.js.map +0 -1
  56. package/dist/tools/compliance.d.ts +0 -4
  57. package/dist/tools/compliance.d.ts.map +0 -1
  58. package/dist/tools/compliance.js +0 -63
  59. package/dist/tools/compliance.js.map +0 -1
  60. package/dist/tools/dashboard.d.ts +0 -4
  61. package/dist/tools/dashboard.d.ts.map +0 -1
  62. package/dist/tools/dashboard.js +0 -57
  63. package/dist/tools/dashboard.js.map +0 -1
  64. package/dist/tools/disputes.d.ts +0 -4
  65. package/dist/tools/disputes.d.ts.map +0 -1
  66. package/dist/tools/disputes.js +0 -103
  67. package/dist/tools/disputes.js.map +0 -1
  68. package/dist/tools/enterprises.d.ts +0 -4
  69. package/dist/tools/enterprises.d.ts.map +0 -1
  70. package/dist/tools/enterprises.js +0 -173
  71. package/dist/tools/enterprises.js.map +0 -1
  72. package/dist/tools/events.d.ts +0 -4
  73. package/dist/tools/events.d.ts.map +0 -1
  74. package/dist/tools/events.js +0 -28
  75. package/dist/tools/events.js.map +0 -1
  76. package/dist/tools/federation-admin.d.ts +0 -4
  77. package/dist/tools/federation-admin.d.ts.map +0 -1
  78. package/dist/tools/federation-admin.js +0 -567
  79. package/dist/tools/federation-admin.js.map +0 -1
  80. package/dist/tools/federation.d.ts +0 -4
  81. package/dist/tools/federation.d.ts.map +0 -1
  82. package/dist/tools/federation.js +0 -505
  83. package/dist/tools/federation.js.map +0 -1
  84. package/dist/tools/health.d.ts +0 -4
  85. package/dist/tools/health.d.ts.map +0 -1
  86. package/dist/tools/health.js +0 -25
  87. package/dist/tools/health.js.map +0 -1
  88. package/dist/tools/mandates.d.ts +0 -4
  89. package/dist/tools/mandates.d.ts.map +0 -1
  90. package/dist/tools/mandates.js +0 -227
  91. package/dist/tools/mandates.js.map +0 -1
  92. package/dist/tools/openclaw.d.ts +0 -4
  93. package/dist/tools/openclaw.d.ts.map +0 -1
  94. package/dist/tools/openclaw.js +0 -110
  95. package/dist/tools/openclaw.js.map +0 -1
  96. package/dist/tools/receipts.d.ts +0 -8
  97. package/dist/tools/receipts.d.ts.map +0 -1
  98. package/dist/tools/receipts.js +0 -111
  99. package/dist/tools/receipts.js.map +0 -1
  100. package/dist/tools/reputation.d.ts +0 -4
  101. package/dist/tools/reputation.d.ts.map +0 -1
  102. package/dist/tools/reputation.js +0 -62
  103. package/dist/tools/reputation.js.map +0 -1
  104. package/dist/tools/schemas.d.ts +0 -4
  105. package/dist/tools/schemas.d.ts.map +0 -1
  106. package/dist/tools/schemas.js +0 -453
  107. package/dist/tools/schemas.js.map +0 -1
  108. package/dist/tools/verification-keys.d.ts +0 -4
  109. package/dist/tools/verification-keys.d.ts.map +0 -1
  110. package/dist/tools/verification-keys.js +0 -27
  111. package/dist/tools/verification-keys.js.map +0 -1
  112. package/dist/tools/verification.d.ts +0 -4
  113. package/dist/tools/verification.d.ts.map +0 -1
  114. package/dist/tools/verification.js +0 -50
  115. package/dist/tools/verification.js.map +0 -1
  116. package/src/enums.ts +0 -47
  117. package/src/errors.ts +0 -44
  118. package/src/resources/contract-types.ts +0 -130
  119. package/src/tool-scopes.ts +0 -180
  120. package/src/tools/a2a.ts +0 -430
  121. package/src/tools/agent-mandates.ts +0 -259
  122. package/src/tools/agents-refs.ts +0 -232
  123. package/src/tools/capabilities.ts +0 -63
  124. package/src/tools/compliance.ts +0 -70
  125. package/src/tools/dashboard.ts +0 -64
  126. package/src/tools/disputes.ts +0 -121
  127. package/src/tools/enterprises.ts +0 -203
  128. package/src/tools/events.ts +0 -33
  129. package/src/tools/federation-admin.ts +0 -665
  130. package/src/tools/federation.ts +0 -587
  131. package/src/tools/health.ts +0 -30
  132. package/src/tools/mandates.ts +0 -264
  133. package/src/tools/openclaw.ts +0 -122
  134. package/src/tools/receipts.ts +0 -134
  135. package/src/tools/reputation.ts +0 -69
  136. package/src/tools/schemas.ts +0 -535
  137. package/src/tools/verification-keys.ts +0 -33
  138. package/src/tools/verification.ts +0 -59
  139. package/tests/conformance.test.ts +0 -197
  140. package/tests/conformance.ts +0 -65
  141. package/tests/mock-client.ts +0 -71
  142. package/tests/profiles.test.ts +0 -120
  143. package/tests/resources/contract-types.test.ts +0 -82
  144. package/tests/tools/a2a.test.ts +0 -213
  145. package/tests/tools/agent-mandates.test.ts +0 -196
  146. package/tests/tools/agents-refs.test.ts +0 -190
  147. package/tests/tools/capabilities.test.ts +0 -80
  148. package/tests/tools/compliance.test.ts +0 -123
  149. package/tests/tools/dashboard.test.ts +0 -111
  150. package/tests/tools/disputes.test.ts +0 -123
  151. package/tests/tools/enterprises.test.ts +0 -171
  152. package/tests/tools/events.test.ts +0 -56
  153. package/tests/tools/federation-admin.test.ts +0 -468
  154. package/tests/tools/federation.test.ts +0 -522
  155. package/tests/tools/health.test.ts +0 -56
  156. package/tests/tools/mandates.test.ts +0 -143
  157. package/tests/tools/openclaw.test.ts +0 -148
  158. package/tests/tools/receipts.test.ts +0 -157
  159. package/tests/tools/reputation.test.ts +0 -108
  160. package/tests/tools/schemas.test.ts +0 -374
  161. package/tests/tools/verification-keys.test.ts +0 -56
  162. package/tests/tools/verification.test.ts +0 -64
package/src/errors.ts DELETED
@@ -1,44 +0,0 @@
1
- import { AgledgerApiError, PermissionError } from '@agledger/sdk';
2
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
3
-
4
- /**
5
- * Convert a typed SDK response to structuredContent.
6
- * JSON round-trip strips class instances, functions, and non-serializable values,
7
- * producing a clean Record<string, unknown>.
8
- */
9
- export function toStructuredContent<T>(value: T): Record<string, unknown> {
10
- return JSON.parse(JSON.stringify(value)) as Record<string, unknown>;
11
- }
12
-
13
- export function errorResult(message: string, details?: Record<string, unknown>): CallToolResult {
14
- let text = `Error: ${message}`;
15
- if (details) text += `\n\nDetails: ${JSON.stringify(details)}`;
16
- return {
17
- content: [{ type: 'text', text }],
18
- isError: true,
19
- };
20
- }
21
-
22
- export function apiErrorResult(e: unknown): CallToolResult {
23
- if (e instanceof PermissionError) {
24
- if (e.missingScopes.length > 0) {
25
- return errorResult(`Insufficient scopes. Missing: ${e.missingScopes.join(', ')}. Use GET /auth/me to check your key's scopes.`);
26
- }
27
- return errorResult('Agent not approved for this enterprise. Use approve_enterprise_agent to approve the agent, or set agentApprovalRequired=false via set_enterprise_config.');
28
- }
29
- if (e instanceof AgledgerApiError) {
30
- const extra: Record<string, unknown> = {};
31
- if (e.code) extra.code = e.code;
32
- if (e.docUrl) extra.docUrl = e.docUrl;
33
- if (e.details && typeof e.details === 'object' && !Array.isArray(e.details)) {
34
- const d = e.details as Record<string, unknown>;
35
- if (d.examplePayload) extra.examplePayload = d.examplePayload;
36
- if (d.requiredFields) extra.requiredFields = d.requiredFields;
37
- if (d.optionalFields) extra.optionalFields = d.optionalFields;
38
- }
39
- if (e.validationErrors.length > 0) extra.validationErrors = e.validationErrors;
40
- if (e.suggestion) extra.suggestion = e.suggestion;
41
- return errorResult(e.message, Object.keys(extra).length > 0 ? extra : undefined);
42
- }
43
- return errorResult(e instanceof Error ? e.message : String(e));
44
- }
@@ -1,130 +0,0 @@
1
- import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
- import type { AgledgerClient } from '@agledger/sdk';
4
- import type { ContractType } from '@agledger/sdk';
5
-
6
- const CONTRACT_TYPES: { type: ContractType; description: string }[] = [
7
- { type: 'ACH-PROC-v1', description: 'General procurement (goods, services, supplies)' },
8
- { type: 'ACH-DLVR-v1', description: 'Deliverables (reports, documents, artifacts)' },
9
- { type: 'ACH-DATA-v1', description: 'Data processing (ETL, analysis, transformation)' },
10
- { type: 'ACH-TXN-v1', description: 'Transactions (payments, transfers, settlements)' },
11
- { type: 'ACH-ORCH-v1', description: 'Orchestration (delegation, task coordination)' },
12
- { type: 'ACH-COMM-v1', description: 'Communication (email, chat, webhooks, notifications)' },
13
- { type: 'ACH-AUTH-v1', description: 'Authorization (permissions, credentials, access control)' },
14
- { type: 'ACH-INFRA-v1', description: 'Infrastructure (DDL, cloud provisioning, config changes)' },
15
- { type: 'ACH-DEL-v1', description: 'Destructive operations (deletions, cancellations, refunds, reversals)' },
16
- { type: 'ACH-ANALYZE-v1', description: 'Research, analysis, and investigation tasks' },
17
- { type: 'ACH-COORD-v1', description: 'Multi-party coordination and consensus building' },
18
- { type: 'ACH-MON-v1', description: 'Monitoring, alerting, and observability tasks' },
19
- { type: 'ACH-REVIEW-v1', description: 'Review, approval, and sign-off workflows' },
20
- ];
21
-
22
- const VALID_TYPES = new Set(CONTRACT_TYPES.map((ct) => ct.type));
23
-
24
- export function registerContractTypeResources(mcp: McpServer, client: AgledgerClient): void {
25
- mcp.registerResource(
26
- 'contract-types',
27
- 'schema://contract-types',
28
- {
29
- description: 'List of all 9 AGLedger standard contract types with descriptions.',
30
- mimeType: 'application/json',
31
- },
32
- async () => {
33
- return {
34
- contents: [
35
- {
36
- uri: 'schema://contract-types',
37
- mimeType: 'application/json',
38
- text: JSON.stringify(CONTRACT_TYPES, null, 2),
39
- },
40
- ],
41
- };
42
- },
43
- );
44
-
45
- const template = new ResourceTemplate(
46
- 'schema://contract-types/{type}',
47
- {
48
- list: async () => {
49
- return {
50
- resources: CONTRACT_TYPES.map((ct) => ({
51
- uri: `schema://contract-types/${ct.type}`,
52
- name: ct.type,
53
- description: ct.description,
54
- mimeType: 'application/json',
55
- })),
56
- };
57
- },
58
- complete: {
59
- type: async (value: string) => {
60
- return CONTRACT_TYPES
61
- .map((ct) => ct.type)
62
- .filter((t) => t.toLowerCase().startsWith(value.toLowerCase()));
63
- },
64
- },
65
- },
66
- );
67
-
68
- mcp.registerResource(
69
- 'contract-type-schema',
70
- template,
71
- {
72
- description: 'Individual AGLedger contract type schema with mandate/receipt JSON Schemas and verification rules.',
73
- mimeType: 'application/json',
74
- },
75
- async (_uri, variables) => {
76
- const contractType = variables.type as string;
77
-
78
- if (!VALID_TYPES.has(contractType as ContractType)) {
79
- return {
80
- contents: [
81
- {
82
- uri: `schema://contract-types/${contractType}`,
83
- mimeType: 'application/json',
84
- text: JSON.stringify({
85
- error: `Unknown contract type: ${contractType}. Valid types: ${[...VALID_TYPES].join(', ')}`,
86
- }),
87
- },
88
- ],
89
- };
90
- }
91
-
92
- try {
93
- const schema = await client.schemas.get(contractType as ContractType);
94
- const info = CONTRACT_TYPES.find((ct) => ct.type === contractType);
95
-
96
- return {
97
- contents: [
98
- {
99
- uri: `schema://contract-types/${contractType}`,
100
- mimeType: 'application/json',
101
- text: JSON.stringify(
102
- {
103
- contractType: schema.contractType,
104
- description: info?.description ?? '',
105
- mandateSchema: schema.mandateSchema,
106
- receiptSchema: schema.receiptSchema,
107
- rulesConfig: schema.rulesConfig ?? null,
108
- },
109
- null,
110
- 2,
111
- ),
112
- },
113
- ],
114
- };
115
- } catch (err) {
116
- return {
117
- contents: [
118
- {
119
- uri: `schema://contract-types/${contractType}`,
120
- mimeType: 'application/json',
121
- text: JSON.stringify({
122
- error: err instanceof Error ? err.message : String(err),
123
- }),
124
- },
125
- ],
126
- };
127
- }
128
- },
129
- );
130
- }
@@ -1,180 +0,0 @@
1
- /**
2
- * Required scopes for each tool, keyed by tool name.
3
- * Read scopes grant access; write scopes imply read.
4
- */
5
- export const TOOL_SCOPES: Record<string, string[]> = {
6
- // Mandates
7
- create_mandate: ['mandates:write'],
8
- get_mandate: ['mandates:read'],
9
- search_mandates: ['mandates:read'],
10
- update_mandate: ['mandates:write'],
11
- activate_mandate: ['mandates:write'],
12
- cancel_mandate: ['mandates:write'],
13
- settle_mandate: ['mandates:write'],
14
- request_revision: ['mandates:write'],
15
- delegate_mandate: ['mandates:write'],
16
- get_mandate_graph: ['mandates:read'],
17
- get_mandate_summary: ['mandates:read'],
18
- get_sub_mandates: ['mandates:read'],
19
- get_delegation_chain: ['mandates:read'],
20
- report_outcome: ['mandates:write'],
21
-
22
- // Mandates (agent)
23
- propose_mandate: ['mandates:write'],
24
- propose_agent_mandate: ['mandates:write'],
25
- accept_proposal: ['mandates:write'],
26
- reject_proposal: ['mandates:write'],
27
- counter_proposal: ['mandates:write'],
28
- check_proposals: ['mandates:read'],
29
- list_my_proposals: ['mandates:read'],
30
- list_principal_mandates: ['mandates:read'],
31
-
32
- // A2A
33
- accept_mandate: ['mandates:write'],
34
- reject_mandate: ['mandates:write'],
35
- accept_counter_proposal: ['mandates:write'],
36
- my_mandates: ['mandates:read'],
37
-
38
- // Receipts
39
- submit_receipt: ['receipts:write'],
40
- get_receipt: ['receipts:read'],
41
- list_receipts: ['receipts:read'],
42
- // Verification
43
- verify_mandate: ['mandates:write'],
44
- get_verification_status: ['mandates:read'],
45
-
46
- // Disputes
47
- create_dispute: ['disputes:manage'],
48
- get_dispute: ['disputes:read'],
49
- escalate_dispute: ['disputes:manage'],
50
- submit_dispute_evidence: ['disputes:manage'],
51
-
52
- // Events / Audit
53
- get_audit_trail: ['audit:read'],
54
-
55
- // Schemas
56
- list_contract_schemas: ['schemas:read'],
57
- get_contract_schema: ['schemas:read'],
58
- get_schema_rules: ['schemas:read'],
59
- get_schema_versions: ['schemas:read'],
60
- get_schema_version: ['schemas:read'],
61
- diff_schema_versions: ['schemas:read'],
62
- get_meta_schema: ['schemas:read'],
63
- get_blank_schema_template: ['schemas:read'],
64
- get_schema_template: ['schemas:read'],
65
- preview_schema: ['schemas:read'],
66
- check_schema_compatibility: ['schemas:read'],
67
- register_schema: ['schemas:write'],
68
- delete_schema: ['schemas:write'],
69
- export_schema: ['schemas:read'],
70
- import_schema: ['schemas:write'],
71
- validate_receipt_schema: ['schemas:read'],
72
-
73
- // Enterprise management
74
- approve_enterprise_agent: ['agents:manage'],
75
- revoke_enterprise_agent: ['agents:manage'],
76
- list_enterprise_agents: ['agents:read'],
77
- create_enterprise: ['admin:trust'],
78
- create_agent: ['admin:trust'],
79
- set_enterprise_config: ['admin:trust'],
80
-
81
- // Agents & References
82
- get_agent: ['agents:read'],
83
- update_agent: ['agents:manage'],
84
- add_agent_references: ['agents:manage'],
85
- get_agent_references: ['agents:read'],
86
- lookup_reference: ['agents:read'],
87
- add_mandate_references: ['mandates:write'],
88
- get_mandate_references: ['mandates:read'],
89
-
90
- // Capabilities
91
- get_agent_capabilities: ['agents:read'],
92
- declare_capabilities: ['agents:manage'],
93
-
94
- // Reputation
95
- get_agent_reputation: ['reputation:read'],
96
- get_reputation_by_type: ['reputation:read'],
97
- get_agent_history: ['reputation:read'],
98
- check_reputation: ['reputation:read'],
99
-
100
- // Dashboard
101
- get_dashboard_summary: ['dashboard:read'],
102
- get_dashboard_metrics: ['dashboard:read'],
103
- get_dashboard_alerts: ['dashboard:read'],
104
-
105
- // Compliance
106
- create_compliance_record: ['compliance:write'],
107
- list_compliance_records: ['compliance:read'],
108
- get_eu_ai_act_report: ['compliance:read'],
109
-
110
- // Health
111
- check_api_health: [],
112
-
113
- // Verification Keys (public, no auth required)
114
- list_verification_keys: [],
115
-
116
- // Federation Gateway
117
- federation_register: [],
118
- federation_heartbeat: [],
119
- federation_register_agent: [],
120
- federation_list_agents: [],
121
- federation_submit_transition: [],
122
- federation_relay_signal: [],
123
- federation_rotate_key: [],
124
- federation_revoke: [],
125
- federation_catch_up: [],
126
- federation_stream: [],
127
- federation_publish_schema: [],
128
- federation_confirm_schema_publish: [],
129
- federation_list_contract_types: [],
130
- federation_get_contract_type: [],
131
- federation_get_mandate_criteria: [],
132
- federation_submit_mandate_criteria: [],
133
- federation_contribute_reputation: [],
134
- federation_get_agent_reputation: [],
135
- federation_broadcast_revocations: [],
136
- federation_sync_agent_directory: [],
137
-
138
- // Federation Admin
139
- federation_create_token: ['admin:system'],
140
- federation_list_gateways: ['admin:system'],
141
- federation_admin_revoke: ['admin:system'],
142
- federation_query_mandates: ['admin:system'],
143
- federation_audit_log: ['admin:system'],
144
- federation_health: ['admin:system'],
145
- federation_reset_sequence: ['admin:system'],
146
- federation_list_dlq: ['admin:system'],
147
- federation_retry_dlq: ['admin:system'],
148
- federation_delete_dlq: ['admin:system'],
149
- federation_rotate_hub_key: ['admin:system'],
150
- federation_list_hub_keys: ['admin:system'],
151
- federation_activate_hub_key: ['admin:system'],
152
- federation_expire_hub_key: ['admin:system'],
153
- federation_register_peer: ['admin:system'],
154
- federation_list_peers: ['admin:system'],
155
- federation_get_peer: ['admin:system'],
156
- federation_revoke_peer: ['admin:system'],
157
- federation_resync_peer: ['admin:system'],
158
- federation_create_peering_token: ['admin:system'],
159
- federation_delete_schema_version: ['admin:system'],
160
- federation_list_reputation_contributions: ['admin:system'],
161
- federation_reset_reputation: ['admin:system'],
162
- federation_get_mandate_criteria_status: ['admin:system'],
163
-
164
- // OpenClaw
165
- agledger_notarize: ['mandates:write', 'receipts:write'],
166
- agledger_receipt: ['receipts:write'],
167
- agledger_status: ['mandates:read'],
168
- agledger_accept: ['mandates:write'],
169
- agledger_verdict: ['mandates:write'],
170
- };
171
-
172
- /**
173
- * Build `_meta` object for a tool, including `requiredScopes`.
174
- * Returns undefined if no scopes are mapped (passthrough).
175
- */
176
- export function toolMeta(toolName: string): Record<string, unknown> | undefined {
177
- const scopes = TOOL_SCOPES[toolName];
178
- if (!scopes || scopes.length === 0) return undefined;
179
- return { requiredScopes: scopes };
180
- }