Skip to main content
Glama

Merge Territories

territory_merge
Destructive

Merges a pair of adjacent territories (N to N-1 territories). By default, territory_id_b is folded into territory_id_a (or renamed to new_territory_label) and the rest of the alignment rebalances with minimal disruption, e.g. when a rep leaves and neighbors absorb the territory. Set preserve_other_territories=true for an exact two-territory union that combines only territory_id_a and territory_id_b (optionally named new_territory_label) and leaves every other territory unchanged with no rebalance. Non-adjacent ids return NON_ADJACENT_TERRITORIES. Needs source_tal_id and the Territory Solution from map_session_id or ts_handle; workload rebalance needs dwell_time (CLARIFICATION_REQUIRED otherwise). Writes a new derived alignment. Returns a task.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "territory_merge"
  }
}

Input Schema

NameRequiredDescriptionDefault
objectiveNo
ts_handleNoTerritory Solution reference (tsh_...) from a build, ingest_accounts, import_geojson, import_designer_project, or get_map_visualization; Territory Solutions are not accepted inline.
dwell_timeNo
part_layerNoPart layer (e.g. us_zips). Required only when not inferable from the source TAL.
point_layerNoOptional point layer used to compute per-part workload/metric measures. When omitted, a uniform geography-only weighting is used.
new_tal_labelNoLabel for the derived TAL. Defaults to '<source label> (<operation>)'.
repair_policyNoTopology repair for dissolved territories. default fills interior holes in the dissolved geometry (no part is added or reassigned; repair_summary.changed_part_ids lists the territories' own parts). report_only detects holes and changes nothing (warning REPAIR_AVAILABLE). strict fails with REPAIR_REQUIRED when a hole is found.default
source_tal_idNoSource TAL. Optional for form-capable clients that can answer via elicitation.
map_session_idNoOpen map session (msess_...) from get_map_visualization. Its Territory Solution is the input; omit ts_handle when set.
territory_id_aNoFirst territory (id or label). The merged territory keeps this identity unless new_territory_label is supplied.
territory_id_bNoSecond territory (id or label). Must be adjacent to territory_id_a.
balance_toleranceNoAccepted for compatibility. The power-diagram rebalance converges on its own internal tolerance, so this value no longer gates per-part moves.
disruption_weightNoIncumbency stickiness for the warm-started power-diagram rebalance. 0 is a pure power re-solve (max balance, more churn); higher values keep more of the source alignment by requiring a neighbor territory to inflate further before it can claim a border part.
new_territory_labelNoOptional display label for the merged territory (defaults to territory_id_a's label).
visit_frequency_fieldNoNumeric visits-per-cycle column on the point layer. When omitted, inherits from source TAL build_provenance or point-layer metadata.
preserve_other_territoriesNoWhen true, performs an exact union of territory_id_a and territory_id_b without rebalancing any other territory in the alignment.

Output Schema

NameRequiredDescriptionDefault
okYes
errorNoPresent when ok is false.
resultNoPresent when ok is true. A submission returns the task reference (task_id, next_action, sleep_ms); the completed task result carries the remaining fields.
warningsNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedInput schema / properties / objective / anyOf
      Previous value: -[
      -  {
      -    "additionalProperties": true,
      -    "description": "Balance objective: {metric: '<column>|__account_count__', workload_bias: 0..100, metric_bias: 0..100}. Biases sum to 100. For pure metric balance, pass {metric: '<column>', workload_bias: 0, metric_bias: 100} (or {metric: '<column>'} on restructure tools). When omitted on restructure tools, inherits the source TAL build_provenance objective or seed_build target.",
      -    "properties": {
      -      "metric": {
      -        "description": "Point metric column name to balance (e.g. 'Revenue', 'weekly_volume'), or '__account_count__' for location-count balance.",
      -        "type": "string"
      -      },
      -      "metric_bias": {
      -        "description": "Weight (0..100) on the metric or location-count dimension.",
      -        "maximum": 100,
      -        "minimum": 0,
      -        "type": "integer"
      -      },
      -      "workload_bias": {
      -        "description": "Weight (0..100) on workload (drive time + dwell).",
      -        "maximum": 100,
      -        "minimum": 0,
      -        "type": "integer"
      -      }
      -    },
      -    "type": "object"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]New value: +[
      +  {
      +    "additionalProperties": true,
      +    "description": "Balance objective: workload_bias + metric_bias + count_bias = 100, weighting workload (drive + dwell), one metric column, and account count. Workload: {workload_bias: 100}. Metric: {metric: '<column>', workload_bias: 0, metric_bias: 100}. Count: {workload_bias: 0, count_bias: 100}. Three-way: {metric: 'Score', workload_bias: 40, metric_bias: 40, count_bias: 20}. Only one metric column balances; combine several into one score column at ingest. Omitted on restructure tools: inherits the source TAL build_provenance objective.",
      +    "properties": {
      +      "count_bias": {
      +        "description": "Weight (0..100) on account count (locations per territory). Default 0.",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      },
      +      "metric": {
      +        "description": "Point metric column name to balance (e.g. 'Revenue', 'Score'). Required when metric_bias > 0. Account count is count_bias, not a column.",
      +        "type": "string"
      +      },
      +      "metric_bias": {
      +        "description": "Weight (0..100) on the metric column.",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      },
      +      "workload_bias": {
      +        "description": "Weight (0..100) on workload (drive time + dwell).",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      }
      +    },
      +    "type": "object"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
  2. Changed3 schema fields changed
    • addedInput schema / properties / new_territory_label
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Optional display label for the merged territory (defaults to territory_id_a's label).",
      +  "title": "New Territory Label"
      +}
    • addedInput schema / properties / preserve_other_territories
      Added value: +{
      +  "default": false,
      +  "description": "When true, performs an exact union of territory_id_a and territory_id_b without rebalancing any other territory in the alignment.",
      +  "title": "Preserve Other Territories",
      +  "type": "boolean"
      +}
    • changedInput schema / properties / territory_id_a / description
      Previous value: -"First territory (id or label). The merged territory keeps this identity."New value: +"First territory (id or label). The merged territory keeps this identity unless new_territory_label is supplied."
  3. Changed16 schema fields changed
    • addedInput schema / properties / balance_tolerance / description
      Added value: +"Accepted for compatibility. The power-diagram rebalance converges on its own internal tolerance, so this value no longer gates per-part moves."
    • addedInput schema / properties / disruption_weight / description
      Added value: +"Incumbency stickiness for the warm-started power-diagram rebalance. 0 is a pure power re-solve (max balance, more churn); higher values keep more of the source alignment by requiring a neighbor territory to inflate further before it can claim a border part."
    • addedInput schema / properties / map_session_id / description
      Added value: +"Open map session (msess_...) from get_map_visualization. Its Territory Solution is the input; omit ts_handle when set."
    • addedInput schema / properties / new_tal_label / description
      Added value: +"Label for the derived TAL. Defaults to '<source label> (<operation>)'."
    • addedInput schema / properties / part_layer / description
      Added value: +"Part layer (e.g. us_zips). Required only when not inferable from the source TAL."
    • addedInput schema / properties / point_layer / description
      Added value: +"Optional point layer used to compute per-part workload/metric measures. When omitted, a uniform geography-only weighting is used."
    • addedInput schema / properties / source_tal_id / description
      Added value: +"Source TAL. Optional for form-capable clients that can answer via elicitation."
    • addedInput schema / properties / territory_id_a / description
      Added value: +"First territory (id or label). The merged territory keeps this identity."
    • addedInput schema / properties / territory_id_b / description
      Added value: +"Second territory (id or label). Must be adjacent to territory_id_a."
    • removedInput schema / properties / ts
      Removed value: -{
      -  "anyOf": [
      -    {
      -      "additionalProperties": true,
      -      "type": "object"
      -    },
      -    {
      -      "type": "null"
      -    }
      -  ],
      -  "default": null,
      -  "title": "Ts"
      -}
    • addedInput schema / properties / ts_handle / description
      Added value: +"Territory Solution reference (tsh_...) from a build, ingest_accounts, import_geojson, import_designer_project, or get_map_visualization; Territory Solutions are not accepted inline."
    • addedInput schema / properties / visit_frequency_field / description
      Added value: +"Numeric visits-per-cycle column on the point layer. When omitted, inherits from source TAL build_provenance or point-layer metadata."
    • removedOutput schema / additionalProperties
      Removed value: -true
    • addedOutput schema / properties
      Added value: +{
      +  "error": {
      +    "description": "Present when ok is false.",
      +    "properties": {
      +      "ask_user": {
      +        "items": {
      +          "type": "string"
      +        },
      +        "type": "array"
      +      },
      +      "code": {
      +        "type": "string"
      +      },
      +      "details": {
      +        "type": "object"
      +      },
      +      "do_this_next": {
      +        "type": "object"
      +      },
      +      "message": {
      +        "type": "string"
      +      }
      +    },
      +    "type": "object"
      +  },
      +  "ok": {
      +    "type": "boolean"
      +  },
      +  "result": {
      +    "description": "Present when ok is true. A submission returns the task reference (task_id, next_action, sleep_ms); the completed task result carries the remaining fields.",
      +    "properties": {
      +      "balance_summary": {
      +        "type": "object"
      +      },
      +      "disruption_summary": {
      +        "type": "object"
      +      },
      +      "do_this_next": {
      +        "type": "object"
      +      },
      +      "expires_at": {
      +        "type": "string"
      +      },
      +      "job_id": {
      +        "type": "string"
      +      },
      +      "next_action": {
      +        "type": "string"
      +      },
      +      "operation": {
      +        "type": "string"
      +      },
      +      "repair_summary": {
      +        "type": "object"
      +      },
      +      "sleep_ms": {
      +        "type": "integer"
      +      },
      +      "solver_diagnostics": {
      +        "type": "object"
      +      },
      +      "source_tal_id": {
      +        "type": "string"
      +      },
      +      "status": {
      +        "type": "string"
      +      },
      +      "tal_id": {
      +        "type": "string"
      +      },
      +      "task_id": {
      +        "type": "string"
      +      },
      +      "terminal": {
      +        "type": "boolean"
      +      },
      +      "territory_count": {
      +        "type": "integer"
      +      },
      +      "ts_handle": {
      +        "type": "string"
      +      },
      +      "ts_identity": {
      +        "type": "object"
      +      },
      +      "ts_omitted": {
      +        "type": "object"
      +      }
      +    },
      +    "type": "object"
      +  },
      +  "warnings": {
      +    "items": {
      +      "properties": {
      +        "code": {
      +          "type": "string"
      +        },
      +        "message": {
      +          "type": "string"
      +        }
      +      },
      +      "type": "object"
      +    },
      +    "type": "array"
      +  }
      +}
    • addedOutput schema / required
      Added value: +[
      +  "ok"
      +]
    • removedOutput schema / title
      Removed value: -"territory_mergeDictOutput"
  4. Changed1 schema field changed
    • changedInput schema / properties / objective / anyOf
      Previous value: -[
      -  {
      -    "additionalProperties": true,
      -    "type": "object"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]New value: +[
      +  {
      +    "additionalProperties": true,
      +    "description": "Balance objective: {metric: '<column>|__account_count__', workload_bias: 0..100, metric_bias: 0..100}. Biases sum to 100. For pure metric balance, pass {metric: '<column>', workload_bias: 0, metric_bias: 100} (or {metric: '<column>'} on restructure tools). When omitted on restructure tools, inherits the source TAL build_provenance objective or seed_build target.",
      +    "properties": {
      +      "metric": {
      +        "description": "Point metric column name to balance (e.g. 'Revenue', 'weekly_volume'), or '__account_count__' for location-count balance.",
      +        "type": "string"
      +      },
      +      "metric_bias": {
      +        "description": "Weight (0..100) on the metric or location-count dimension.",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      },
      +      "workload_bias": {
      +        "description": "Weight (0..100) on workload (drive time + dwell).",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      }
      +    },
      +    "type": "object"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
  5. Changed1 schema field changed
    • changedInput schema / properties / dwell_time / anyOf
      Previous value: -[
      -  {
      -    "additionalProperties": true,
      -    "type": "object"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]New value: +[
      +  {
      +    "additionalProperties": true,
      +    "description": "Onsite (dwell) time per visit: {type: 'scalar', value: <number>, unit: 'minutes'|'hours'} or {type: 'field', field: '<column>', unit: 'minutes'|'hours'}.",
      +    "properties": {
      +      "field": {
      +        "description": "Point column name holding per-account onsite time when type='field'.",
      +        "minLength": 1,
      +        "type": "string"
      +      },
      +      "type": {
      +        "description": "Dwell source: 'scalar' for a fixed per-visit duration or 'field' for an ingested point column.",
      +        "enum": [
      +          "scalar",
      +          "field"
      +        ],
      +        "type": "string"
      +      },
      +      "unit": {
      +        "default": "minutes",
      +        "description": "Time unit for value or field ('minutes' or 'hours').",
      +        "enum": [
      +          "minutes",
      +          "hours"
      +        ],
      +        "type": "string"
      +      },
      +      "value": {
      +        "description": "Confirmed onsite duration per visit when type='scalar'.",
      +        "minimum": 0,
      +        "type": "number"
      +      }
      +    },
      +    "required": [
      +      "type"
      +    ],
      +    "type": "object"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
  6. Changed1 schema field changed
    • removedInput schema / properties / guidance_handle
      Removed value: -{
      -  "anyOf": [
      -    {
      -      "type": "string"
      -    },
      -    {
      -      "type": "null"
      -    }
      -  ],
      -  "default": null,
      -  "title": "Guidance Handle"
      -}
  7. Changed2 schema fields changed
    • addedInput schema / properties / repair_policy / description
      Added value: +"Topology repair for dissolved territories. default fills interior holes in the dissolved geometry (no part is added or reassigned; repair_summary.changed_part_ids lists the territories' own parts). report_only detects holes and changes nothing (warning REPAIR_AVAILABLE). strict fails with REPAIR_REQUIRED when a hole is found."
    • addedInput schema / properties / repair_policy / enum
      Added value: +[
      +  "default",
      +  "strict",
      +  "report_only"
      +]
  8. First observed

TDQS

A4/5.0
Behavior4/5

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

Annotations already declare destructiveHint=true and idempotentHint=false; the description goes beyond them by saying it 'writes a new derived alignment' (source is not mutated in place) and by quantifying the blast radius of each mode — default rebalances surrounding territory borders, preserve_other_territories leaves everything else untouched. It also surfaces preconditions (source_tal_id plus ts_handle or map_session_id, dwell_time for workload) that annotations cannot express.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core action and the N-to-N-1 outcome, then the mode switch, then the error/precondition tail. The middle sentence is long and packs several conditional clauses, but every clause carries real decision value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 16-parameter, destructive, derived-artifact-producing tool, the description covers the merge semantics, adjacency requirement, and input provenance, and an output schema exists to explain the returned task. What it omits is how the returned task is consumed (polling, where the derived alignment is referenced afterward), which matters for a write tool whose result is asynchronous.

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 coverage is 88%, so the schema already documents nearly every parameter including repair_policy, objective, and dwell_time. The description adds genuine meaning only for the identity semantics of territory_id_a vs territory_id_b (b folds into a, or is renamed) and for preserve_other_territories, which the schema also states. Baseline 3 is right given how little the prose must carry.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource with the cardinality effect made explicit: 'Merges a pair of adjacent territories (N to N-1 territories)'. That immediately separates it from the splitting/creation siblings without the agent needing the schema.

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

Usage Guidelines4/5

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

Names the two operating modes and the condition that selects each: the default rebalance for 'when a rep leaves and neighbors absorb the territory', versus preserve_other_territories=true for an exact two-territory union with no knock-on churn. It also lists required inputs and the NON_ADJACENT_TERRITORIES / CLARIFICATION_REQUIRED failure conditions. It stops short of naming a sibling to use instead when the intent is actually a split or a full rebalance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources