@agledger/mcp-server 1.2.0 → 1.2.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 (47) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/server.d.ts.map +1 -1
  5. package/dist/server.js +6 -2
  6. package/dist/server.js.map +1 -1
  7. package/dist/tool-scopes.d.ts.map +1 -1
  8. package/dist/tool-scopes.js +2 -0
  9. package/dist/tool-scopes.js.map +1 -1
  10. package/dist/tools/code-mode.d.ts.map +1 -1
  11. package/dist/tools/code-mode.js +4 -1
  12. package/dist/tools/code-mode.js.map +1 -1
  13. package/dist/tools/verification-keys.d.ts +5 -0
  14. package/dist/tools/verification-keys.d.ts.map +1 -0
  15. package/dist/tools/verification-keys.js +49 -0
  16. package/dist/tools/verification-keys.js.map +1 -0
  17. package/package.json +1 -6
  18. package/src/enums.ts +48 -0
  19. package/src/errors.ts +37 -0
  20. package/src/index.ts +102 -0
  21. package/src/resources/contract-types.ts +134 -0
  22. package/src/server.ts +134 -0
  23. package/src/tool-scopes.ts +193 -0
  24. package/src/tools/a2a.ts +551 -0
  25. package/src/tools/agent-mandates.ts +336 -0
  26. package/src/tools/agents-refs.ts +296 -0
  27. package/src/tools/capabilities.ts +80 -0
  28. package/src/tools/code-mode.ts +473 -0
  29. package/src/tools/compliance.ts +81 -0
  30. package/src/tools/dashboard.ts +75 -0
  31. package/src/tools/disputes.ts +160 -0
  32. package/src/tools/enterprises.ts +243 -0
  33. package/src/tools/events.ts +55 -0
  34. package/src/tools/federation-admin.ts +948 -0
  35. package/src/tools/federation.ts +806 -0
  36. package/src/tools/health.ts +46 -0
  37. package/src/tools/mandates.ts +394 -0
  38. package/src/tools/openclaw.ts +174 -0
  39. package/src/tools/receipts.ts +185 -0
  40. package/src/tools/reputation.ts +80 -0
  41. package/src/tools/schemas.ts +685 -0
  42. package/src/tools/verification-keys.ts +58 -0
  43. package/src/tools/verification.ts +89 -0
  44. package/tests/code-mode-manifest.test.ts +144 -0
  45. package/tests/enterprises.test.ts +96 -0
  46. package/tests/schemas.test.ts +531 -0
  47. package/tsconfig.json +12 -0
package/src/server.ts ADDED
@@ -0,0 +1,134 @@
1
+ /** AGLedger™ — MCP Server wrapping the AGLedger API for agent consumption. Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved. */
2
+
3
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
+ import { AgledgerClient } from '@agledger/sdk';
5
+
6
+ import { registerMandateTools } from './tools/mandates.js';
7
+ import { registerAgentMandateTools } from './tools/agent-mandates.js';
8
+ import { registerReceiptTools } from './tools/receipts.js';
9
+ import { registerVerificationTools } from './tools/verification.js';
10
+ import { registerDisputeTools } from './tools/disputes.js';
11
+ import { registerReputationTools } from './tools/reputation.js';
12
+ import { registerEventTools } from './tools/events.js';
13
+ import { registerSchemaTools } from './tools/schemas.js';
14
+ import { registerHealthTools } from './tools/health.js';
15
+ import { registerCapabilityTools } from './tools/capabilities.js';
16
+ import { registerA2aTools } from './tools/a2a.js';
17
+ import { registerOpenClawTools } from './tools/openclaw.js';
18
+ import { registerEnterpriseTools } from './tools/enterprises.js';
19
+ import { registerDashboardTools } from './tools/dashboard.js';
20
+ import { registerComplianceTools } from './tools/compliance.js';
21
+ import { registerFederationTools } from './tools/federation.js';
22
+ import { registerFederationAdminTools } from './tools/federation-admin.js';
23
+ import { registerAgentsRefsTools } from './tools/agents-refs.js';
24
+ import { registerCodeModeTools } from './tools/code-mode.js';
25
+ import { registerVerificationKeysTools } from './tools/verification-keys.js';
26
+ import { registerContractTypeResources } from './resources/contract-types.js';
27
+
28
+ export type ToolProfile = 'full' | 'code' | 'a2a' | 'openclaw' | 'schema-dev' | 'admin' | 'audit' | 'federation';
29
+
30
+ export interface AgledgerMcpServerOptions {
31
+ apiKey: string;
32
+ apiUrl?: string;
33
+ /** Tool profile: "code" (2 tools — SDK code execution + docs, replaces full), "a2a", "openclaw", "schema-dev", "admin", "audit", "federation", or "full" (legacy, all individual tools). */
34
+ profile?: ToolProfile;
35
+ /** Enterprise ID for A2A search queries. Falls back to AGLEDGER_ENTERPRISE_ID env var. */
36
+ enterpriseId?: string;
37
+ }
38
+
39
+ export class AgledgerMcpServer {
40
+ readonly mcp: McpServer;
41
+ readonly client: AgledgerClient;
42
+ readonly profile: ToolProfile;
43
+ private readonly enterpriseId?: string;
44
+
45
+ constructor(options: AgledgerMcpServerOptions) {
46
+ this.profile = options.profile ?? 'full';
47
+ this.enterpriseId = options.enterpriseId;
48
+
49
+ this.mcp = new McpServer(
50
+ {
51
+ name: 'agledger-mcp-server',
52
+ version: '1.2.1',
53
+ },
54
+ {
55
+ capabilities: {
56
+ tools: {},
57
+ resources: {},
58
+ },
59
+ },
60
+ );
61
+
62
+ this.client = new AgledgerClient({
63
+ apiKey: options.apiKey,
64
+ baseUrl: options.apiUrl ?? 'https://agledger.example.com',
65
+ });
66
+
67
+ this.registerTools();
68
+ }
69
+
70
+ private registerTools(): void {
71
+ if (this.profile === 'code') {
72
+ // Code mode: 2 tools — SDK code execution + documentation (replaces full)
73
+ registerCodeModeTools(this.mcp, this.client);
74
+ } else if (this.profile === 'openclaw') {
75
+ // OpenClaw profile: 5 thin notarization tools (<500 tokens total schema)
76
+ registerOpenClawTools(this.mcp, this.client);
77
+ } else if (this.profile === 'a2a') {
78
+ // Focused A2A profile: agent-to-agent tools + agent identity + references
79
+ registerA2aTools(this.mcp, this.client, { enterpriseId: this.enterpriseId });
80
+ registerAgentsRefsTools(this.mcp, this.client);
81
+ } else if (this.profile === 'schema-dev') {
82
+ // Schema development profile: schema tools + health check
83
+ registerSchemaTools(this.mcp, this.client);
84
+ registerHealthTools(this.mcp, this.client);
85
+ } else if (this.profile === 'admin') {
86
+ // Admin profile: enterprise + agent management + references + federation admin
87
+ registerEnterpriseTools(this.mcp, this.client);
88
+ registerCapabilityTools(this.mcp, this.client);
89
+ registerReputationTools(this.mcp, this.client);
90
+ registerAgentsRefsTools(this.mcp, this.client);
91
+ registerFederationAdminTools(this.mcp, this.client);
92
+ registerHealthTools(this.mcp, this.client);
93
+ registerVerificationKeysTools(this.mcp, this.client);
94
+ } else if (this.profile === 'federation') {
95
+ // Federation profile: gateway ops + admin ops + agent identity + health
96
+ registerFederationTools(this.mcp, this.client);
97
+ registerFederationAdminTools(this.mcp, this.client);
98
+ registerAgentsRefsTools(this.mcp, this.client);
99
+ registerHealthTools(this.mcp, this.client);
100
+ } else if (this.profile === 'audit') {
101
+ // Audit profile: read-only compliance monitoring + dashboard + agent lookup
102
+ registerEventTools(this.mcp, this.client);
103
+ registerVerificationTools(this.mcp, this.client);
104
+ registerDisputeTools(this.mcp, this.client);
105
+ registerReputationTools(this.mcp, this.client);
106
+ registerDashboardTools(this.mcp, this.client);
107
+ registerComplianceTools(this.mcp, this.client);
108
+ registerAgentsRefsTools(this.mcp, this.client);
109
+ registerHealthTools(this.mcp, this.client);
110
+ registerVerificationKeysTools(this.mcp, this.client);
111
+ } else {
112
+ // Full profile (legacy): all individual tools
113
+ registerMandateTools(this.mcp, this.client);
114
+ registerAgentMandateTools(this.mcp, this.client);
115
+ registerReceiptTools(this.mcp, this.client);
116
+ registerVerificationTools(this.mcp, this.client);
117
+ registerDisputeTools(this.mcp, this.client);
118
+ registerReputationTools(this.mcp, this.client);
119
+ registerEventTools(this.mcp, this.client);
120
+ registerSchemaTools(this.mcp, this.client);
121
+ registerHealthTools(this.mcp, this.client);
122
+ registerCapabilityTools(this.mcp, this.client);
123
+ registerEnterpriseTools(this.mcp, this.client);
124
+ registerDashboardTools(this.mcp, this.client);
125
+ registerComplianceTools(this.mcp, this.client);
126
+ registerFederationTools(this.mcp, this.client);
127
+ registerFederationAdminTools(this.mcp, this.client);
128
+ registerAgentsRefsTools(this.mcp, this.client);
129
+ registerVerificationKeysTools(this.mcp, this.client);
130
+ }
131
+ // Resources are always available
132
+ registerContractTypeResources(this.mcp, this.client);
133
+ }
134
+ }
@@ -0,0 +1,193 @@
1
+ /**
2
+ * AGLedger™ — Tool-level scope annotations (SEP-1880 early adoption).
3
+ * Patent Pending. Copyright 2026 AGLedger LLC. All rights reserved.
4
+ *
5
+ * Maps each MCP tool to the API scopes it requires. Exposed via `_meta.requiredScopes`
6
+ * on each tool definition so MCP clients can pre-filter tools the session can't use.
7
+ *
8
+ * Uses `_meta` (MCP spec vendor metadata) with the `requiredScopes` key.
9
+ * When SEP-1880 is accepted, migrate to the standard annotation key.
10
+ *
11
+ * @see https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1880
12
+ */
13
+
14
+ /**
15
+ * Required scopes for each tool, keyed by tool name.
16
+ * Read scopes grant access; write scopes imply read.
17
+ */
18
+ export const TOOL_SCOPES: Record<string, string[]> = {
19
+ // --- Mandates (enterprise) ---
20
+ create_mandate: ['mandates:write'],
21
+ get_mandate: ['mandates:read'],
22
+ search_mandates: ['mandates:read'],
23
+ update_mandate: ['mandates:write'],
24
+ activate_mandate: ['mandates:write'],
25
+ cancel_mandate: ['mandates:write'],
26
+ settle_mandate: ['mandates:write'],
27
+ request_revision: ['mandates:write'],
28
+ delegate_mandate: ['mandates:write'],
29
+ get_mandate_graph: ['mandates:read'],
30
+ get_mandate_summary: ['mandates:read'],
31
+ get_sub_mandates: ['mandates:read'],
32
+ get_delegation_chain: ['mandates:read'],
33
+ report_outcome: ['mandates:write'],
34
+
35
+ // --- Mandates (agent) ---
36
+ propose_mandate: ['mandates:write'],
37
+ propose_agent_mandate: ['mandates:write'],
38
+ accept_proposal: ['mandates:write'],
39
+ reject_proposal: ['mandates:write'],
40
+ counter_proposal: ['mandates:write'],
41
+ check_proposals: ['mandates:read'],
42
+ list_my_proposals: ['mandates:read'],
43
+ list_principal_mandates: ['mandates:read'],
44
+
45
+ // --- A2A ---
46
+ accept_mandate: ['mandates:write'],
47
+ my_mandates: ['mandates:read'],
48
+
49
+ // --- Receipts ---
50
+ submit_receipt: ['receipts:write'],
51
+ get_receipt: ['receipts:read'],
52
+ list_receipts: ['receipts:read'],
53
+ validate_receipt_schema: ['receipts:read', 'schemas:read'],
54
+
55
+ // --- Verification ---
56
+ verify_mandate: ['mandates:write'],
57
+ get_verification_status: ['mandates:read'],
58
+
59
+ // --- Disputes ---
60
+ create_dispute: ['disputes:manage'],
61
+ get_dispute: ['disputes:read'],
62
+ escalate_dispute: ['disputes:manage'],
63
+ submit_dispute_evidence: ['disputes:manage'],
64
+
65
+ // --- Events / Audit ---
66
+ get_audit_trail: ['audit:read'],
67
+
68
+ // --- Schemas ---
69
+ list_contract_schemas: ['schemas:read'],
70
+ get_contract_schema: ['schemas:read'],
71
+ get_schema_rules: ['schemas:read'],
72
+ get_schema_versions: ['schemas:read'],
73
+ get_schema_version: ['schemas:read'],
74
+ diff_schema_versions: ['schemas:read'],
75
+ get_meta_schema: ['schemas:read'],
76
+ get_blank_schema_template: ['schemas:read'],
77
+ get_schema_template: ['schemas:read'],
78
+ preview_schema: ['schemas:read'],
79
+ check_schema_compatibility: ['schemas:read'],
80
+ register_schema: ['schemas:write'],
81
+ delete_schema: ['schemas:write'],
82
+ export_schema: ['schemas:read'],
83
+ import_schema: ['schemas:write'],
84
+ validate_receipt_against_schema: ['schemas:read'],
85
+
86
+ // --- Enterprise management ---
87
+ approve_enterprise_agent: ['agents:manage'],
88
+ revoke_enterprise_agent: ['agents:manage'],
89
+ list_enterprise_agents: ['agents:read'],
90
+ create_enterprise: ['admin:trust'],
91
+ create_agent: ['admin:trust'],
92
+ set_enterprise_config: ['admin:trust'],
93
+
94
+ // --- Agents & References ---
95
+ get_agent: ['agents:read'],
96
+ update_agent: ['agents:manage'],
97
+ add_agent_references: ['agents:manage'],
98
+ get_agent_references: ['agents:read'],
99
+ lookup_reference: ['agents:read'],
100
+ add_mandate_references: ['mandates:write'],
101
+ get_mandate_references: ['mandates:read'],
102
+
103
+ // --- Capabilities ---
104
+ get_agent_capabilities: ['agents:read'],
105
+ declare_capabilities: ['agents:manage'],
106
+
107
+ // --- Reputation ---
108
+ get_agent_reputation: ['reputation:read'],
109
+ get_reputation_by_type: ['reputation:read'],
110
+ get_agent_history: ['reputation:read'],
111
+ check_reputation: ['reputation:read'],
112
+
113
+ // --- Dashboard ---
114
+ get_dashboard_summary: ['dashboard:read'],
115
+ get_dashboard_metrics: ['dashboard:read'],
116
+ get_dashboard_alerts: ['dashboard:read'],
117
+
118
+ // --- Compliance ---
119
+ create_compliance_record: ['compliance:write'],
120
+ list_compliance_records: ['compliance:read'],
121
+ get_eu_ai_act_report: ['compliance:read'],
122
+
123
+ // --- Health ---
124
+ check_api_health: [],
125
+
126
+ // --- Verification Keys (public, no auth required) ---
127
+ list_verification_keys: [],
128
+
129
+ // --- Federation Gateway ---
130
+ federation_register: [],
131
+ federation_heartbeat: [],
132
+ federation_register_agent: [],
133
+ federation_list_agents: [],
134
+ federation_submit_transition: [],
135
+ federation_relay_signal: [],
136
+ federation_rotate_key: [],
137
+ federation_revoke: [],
138
+ federation_catch_up: [],
139
+ federation_stream: [],
140
+ federation_publish_schema: [],
141
+ federation_confirm_schema_publish: [],
142
+ federation_list_contract_types: [],
143
+ federation_get_contract_type: [],
144
+ federation_get_mandate_criteria: [],
145
+ federation_submit_mandate_criteria: [],
146
+ federation_contribute_reputation: [],
147
+ federation_get_agent_reputation: [],
148
+ federation_broadcast_revocations: [],
149
+ federation_sync_agent_directory: [],
150
+
151
+ // --- Federation Admin ---
152
+ federation_create_token: ['admin:system'],
153
+ federation_list_gateways: ['admin:system'],
154
+ federation_admin_revoke: ['admin:system'],
155
+ federation_query_mandates: ['admin:system'],
156
+ federation_audit_log: ['admin:system'],
157
+ federation_health: ['admin:system'],
158
+ federation_reset_sequence: ['admin:system'],
159
+ federation_list_dlq: ['admin:system'],
160
+ federation_retry_dlq: ['admin:system'],
161
+ federation_delete_dlq: ['admin:system'],
162
+ federation_rotate_hub_key: ['admin:system'],
163
+ federation_list_hub_keys: ['admin:system'],
164
+ federation_activate_hub_key: ['admin:system'],
165
+ federation_expire_hub_key: ['admin:system'],
166
+ federation_register_peer: ['admin:system'],
167
+ federation_list_peers: ['admin:system'],
168
+ federation_get_peer: ['admin:system'],
169
+ federation_revoke_peer: ['admin:system'],
170
+ federation_resync_peer: ['admin:system'],
171
+ federation_create_peering_token: ['admin:system'],
172
+ federation_delete_schema_version: ['admin:system'],
173
+ federation_list_reputation_contributions: ['admin:system'],
174
+ federation_reset_reputation: ['admin:system'],
175
+ federation_get_mandate_criteria_status: ['admin:system'],
176
+
177
+ // --- OpenClaw ---
178
+ agledger_notarize: ['mandates:write', 'receipts:write'],
179
+ agledger_receipt: ['receipts:write'],
180
+ agledger_status: ['mandates:read'],
181
+ agledger_accept: ['mandates:write'],
182
+ agledger_verdict: ['mandates:write'],
183
+ };
184
+
185
+ /**
186
+ * Build `_meta` object for a tool, including `requiredScopes`.
187
+ * Returns undefined if no scopes are mapped (passthrough).
188
+ */
189
+ export function toolMeta(toolName: string): Record<string, unknown> | undefined {
190
+ const scopes = TOOL_SCOPES[toolName];
191
+ if (!scopes || scopes.length === 0) return undefined;
192
+ return { requiredScopes: scopes };
193
+ }