Skip to main content
Glama
widjis
by widjis

ssh_connect_with_credential

Connect to SSH servers using saved credentials for remote access and management. This tool establishes secure connections with stored authentication details to execute commands and transfer files.

Instructions

Connect to SSH server using saved credentials

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
credentialIdYesStored credential ID to use
connectionIdYesUnique identifier for this connection

Implementation Reference

  • Handler function that executes the ssh_connect_with_credential tool. Retrieves stored credential by ID, establishes SSH connection using node-ssh library, manages connection pool and contexts, updates credential usage timestamp, handles errors.
    private async handleConnectWithCredential(args: unknown) {
      const params = ConnectWithCredentialSchema.parse(args);
      
      if (connectionPool.has(params.connectionId)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Connection ID '${params.connectionId}' already exists`
        );
      }
    
      const credential = credentialStore.get(params.credentialId);
      if (!credential) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Credential ID '${params.credentialId}' not found`
        );
      }
    
      const ssh = new NodeSSH();
      
      try {
        const connectConfig: any = {
          host: credential.host,
          port: credential.port,
          username: credential.username,
        };
    
        if (credential.privateKeyPath) {
          const privateKey = await fs.readFile(credential.privateKeyPath, 'utf8');
          connectConfig.privateKey = privateKey;
          if (credential.passphrase) {
            connectConfig.passphrase = credential.passphrase;
          }
        } else if (credential.password) {
          connectConfig.password = credential.password;
        } else {
          throw new McpError(
            ErrorCode.InvalidParams,
            'Credential has neither password nor private key'
          );
        }
    
        await ssh.connect(connectConfig);
        connectionPool.set(params.connectionId, ssh);
    
        // Initialize connection context
        connectionContexts.set(params.connectionId, {
          ssh,
          currentWorkingDirectory: undefined,
          defaultWorkingDirectory: undefined
        });
    
        // Update last used timestamp
        credential.lastUsed = new Date().toISOString();
        credentialStore.set(params.credentialId, credential);
    
        return {
          content: [
            {
              type: 'text',
              text: `Successfully connected to ${credential.host}:${credential.port} as ${credential.username} using saved credential '${params.credentialId}' (Connection ID: ${params.connectionId})`,
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `SSH connection failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
  • Zod schema defining input parameters for the ssh_connect_with_credential tool: credentialId (string) and connectionId (string). Used for validation in the handler.
    const ConnectWithCredentialSchema = z.object({
      credentialId: z.string().describe('Stored credential ID to use'),
      connectionId: z.string().describe('Unique identifier for this connection')
    });
  • src/index.ts:408-419 (registration)
    Tool registration in the ListTools response, defining name, description, and inputSchema for ssh_connect_with_credential.
    {
      name: 'ssh_connect_with_credential',
      description: 'Connect to SSH server using saved credentials',
      inputSchema: {
        type: 'object',
        properties: {
          credentialId: { type: 'string', description: 'Stored credential ID to use' },
          connectionId: { type: 'string', description: 'Unique identifier for this connection' }
        },
        required: ['credentialId', 'connectionId']
      },
    },
  • src/index.ts:511-512 (registration)
    Dispatch registration in the CallToolRequest handler switch statement, mapping the tool name to its handler function.
    case 'ssh_connect_with_credential':
      return await this.handleConnectWithCredential(args);
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool establishes an SSH connection but lacks critical details: whether this initiates an interactive session, requires specific permissions, has side effects (e.g., opening network ports), or handles errors. For a connection tool with zero annotation coverage, this is a significant gap in transparency.

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 that front-loads the core purpose without unnecessary words. Every part ('Connect to SSH server using saved credentials') earns its place by specifying the action and method, making it appropriately 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 complexity of SSH operations (involving network connections, authentication, and potential side effects), no annotations, and no output schema, the description is incomplete. It doesn't explain what happens after connection (e.g., returns a session handle, initiates a shell), error conditions, or dependencies on other tools like 'ssh_save_credential'. This leaves the agent with insufficient context for safe and effective use.

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

Parameters3/5

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

Schema description coverage is 100%, with both parameters ('credentialId' and 'connectionId') clearly documented in the schema. The description adds no additional parameter semantics beyond implying the use of saved credentials, which aligns with the schema. This meets the baseline score of 3 when the schema does the heavy lifting.

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 action ('Connect to SSH server') and the method ('using saved credentials'), which provides a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'ssh_connect' (which likely uses different authentication methods) or 'ssh_start_interactive_shell' (which might be for different connection types).

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing saved credentials via 'ssh_save_credential'), exclusions, or comparisons to siblings like 'ssh_connect' (which might use direct credentials). This leaves the agent with minimal context for tool selection.

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/widjis/mcp-ssh'

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