get_hostname
Retrieve the hostname of the machine running the MCP server to identify the system or verify server details using the Local Utilities MCP Server interface.
Instructions
Returns the hostname of the machine running the MCP server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp/hostname.ts:16-27 (handler)The anonymous async handler function that executes the get_hostname tool logic. It calls the getHostname helper and formats the result as MCP text content.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:12-29 (registration)Registers the get_hostname tool on the MCP server, including the name, description, and inline handler function.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 (helper)Helper function that retrieves and returns the system hostname using Node.js os.hostname().export function getHostname(): string { return os.hostname(); }
- src/index.ts:19-19 (registration)Top-level registration call that adds the hostname tool to the main MCP server instance.registerHostnameTool(server);