get_hostname
Retrieves the hostname of the computer running the server. Useful for identifying the local machine in automation tasks.
Instructions
Returns the hostname of the machine running the MCP server.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp/hostname.ts:12-29 (handler)Registers the 'get_hostname' tool with the MCP server. The tool handler calls getHostname() and returns the system hostname as text content.
export function registerHostnameTool(server: McpServer): void { server.tool( "get_hostname", "Returns the hostname of the machine running the MCP server.", async () => { // Note: Error handling is simplified; the MCP SDK handles basic errors. // More complex tools might still need try/catch. const hostname = getHostname(); return { content: [{ type: "text", // Return plain text for simple values text: hostname }] }; } ); } - src/mcp/hostname.ts:8-10 (handler)The core helper function that calls os.hostname() to retrieve the system hostname.
export function getHostname(): string { return os.hostname(); } - src/index.ts:19-19 (registration)Registration call: invokes registerHostnameTool(server) to register the tool on the MCP server.
registerHostnameTool(server); - src/protocols/commands.ts:5-5 (schema)Enum definition for GET_HOSTNAME command type used in protocols.
GET_HOSTNAME = "getHostname", // Add new command here - src/index.ts:4-4 (registration)Import of the registerHostnameTool function from the hostname module.
import { registerHostnameTool } from "./mcp/hostname.js";