@rickydata/agent0-mcp 0.1.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 (70) hide show
  1. package/.env.example +17 -0
  2. package/Dockerfile +25 -0
  3. package/README.md +85 -0
  4. package/dist/auth/sdk-client.d.ts +47 -0
  5. package/dist/auth/sdk-client.js +142 -0
  6. package/dist/auth/sdk-client.js.map +1 -0
  7. package/dist/auth/token.d.ts +5 -0
  8. package/dist/auth/token.js +6 -0
  9. package/dist/auth/token.js.map +1 -0
  10. package/dist/auth/wallet-derivation.d.ts +26 -0
  11. package/dist/auth/wallet-derivation.js +76 -0
  12. package/dist/auth/wallet-derivation.js.map +1 -0
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +140 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/tools/a2a.d.ts +3 -0
  17. package/dist/tools/a2a.js +170 -0
  18. package/dist/tools/a2a.js.map +1 -0
  19. package/dist/tools/discovery.d.ts +3 -0
  20. package/dist/tools/discovery.js +465 -0
  21. package/dist/tools/discovery.js.map +1 -0
  22. package/dist/tools/index.d.ts +3 -0
  23. package/dist/tools/index.js +38 -0
  24. package/dist/tools/index.js.map +1 -0
  25. package/dist/tools/payments.d.ts +3 -0
  26. package/dist/tools/payments.js +124 -0
  27. package/dist/tools/payments.js.map +1 -0
  28. package/dist/tools/registration.d.ts +3 -0
  29. package/dist/tools/registration.js +324 -0
  30. package/dist/tools/registration.js.map +1 -0
  31. package/dist/tools/reputation.d.ts +3 -0
  32. package/dist/tools/reputation.js +147 -0
  33. package/dist/tools/reputation.js.map +1 -0
  34. package/dist/utils/chains.d.ts +10 -0
  35. package/dist/utils/chains.js +33 -0
  36. package/dist/utils/chains.js.map +1 -0
  37. package/dist/utils/trust-labels.d.ts +10 -0
  38. package/dist/utils/trust-labels.js +48 -0
  39. package/dist/utils/trust-labels.js.map +1 -0
  40. package/dist/utils/validation.d.ts +12 -0
  41. package/dist/utils/validation.js +19 -0
  42. package/dist/utils/validation.js.map +1 -0
  43. package/package.json +32 -0
  44. package/src/auth/sdk-client.ts +171 -0
  45. package/src/auth/token.ts +19 -0
  46. package/src/auth/wallet-derivation.ts +91 -0
  47. package/src/index.ts +184 -0
  48. package/src/tools/a2a.ts +205 -0
  49. package/src/tools/discovery.ts +517 -0
  50. package/src/tools/index.ts +45 -0
  51. package/src/tools/payments.ts +146 -0
  52. package/src/tools/registration.ts +389 -0
  53. package/src/tools/reputation.ts +183 -0
  54. package/src/utils/chains.ts +42 -0
  55. package/src/utils/trust-labels.ts +53 -0
  56. package/src/utils/validation.ts +20 -0
  57. package/tests/a2a.test.ts +234 -0
  58. package/tests/chains.test.ts +57 -0
  59. package/tests/discovery.test.ts +455 -0
  60. package/tests/e2e.test.ts +234 -0
  61. package/tests/payments.test.ts +148 -0
  62. package/tests/registration.test.ts +313 -0
  63. package/tests/reputation.test.ts +231 -0
  64. package/tests/sdk-client.test.ts +143 -0
  65. package/tests/tool-router.test.ts +28 -0
  66. package/tests/trust-labels.test.ts +229 -0
  67. package/tests/validation.test.ts +132 -0
  68. package/tests/wallet-derivation.test.ts +109 -0
  69. package/tsconfig.json +8 -0
  70. package/vitest.config.ts +8 -0
@@ -0,0 +1,205 @@
1
+ import type { Tool } from "@modelcontextprotocol/sdk/types.js";
2
+ import {
3
+ getAuthenticatedSDK,
4
+ getReadOnlySDK,
5
+ hasAuthentication,
6
+ } from "../auth/sdk-client.js";
7
+ import { getChainName } from "../utils/chains.js";
8
+
9
+ export const a2aTools: Tool[] = [
10
+ {
11
+ name: "a2a_send_message",
12
+ description:
13
+ "Send a message to an ERC-8004 agent via the A2A (Agent-to-Agent) protocol. " +
14
+ "The agent must have an A2A endpoint configured. Requires configured wallet. " +
15
+ "Returns a task ID for tracking the conversation.",
16
+ inputSchema: {
17
+ type: "object" as const,
18
+ properties: {
19
+ agentId: {
20
+ type: "string",
21
+ description: "Agent ID in chainId:tokenId format (e.g. '11155111:42')",
22
+ },
23
+ message: {
24
+ type: "string",
25
+ description: "Message text to send to the agent",
26
+ },
27
+ taskId: {
28
+ type: "string",
29
+ description: "Existing task ID to continue a conversation (optional)",
30
+ },
31
+ },
32
+ required: ["agentId", "message"],
33
+ },
34
+ },
35
+ {
36
+ name: "a2a_list_tasks",
37
+ description:
38
+ "List A2A tasks/conversations with a specific agent. " +
39
+ "Returns task IDs, statuses, and summaries.",
40
+ inputSchema: {
41
+ type: "object" as const,
42
+ properties: {
43
+ agentId: {
44
+ type: "string",
45
+ description: "Agent ID in chainId:tokenId format",
46
+ },
47
+ },
48
+ required: ["agentId"],
49
+ },
50
+ },
51
+ {
52
+ name: "a2a_get_task",
53
+ description:
54
+ "Get details of a specific A2A task including messages and artifacts.",
55
+ inputSchema: {
56
+ type: "object" as const,
57
+ properties: {
58
+ agentId: {
59
+ type: "string",
60
+ description: "Agent ID in chainId:tokenId format",
61
+ },
62
+ taskId: {
63
+ type: "string",
64
+ description: "Task ID to retrieve",
65
+ },
66
+ },
67
+ required: ["agentId", "taskId"],
68
+ },
69
+ },
70
+ ];
71
+
72
+ // ============================================================================
73
+ // HELPERS
74
+ // ============================================================================
75
+
76
+ function requireAuth() {
77
+ if (!hasAuthentication()) {
78
+ return {
79
+ sdk: null as ReturnType<typeof getAuthenticatedSDK>,
80
+ error: "No wallet configured. Call configure_wallet first.",
81
+ };
82
+ }
83
+ const sdk = getAuthenticatedSDK();
84
+ if (!sdk) {
85
+ return { sdk: null as ReturnType<typeof getAuthenticatedSDK>, error: "Failed to initialize authenticated SDK." };
86
+ }
87
+ return { sdk, error: undefined };
88
+ }
89
+
90
+ function parseChainId(agentId: string): number {
91
+ const parts = agentId.split(":");
92
+ return parts.length === 2 ? parseInt(parts[0], 10) : 11155111;
93
+ }
94
+
95
+ // ============================================================================
96
+ // HANDLERS
97
+ // ============================================================================
98
+
99
+ async function handleSendMessage(
100
+ args: Record<string, unknown>,
101
+ ): Promise<unknown> {
102
+ const { sdk, error } = requireAuth();
103
+ if (error || !sdk) return { error };
104
+
105
+ const agentId = args.agentId as string;
106
+ const message = args.message as string;
107
+
108
+ // Load agent summary to get A2A endpoint
109
+ const agentSummary = await sdk.getAgent(agentId);
110
+ if (!agentSummary) {
111
+ return { error: `Agent ${agentId} not found` };
112
+ }
113
+ if (!agentSummary.a2a) {
114
+ return {
115
+ error: `Agent ${agentId} does not have an A2A endpoint configured`,
116
+ };
117
+ }
118
+
119
+ // Create A2A client from summary
120
+ const a2aClient = sdk.createA2AClient(agentSummary);
121
+
122
+ // Send message
123
+ const result = await (a2aClient as any).messageA2A(message, {
124
+ taskId: (args.taskId as string) ?? undefined,
125
+ });
126
+
127
+ const chainId = parseChainId(agentId);
128
+ return {
129
+ success: true,
130
+ agentId,
131
+ chain: getChainName(chainId),
132
+ taskId: result?.taskId ?? result?.id,
133
+ status: result?.status,
134
+ response: result?.response ?? result?.text ?? result,
135
+ };
136
+ }
137
+
138
+ async function handleListTasks(
139
+ args: Record<string, unknown>,
140
+ ): Promise<unknown> {
141
+ const { sdk, error } = requireAuth();
142
+ if (error || !sdk) return { error };
143
+
144
+ const agentId = args.agentId as string;
145
+ const agentSummary = await sdk.getAgent(agentId);
146
+ if (!agentSummary) {
147
+ return { error: `Agent ${agentId} not found` };
148
+ }
149
+ if (!agentSummary.a2a) {
150
+ return { error: `Agent ${agentId} does not have an A2A endpoint` };
151
+ }
152
+
153
+ const a2aClient = sdk.createA2AClient(agentSummary);
154
+ const tasks = await (a2aClient as any).listTasks();
155
+
156
+ return {
157
+ agentId,
158
+ count: Array.isArray(tasks) ? tasks.length : 0,
159
+ tasks: tasks ?? [],
160
+ };
161
+ }
162
+
163
+ async function handleGetTask(
164
+ args: Record<string, unknown>,
165
+ ): Promise<unknown> {
166
+ const { sdk, error } = requireAuth();
167
+ if (error || !sdk) return { error };
168
+
169
+ const agentId = args.agentId as string;
170
+ const taskId = args.taskId as string;
171
+
172
+ const agentSummary = await sdk.getAgent(agentId);
173
+ if (!agentSummary) {
174
+ return { error: `Agent ${agentId} not found` };
175
+ }
176
+
177
+ const a2aClient = sdk.createA2AClient(agentSummary);
178
+ const task = await (a2aClient as any).loadTask(taskId);
179
+
180
+ return {
181
+ agentId,
182
+ taskId,
183
+ task: task ?? { error: "Task not found" },
184
+ };
185
+ }
186
+
187
+ // ============================================================================
188
+ // DISPATCH
189
+ // ============================================================================
190
+
191
+ export async function handleA2ATool(
192
+ name: string,
193
+ args: Record<string, unknown>,
194
+ ): Promise<unknown> {
195
+ switch (name) {
196
+ case "a2a_send_message":
197
+ return handleSendMessage(args);
198
+ case "a2a_list_tasks":
199
+ return handleListTasks(args);
200
+ case "a2a_get_task":
201
+ return handleGetTask(args);
202
+ default:
203
+ return { error: `Unknown A2A tool: ${name}` };
204
+ }
205
+ }