List Registered Agents
listRegisteredAgentsRetrieve registered agent details and enriched data from the AgentScore Registry, optionally filtering by owner address to access performance metrics and registration information.
Instructions
List all agents (or single agent by owner address). Returns enriched data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | No | Optional owner address |
Implementation Reference
- src/tools.ts:169-260 (handler)The handler function for the `listRegisteredAgents` tool, which fetches agent profiles from the smart contract.
async ({ owner }: { owner?: string }) => { try { const agents: any[] = []; if (owner) { const addr = owner.toLowerCase() as `0x${string}`; const tokenId = await publicClient.readContract({ address: CONTRACT_ADDRESS, abi: AGENT_SCORE_ABI, functionName: "agentIds", args: [addr], }); if (tokenId === 0n) return { content: [{ type: "text", text: "[]" }], }; const profile = (await publicClient.readContract({ address: CONTRACT_ADDRESS, abi: AGENT_SCORE_ABI, functionName: "agentProfiles", args: [tokenId], })) as AgentProfile; const uri = await publicClient.readContract({ address: CONTRACT_ADDRESS, abi: AGENT_SCORE_ABI, functionName: "tokenURI", args: [tokenId], }); const ownerAddr = await publicClient.readContract({ address: CONTRACT_ADDRESS, abi: AGENT_SCORE_ABI, functionName: "ownerOf", args: [tokenId], }); agents.push({ tokenId: Number(tokenId), owner: ownerAddr, score: Number(profile.score), metadataURI: uri, }); } else { const tokenIds = await publicClient.readContract({ address: CONTRACT_ADDRESS, abi: AGENT_SCORE_ABI, functionName: "getAllAgents", }); const enriched = await Promise.all( tokenIds.map(async (tid) => { const profile = (await publicClient.readContract({ address: CONTRACT_ADDRESS, abi: AGENT_SCORE_ABI, functionName: "agentProfiles", args: [tid], })) as AgentProfile; const uri = await publicClient.readContract({ address: CONTRACT_ADDRESS, abi: AGENT_SCORE_ABI, functionName: "tokenURI", args: [tid], }); const ownerAddr = await publicClient.readContract({ address: CONTRACT_ADDRESS, abi: AGENT_SCORE_ABI, functionName: "ownerOf", args: [tid], }); return { tokenId: Number(tid), owner: ownerAddr, score: Number(profile.score), metadataURI: uri, }; }), ); agents.push(...enriched); } return { content: [ { type: "text", text: JSON.stringify(agents, null, 2) }, ], }; } catch (err: any) { return { isError: true, content: [{ type: "text", text: `Error: ${err.message}` }], }; } }, - src/tools.ts:153-167 (schema)Input and output schema definitions for the `listRegisteredAgents` tool.
inputSchema: z.object({ owner: z .string() .regex(/^0x[a-fA-F0-9]{40}$/i) .optional() .describe("Optional owner address"), }), outputSchema: z.array( z.object({ tokenId: z.number(), owner: z.string(), score: z.number(), metadataURI: z.string(), }), ), - src/tools.ts:146-168 (registration)Registration of the `listRegisteredAgents` tool with the server.
// Tool 3: listRegisteredAgents server.registerTool( "listRegisteredAgents", { title: "List Registered Agents", description: "List all agents (or single agent by owner address). Returns enriched data.", inputSchema: z.object({ owner: z .string() .regex(/^0x[a-fA-F0-9]{40}$/i) .optional() .describe("Optional owner address"), }), outputSchema: z.array( z.object({ tokenId: z.number(), owner: z.string(), score: z.number(), metadataURI: z.string(), }), ), },