@agledger/mcp-server 1.5.0 → 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 (66) 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/src/enums.ts +0 -47
  21. package/src/errors.ts +0 -44
  22. package/src/resources/contract-types.ts +0 -130
  23. package/src/tool-scopes.ts +0 -180
  24. package/src/tools/a2a.ts +0 -430
  25. package/src/tools/agent-mandates.ts +0 -259
  26. package/src/tools/agents-refs.ts +0 -232
  27. package/src/tools/capabilities.ts +0 -63
  28. package/src/tools/compliance.ts +0 -70
  29. package/src/tools/dashboard.ts +0 -64
  30. package/src/tools/disputes.ts +0 -121
  31. package/src/tools/enterprises.ts +0 -203
  32. package/src/tools/events.ts +0 -33
  33. package/src/tools/federation-admin.ts +0 -665
  34. package/src/tools/federation.ts +0 -587
  35. package/src/tools/health.ts +0 -30
  36. package/src/tools/mandates.ts +0 -264
  37. package/src/tools/openclaw.ts +0 -122
  38. package/src/tools/receipts.ts +0 -134
  39. package/src/tools/reputation.ts +0 -69
  40. package/src/tools/schemas.ts +0 -535
  41. package/src/tools/verification-keys.ts +0 -33
  42. package/src/tools/verification.ts +0 -59
  43. package/tests/conformance.test.ts +0 -197
  44. package/tests/conformance.ts +0 -65
  45. package/tests/mock-client.ts +0 -71
  46. package/tests/profiles.test.ts +0 -120
  47. package/tests/resources/contract-types.test.ts +0 -82
  48. package/tests/tools/a2a.test.ts +0 -213
  49. package/tests/tools/agent-mandates.test.ts +0 -196
  50. package/tests/tools/agents-refs.test.ts +0 -190
  51. package/tests/tools/capabilities.test.ts +0 -80
  52. package/tests/tools/compliance.test.ts +0 -123
  53. package/tests/tools/dashboard.test.ts +0 -111
  54. package/tests/tools/disputes.test.ts +0 -123
  55. package/tests/tools/enterprises.test.ts +0 -171
  56. package/tests/tools/events.test.ts +0 -56
  57. package/tests/tools/federation-admin.test.ts +0 -468
  58. package/tests/tools/federation.test.ts +0 -522
  59. package/tests/tools/health.test.ts +0 -56
  60. package/tests/tools/mandates.test.ts +0 -143
  61. package/tests/tools/openclaw.test.ts +0 -148
  62. package/tests/tools/receipts.test.ts +0 -157
  63. package/tests/tools/reputation.test.ts +0 -108
  64. package/tests/tools/schemas.test.ts +0 -374
  65. package/tests/tools/verification-keys.test.ts +0 -56
  66. 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
- }