Skip to main content
Glama
piekstra

New Relic MCP Server

by piekstra

manage_credentials

Securely manage New Relic API credentials in keychain - check status, store new keys, or remove all credentials for API access.

Instructions

Manage New Relic credentials securely in keychain. Actions: - 'status': Show current credential status - 'store': Store new credentials (requires api_key parameter) - 'delete': Remove all credentials from keychain

Input Schema

NameRequiredDescriptionDefault
actionYes
api_keyNo
account_idNo

Input Schema (JSON Schema)

{ "properties": { "account_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Account Id" }, "action": { "title": "Action", "type": "string" }, "api_key": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Api Key" } }, "required": [ "action" ], "type": "object" }

Implementation Reference

  • The core handler function for the 'manage_credentials' tool. Decorated with @mcp.tool() for automatic registration in FastMCP. Handles three actions: status (lists credentials), store (saves API key and optional account ID), delete (removes credentials). Uses SecureCredentials helpers for secure storage/retrieval.
    @mcp.tool() async def manage_credentials( action: str, api_key: Optional[str] = None, account_id: Optional[str] = None ) -> str: """ Manage New Relic credentials securely in keychain. Actions: - 'status': Show current credential status - 'store': Store new credentials (requires api_key parameter) - 'delete': Remove all credentials from keychain """ try: if action == "status": status = SecureCredentials.list_stored_credentials() return json.dumps( {"status": status, "message": "Current credential status"}, indent=2 ) elif action == "store": if not api_key: return json.dumps( {"error": "api_key parameter is required for store action"}, indent=2, ) if not api_key.startswith("NRAK-"): return json.dumps( { "error": "Invalid API key format. " "New Relic API keys start with 'NRAK-'" }, indent=2, ) SecureCredentials.store_api_key(api_key) if account_id: SecureCredentials.store_account_id(account_id) return json.dumps( { "success": True, "message": "Credentials stored securely in keychain", }, indent=2, ) elif action == "delete": SecureCredentials.delete_credentials() return json.dumps( { "success": True, "message": "All credentials removed from keychain", }, indent=2, ) else: return json.dumps( { "error": f"Unknown action '{action}'. " "Valid actions: status, store, delete" }, indent=2, ) except Exception as e: return json.dumps({"error": str(e)}, indent=2)
  • Helper method used by manage_credentials 'status' action to check and report presence of stored credentials without revealing values.
    def list_stored_credentials() -> dict: """List what credentials are stored (True/False, not actual values)""" credentials = {} try: api_key = keyring.get_password(SERVICE_NAME, "api_key") credentials["api_key_in_keychain"] = api_key is not None except Exception: credentials["api_key_in_keychain"] = False try: account_id = keyring.get_password(SERVICE_NAME, "account_id") credentials["account_id_in_keychain"] = account_id is not None except Exception: credentials["account_id_in_keychain"] = False credentials["api_key_in_env"] = bool( os.getenv("NEWRELIC_API_KEY") or os.getenv("NEW_RELIC_API_KEY") ) credentials["account_id_in_env"] = bool(os.getenv("NEWRELIC_ACCOUNT_ID")) credentials["region"] = os.getenv("NEWRELIC_REGION", "US") return credentials
  • Helper method called by manage_credentials 'store' action to securely store the API key using keyring.
    @staticmethod def store_api_key(api_key: str) -> None: """Store New Relic API key securely in keychain""" try: keyring.set_password(SERVICE_NAME, "api_key", api_key) logger.info("API key stored securely in keychain") except Exception as e: logger.error(f"Failed to store API key in keychain: {e}") raise
  • Helper method called by manage_credentials 'store' action (when account_id provided) to securely store the account ID.
    @staticmethod def store_account_id(account_id: str) -> None: """Store New Relic account ID securely in keychain""" try: keyring.set_password(SERVICE_NAME, "account_id", account_id) logger.info("Account ID stored securely in keychain") except Exception as e: logger.error(f"Failed to store account ID in keychain: {e}") raise
  • Helper method called by manage_credentials 'delete' action to remove stored credentials from keychain.
    def delete_credentials() -> None: """Remove all stored credentials from keychain""" try: keyring.delete_password(SERVICE_NAME, "api_key") logger.info("API key removed from keychain") except keyring.errors.PasswordDeleteError: logger.info("No API key found in keychain to delete") except Exception as e: logger.error(f"Failed to delete API key from keychain: {e}") try: keyring.delete_password(SERVICE_NAME, "account_id") logger.info("Account ID removed from keychain") except keyring.errors.PasswordDeleteError: logger.info("No account ID found in keychain to delete") except Exception as e: logger.error(f"Failed to delete account ID from keychain: {e}")

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/piekstra/newrelic-mcp-server'

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