-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlist.tsx
More file actions
66 lines (61 loc) · 2.44 KB
/
Copy pathlist.tsx
File metadata and controls
66 lines (61 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React, { useEffect } from 'react'
import zod from 'zod'
import { option } from 'pastel'
import { loadMemoConfig } from '@memo/core'
import { getMcpAuthStatus } from '@memo/tools/router/mcp/oauth'
import { formatServer, oauthSettingsFromLoaded } from '../../features/mcp/mcpHelpers'
import type { McpAuthStatus } from '@memo/tools/router/mcp/oauth'
export const options = zod.object({
json: zod
.boolean()
.optional()
.default(false)
.describe(option({ description: 'Output as JSON', alias: 'j' })),
})
export default function McpList({ options: opts }: { options: zod.infer<typeof options> }) {
useEffect(() => {
async function run() {
const loaded = await loadMemoConfig()
const servers = loaded.config.mcp_servers ?? {}
const names = Object.keys(servers)
const settings = oauthSettingsFromLoaded(loaded)
const authStatuses = new Map<string, McpAuthStatus>()
await Promise.all(
names.map(async (name) => {
const config = servers[name]
if (!config) return
try {
const status = await getMcpAuthStatus(config, settings)
authStatuses.set(name, status)
} catch {
authStatuses.set(name, 'unsupported')
}
}),
)
if (opts.json) {
const output: Record<string, unknown> = {}
for (const name of names) {
const server = servers[name]
if (!server) continue
output[name] = {
...server,
auth_status: authStatuses.get(name) ?? 'unsupported',
}
}
console.log(JSON.stringify(output, null, 2))
} else if (names.length === 0) {
console.log('No MCP servers configured. Add one with "memo mcp add".')
} else {
console.log(`MCP servers (${names.length}):`)
for (const name of names) {
const config = servers[name]
if (!config) continue
console.log(formatServer(name, config, authStatuses.get(name)))
}
}
process.exit(process.exitCode ?? 0)
}
run()
}, [])
return null
}