Skip to main content
Glama

listScreens

Retrieve available display screens for capturing visual content during web development tasks.

Instructions

List available screens/displays that can be captured

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that executes the listScreens tool logic. It fetches available screens using getAvailableScreens, formats them into a text list, and returns as MCP content. Includes error handling.
    async () => {
    	try {
    		console.log("Listing available screens...")
    		const screens = await getAvailableScreens()
    
    		// Format the output for display
    		const screenList = screens
    			.map((screen) => `Screen ${screen.id}: ${screen.description}`)
    			.join("\n")
    
    		return {
    			content: [
    				{
    					type: "text",
    					text: `Available screens:\n${screenList}`
    				}
    			]
    		}
    	} catch (error: unknown) {
    		console.error("Error listing screens:", error)
    		const errorMessage =
    			error instanceof Error ? error.message : String(error)
    		return {
    			content: [
    				{
    					type: "text",
    					text: `Error listing screens: ${errorMessage}`
    				}
    			]
    		}
    	}
    }
  • src/index.ts:15-51 (registration)
    Registers the listScreens tool with the MCP server, including name, description, empty schema, and inline handler function.
    server.tool(
    	"listScreens",
    	"List available screens/displays that can be captured",
    	{},
    	async () => {
    		try {
    			console.log("Listing available screens...")
    			const screens = await getAvailableScreens()
    
    			// Format the output for display
    			const screenList = screens
    				.map((screen) => `Screen ${screen.id}: ${screen.description}`)
    				.join("\n")
    
    			return {
    				content: [
    					{
    						type: "text",
    						text: `Available screens:\n${screenList}`
    					}
    				]
    			}
    		} catch (error: unknown) {
    			console.error("Error listing screens:", error)
    			const errorMessage =
    				error instanceof Error ? error.message : String(error)
    			return {
    				content: [
    					{
    						type: "text",
    						text: `Error listing screens: ${errorMessage}`
    					}
    				]
    			}
    		}
    	}
    )
  • Input schema for listScreens tool: empty object indicating no parameters required.
    {},
  • Core helper function that implements screen listing logic using platform-specific system commands (detailed parsing for macOS via system_profiler), with platform fallbacks and robust error handling.
    // Add a helper function to list available screens (macOS only)
    export async function getAvailableScreens(): Promise<
    	{ id: number; description: string }[]
    > {
    	try {
    		const platform = os.platform()
    
    		if (platform === "darwin") {
    			// Use system_profiler to get display information
    			const { stdout } = await execAsync(
    				"system_profiler SPDisplaysDataType"
    			)
    
    			// Parse the system_profiler output to properly identify displays
    			// First, separate the output into sections for each display
    			const displayData = stdout
    				.split("Graphics/Displays:")
    				.filter((section) => section.trim().length > 0)
    
    			if (displayData.length === 0) {
    				// Fallback if no displays were found
    				return [{ id: 1, description: "Main Display" }]
    			}
    
    			// Initial display list with Main Display
    			const displays: { id: number; description: string }[] = []
    
    			// Scan through raw output and extract display sections
    			const displaySections = stdout
    				.split(/^\s*\w+:/m)
    				.filter(
    					(section) =>
    						section.includes("Display Type") ||
    						section.includes("Resolution") ||
    						section.includes("Type:")
    				)
    
    			// Check if we're dealing with a more specific format
    			if (displaySections.length === 0) {
    				// Fallback to main display only
    				return [{ id: 1, description: "Main Display" }]
    			}
    
    			// Process each section to extract display info
    			for (let i = 0; i < displaySections.length; i++) {
    				const section = displaySections[i]
    				const lines = section.split("\n").map((line) => line.trim())
    
    				let displayName = ""
    				let resolution = ""
    				let displayType = ""
    
    				// Extract relevant display information
    				for (const line of lines) {
    					if (
    						line.includes("Display Type:") ||
    						line.includes("Type:")
    					) {
    						displayType = line.split(":")[1]?.trim() || "Unknown"
    					} else if (line.includes("Resolution:")) {
    						resolution = line.split(":")[1]?.trim() || ""
    					} else if (line.includes("Name:")) {
    						displayName = line.split(":")[1]?.trim() || ""
    					}
    				}
    
    				// Combine information for a descriptive name
    				let description = displayName || displayType || "Display"
    				if (resolution) {
    					description += ` (${resolution})`
    				}
    
    				// Add to display list
    				displays.push({
    					id: i + 1, // Display IDs in screencapture start at 1
    					description
    				})
    			}
    
    			// If we found displays but none matched our parsing, add a fallback
    			if (displays.length === 0) {
    				displays.push({ id: 1, description: "Main Display" })
    			}
    
    			// Use an alternative method: Check output from "system_profiler SPDisplaysDataType"
    			if (displays.length <= 1) {
    				// Try running a different command to get screen info
    				try {
    					const { stdout: screenInfo } = await execAsync(
    						"system_profiler SPDisplaysDataType | grep Resolution"
    					)
    					const resolutions = screenInfo
    						.split("\n")
    						.filter((line) => line.includes("Resolution"))
    
    					// If we have multiple resolutions, we likely have multiple screens
    					if (resolutions.length > 1) {
    						displays.length = 0 // Clear existing displays
    
    						// Add each detected display
    						for (let i = 0; i < resolutions.length; i++) {
    							const resolution =
    								resolutions[i].split(":")[1]?.trim() || ""
    							displays.push({
    								id: i + 1,
    								description:
    									i === 0
    										? `Main Display (${resolution})`
    										: `External Display ${i} (${resolution})`
    							})
    						}
    					}
    				} catch (err) {
    					console.error("Error getting alternative screen info:", err)
    				}
    			}
    
    			return displays
    		}
    
    		if (platform === "win32") {
    			// Windows implementation (placeholder)
    			return [
    				{
    					id: 0,
    					description:
    						"Primary Screen (multi-screen selection not supported yet)"
    				}
    			]
    		}
    
    		if (platform === "linux") {
    			// Linux implementation (placeholder)
    			return [
    				{
    					id: 0,
    					description:
    						"Primary Screen (multi-screen selection not supported yet)"
    				}
    			]
    		}
    
    		throw new Error(`Unsupported platform: ${platform}`)
    	} catch (error) {
    		console.error("Error listing screens:", error)
    		return [{ id: 1, description: "Main Display" }]
    	}
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions the purpose but fails to disclose behavioral traits such as whether the list is real-time or cached, if it requires permissions, what format the output is in, or any rate limits. This leaves the agent with insufficient information to predict tool behavior accurately.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words, front-loading the core action and purpose. Every element ('List available screens/displays that can be captured') directly contributes to understanding, making it optimally concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the return values are (e.g., list format, screen identifiers), behavioral aspects like permissions or freshness, or error handling. For a tool with zero structured metadata, this leaves significant gaps in agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0 parameters and 100% schema description coverage, the baseline is high. The description adds value by clarifying that the screens are 'available' and for 'capture,' which provides context beyond the empty schema. However, it doesn't detail output semantics, slightly limiting its utility.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('List') and resource ('available screens/displays'), specifying that these are for capture purposes. It distinguishes from the sibling 'takeScreenshot' by focusing on enumeration rather than action. However, it doesn't explicitly differentiate scope or limitations beyond the capture context, keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage is implied by mentioning 'that can be captured,' suggesting this tool should be used before 'takeScreenshot' to identify targets. No explicit guidance on when not to use it or alternatives is provided, and it lacks prerequisites or error conditions, leaving gaps in decision-making context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zueai/webdev-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server