@@ -6,48 +6,43 @@ import { type CloudflareMcpAgent } from '../types/cloudflare-mcp-agent'
66
77export function registerAccountTools ( agent : CloudflareMcpAgent ) {
88 // Tool to list all accounts
9- agent . server . tool (
10- 'accounts_list' ,
11- 'List all accounts in your Cloudflare account' ,
12- { } ,
13- async ( ) => {
14- try {
15- const results = await handleAccountsList ( {
16- client : getCloudflareClient ( agent . props . accessToken ) ,
9+ agent . server . tool ( 'accounts_list' , 'List all accounts in your Cloudflare account' , async ( ) => {
10+ try {
11+ const results = await handleAccountsList ( {
12+ client : getCloudflareClient ( agent . props . accessToken ) ,
13+ } )
14+ // Sort accounts by created_on date (newest first)
15+ const accounts = results
16+ // order by created_on desc ( newest first )
17+ . sort ( ( a , b ) => {
18+ if ( ! a . created_on ) return 1
19+ if ( ! b . created_on ) return - 1
20+ return new Date ( b . created_on ) . getTime ( ) - new Date ( a . created_on ) . getTime ( )
1721 } )
18- // Sort accounts by created_on date (newest first)
19- const accounts = results
20- // order by created_on desc ( newest first )
21- . sort ( ( a , b ) => {
22- if ( ! a . created_on ) return 1
23- if ( ! b . created_on ) return - 1
24- return new Date ( b . created_on ) . getTime ( ) - new Date ( a . created_on ) . getTime ( )
25- } )
2622
27- return {
28- content : [
29- {
30- type : 'text' ,
31- text : JSON . stringify ( {
32- accounts,
33- count : accounts . length ,
34- } ) ,
35- } ,
36- ] ,
37- }
38- } catch ( e ) {
39- agent . server . recordError ( e )
40- return {
41- content : [
42- {
43- type : 'text' ,
44- text : `Error listing accounts: ${ e instanceof Error && e . message } ` ,
45- } ,
46- ] ,
47- }
23+ return {
24+ content : [
25+ {
26+ type : 'text' ,
27+ text : JSON . stringify ( {
28+ accounts,
29+ count : accounts . length ,
30+ } ) ,
31+ } ,
32+ ] ,
33+ }
34+ } catch ( e ) {
35+ agent . server . recordError ( e )
36+ return {
37+ content : [
38+ {
39+ type : 'text' ,
40+ text : `Error listing accounts: ${ e instanceof Error && e . message } ` ,
41+ } ,
42+ ] ,
4843 }
4944 }
50- )
45+ } )
5146
5247 const activeAccountIdParam = z
5348 . string ( )
0 commit comments