Skip to main content
Glama

instances

List all connected OpenCode instances with their current busy or idle status to identify available machines.

Instructions

List all connected opencode instances with their current status (busy/idle). Call this to see what machines are available.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The tool handler for 'instances'. Registers the MCP tool with server.tool(), calls registry.refresh() to get instances, enriches them with busy/idle status and recent session info, then formats and returns the result.
    server.tool(
      'instances',
      'List all connected opencode instances with their current status (busy/idle). Call this to see what machines are available.',
      {},
      async () => {
        try {
          const instances = await registry.refresh()
    
          const enriched = await Promise.all(
            instances
              .filter((inst) => inst.online)
              .map(async (inst) => {
                const { busySessionId } = await getInstanceStatus(inst.url)
                const session = await findMostRecentSession(inst.url)
                const status = busySessionId ? 'busy' : 'idle'
                return {
                  instance: inst,
                  status,
                  recentSession: session?.title,
                }
              }),
          )
    
          return {
            content: [
              { type: 'text', text: formatInstanceList(enriched) },
            ],
          }
        } catch (err) {
          return {
            content: [
              { type: 'text', text: `Error: ${(err as Error).message}` },
            ],
            isError: true,
          }
        }
      },
  • src/index.ts:38-38 (registration)
    Registration call that wires 'instances' tool into the MCP server. registerSimplifiedTools(server, registry) is called from the main entry point.
    registerSimplifiedTools(server, registry)
  • Helper function formatInstanceList that formats the instances list into a user-readable string output.
    function formatInstanceList(
      instances: Array<{
        instance: OpenCodeInstance
        status: string
        recentSession?: string
      }>,
    ): string {
      if (instances.length === 0) {
        return 'No opencode instances are currently connected.\n\nRun `opencode-connected` on a machine to register one.'
      }
    
      const lines: string[] = []
      for (const { instance, status, recentSession } of instances) {
        const session = recentSession ? ` — "${recentSession}"` : ''
        lines.push(
          `**${instance.name}** (${instance.hostname}:${instance.cwd})`,
        )
        lines.push(
          `  ${instance.online ? 'online' : 'offline'} | ${status}${session} | v${instance.version ?? 'unknown'}`,
        )
      }
      return lines.join('\n')
    }
  • Helper function getInstanceStatus that checks the busy/idle status of sessions on an instance via the /session/status endpoint.
    async function getInstanceStatus(
      baseUrl: string,
    ): Promise<{ statuses: Record<string, string>; busySessionId?: string }> {
      try {
        const res = await fetch(`${baseUrl}/session/status`)
        if (!res.ok) return { statuses: {} }
        const data = (await res.json()) as Record<
          string,
          { type: string }
        >
        const statuses: Record<string, string> = {}
        let busySessionId: string | undefined
        for (const [id, info] of Object.entries(data)) {
  • Helper function findMostRecentSession that finds the most recently updated session on an instance via the /session endpoint.
    async function findMostRecentSession(
      baseUrl: string,
    ): Promise<SessionInfo | undefined> {
      try {
        const res = await fetch(`${baseUrl}/session`)
        if (!res.ok) return undefined
        const sessions = (await res.json()) as SessionInfo[]
        if (sessions.length === 0) return undefined
        sessions.sort((a, b) => b.time.updated - a.time.updated)
        return sessions[0]
      } catch {
        return undefined
      }
Behavior5/5

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

No annotations provided, but the description accurately reflects a read-only list operation. It discloses the output (status), and no side effects are expected. Fully transparent.

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?

Two sentences with no wasted words. The purpose is front-loaded, and the call to action is immediate.

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

Completeness4/5

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

Given zero parameters and no output schema, the description covers the essential purpose and return content. It could optionally clarify output format, but the current text is largely sufficient.

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?

No parameters exist, and schema coverage is 100% trivially. The description adds no parameter detail, which is appropriate. Baseline for 0 parameters is 4.

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

Purpose5/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 the resource 'connected opencode instances', and specifies the information returned (current status busy/idle). No confusion with sibling tools (read, send).

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

Usage Guidelines4/5

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

The description advises 'Call this to see what machines are available', providing a clear use case. It does not explicitly exclude alternatives, but siblings are unrelated, so guidance is adequate.

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/klutometis/opencode-mcp'

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