Skip to main content
Glama

register-service

Register a service with Consul by specifying its name, ID, port, address, and optional tags. Simplifies service discovery and management within the Consul MCP Server framework.

Instructions

Register a service with Consul

Input Schema

NameRequiredDescriptionDefault
addressNoAddress the service is running on
idNoID of the service (defaults to name if not provided)
nameNoName of the service to register
portNoPort the service is running on
tagsNoTags to associate with the service

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "address": { "default": "", "description": "Address the service is running on", "type": "string" }, "id": { "default": "", "description": "ID of the service (defaults to name if not provided)", "type": "string" }, "name": { "default": "", "description": "Name of the service to register", "type": "string" }, "port": { "description": "Port the service is running on", "type": "number" }, "tags": { "description": "Tags to associate with the service", "items": { "type": "string" }, "type": "array" } }, "type": "object" }

Implementation Reference

  • The handler function for the 'register-service' tool. It constructs a service definition from inputs and calls consul.agent.service.register to register the service with Consul.
    async ({ name, id, port, address, tags }) => { try { const serviceId = id || name; const serviceDefinition: any = { name, id: serviceId, }; if (port !== undefined) serviceDefinition.port = port; if (address !== undefined) serviceDefinition.address = address; if (tags !== undefined) serviceDefinition.tags = tags; await consul.agent.service.register(serviceDefinition); //if (!success) { // return { content: [{ type: "text", text: `Failed to register service: ${name}` }] }; //} return { content: [{ type: "text", text: `Successfully registered service: ${name} with ID: ${serviceId}` }] }; } catch (error) { console.error("Error registering service:", error); return { content: [{ type: "text", text: `Error registering service: ${name}` }] }; } }
  • Zod schema defining the input parameters for the 'register-service' tool.
    { name: z.string().default("").describe("Name of the service to register"), id: z.string().default("").optional().describe("ID of the service (defaults to name if not provided)"), port: z.number().optional().describe("Port the service is running on"), address: z.string().default("").optional().describe("Address the service is running on"), tags: z.array(z.string()).optional().describe("Tags to associate with the service"), },
  • Registration of the 'register-service' tool on the MCP server using server.tool(), including description, input schema, and handler function.
    server.tool( "register-service", "Register a service with Consul", { name: z.string().default("").describe("Name of the service to register"), id: z.string().default("").optional().describe("ID of the service (defaults to name if not provided)"), port: z.number().optional().describe("Port the service is running on"), address: z.string().default("").optional().describe("Address the service is running on"), tags: z.array(z.string()).optional().describe("Tags to associate with the service"), }, async ({ name, id, port, address, tags }) => { try { const serviceId = id || name; const serviceDefinition: any = { name, id: serviceId, }; if (port !== undefined) serviceDefinition.port = port; if (address !== undefined) serviceDefinition.address = address; if (tags !== undefined) serviceDefinition.tags = tags; await consul.agent.service.register(serviceDefinition); //if (!success) { // return { content: [{ type: "text", text: `Failed to register service: ${name}` }] }; //} return { content: [{ type: "text", text: `Successfully registered service: ${name} with ID: ${serviceId}` }] }; } catch (error) { console.error("Error registering service:", error); return { content: [{ type: "text", text: `Error registering service: ${name}` }] }; } } );

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/kocierik/consul-mcp-server'

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