MCPcopy Index your code
hub / github.com/serverless/serverless / listProjects

Function listProjects

packages/mcp/src/tools/list-projects.js:17–141  ·  view source on GitHub ↗
(params)

Source from the content-addressed store, hash-verified

15 * @returns {Promise<{projects: string[], multipleFound: boolean}>} - Information about found projects
16 */
17export async function listProjects(params) {
18 // Mark that list-projects has been called
19 setListProjectsCalled()
20
21 const { workspaceRoots, userConfirmed } = params
22
23 // Check if user has confirmed
24 if (!userConfirmed) {
25 return {
26 content: [
27 {
28 type: 'text',
29 text:
30 '⚠️⚠️⚠️ ERROR: USER CONFIRMATION REQUIRED ⚠️⚠️⚠️\n\n' +
31 'You MUST explicitly ask the user for permission before searching for projects.\n\n' +
32 'Required workflow:\n' +
33 '1. Ask the user: "Should I search for serverless projects in the following workspace paths: ' +
34 JSON.stringify(workspaceRoots) +
35 '?"\n' +
36 '2. Wait for explicit user confirmation\n' +
37 '3. If user confirms, call this tool again with userConfirmed=true\n' +
38 '4. If user does NOT confirm, ask for the FULL ABSOLUTE PATH to the project directory\n' +
39 '5. Once the user provides a specific path, replace workspaceRoots with ONLY that path',
40 },
41 ],
42 isError: true,
43 }
44 }
45
46 if (
47 !workspaceRoots ||
48 !Array.isArray(workspaceRoots) ||
49 workspaceRoots.length === 0
50 ) {
51 return {
52 content: [
53 {
54 type: 'text',
55 text: 'Error: workspaceRoots parameter is required and must be a non-empty array of directory paths',
56 },
57 ],
58 isError: true,
59 }
60 }
61
62 try {
63 // Get information about serverless projects in all workspace roots
64 let allProjects = []
65
66 // Process each workspace root
67 for (const workspaceRoot of workspaceRoots) {
68 const projectsInfo = await getServerlessProjectsInfo(workspaceRoot)
69 allProjects = [...allProjects, ...projectsInfo.projects]
70 }
71
72 // Remove any duplicate projects (in case of overlapping workspace roots)
73 // Since projects are now objects with paths, we need to deduplicate by path
74 const uniquePaths = new Set()

Callers 1

registerToolsFunction · 0.90

Calls 3

setListProjectsCalledFunction · 0.90
errorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…