Skip to main content
Glama

Build Territories from Assignments

direct_build

Builds territories from known part-to-territory assignments (a ZIP-to-territory sheet or file, including a three-level region/district/territory hierarchy via territory_path) and adds them to the Territory Solution as a new alignment (TAL). Assignments come only as an assignments_handle (aup_...) from request_assignment_upload (the file, csv_text, or assignment rows). Sheets with Postal Code plus Territory/Region/Division columns are mapped automatically. Duplicate part_ids follow duplicate_part_policy (default keep_first). Returns a task; the result carries tal_id and ts_handle and paints the open map. Location points load with ingest_accounts; balanced partitions come from auto_build; grouping by a column is account_build.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "part_layer": "<part_layer>",
      "tal_label": "<tal_label>"
    },
    "name": "direct_build"
  }
}

Input Schema

NameRequiredDescriptionDefault
tal_idNoOptional caller-supplied TAL identifier. When omitted, the server derives a stable ID from tal_label. Supplied IDs must not collide with an existing TAL in the input TS.
tal_labelYes
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.
part_layerYes
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
map_session_idNoOpen map session (msess_...) from get_map_visualization. Its Territory Solution is the input; omit ts_handle when set.
expected_revisionNo
assignments_handleNoRequired. upload_handle (aup_...) from request_assignment_upload. Single-use: the build claims it.
missing_part_policyNoControls assigned part IDs that are absent from the selected polygon part layer. fail returns UNKNOWN_PART_ID. drop_with_warning omits them, lists them in invalid_parts, and proceeds with geometry-covered assignments.fail
duplicate_part_policyNoWhen the same part_id maps to different territory_path values, keep_first (default) keeps the first row and skips the rest with a warning; keep_last keeps the last row; fail aborts with CLARIFICATION_REQUIRED.keep_first

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. Changed12 schema fields changed
    • removedInput schema / properties / assignments
      Removed value: -{
      -  "anyOf": [
      -    {
      -      "items": {
      -        "additionalProperties": true,
      -        "type": "object"
      -      },
      -      "type": "array"
      -    },
      -    {
      -      "type": "null"
      -    }
      -  ],
      -  "default": null,
      -  "title": "Assignments"
      -}
    • addedInput schema / properties / assignments_handle / description
      Added value: +"Required. upload_handle (aup_...) from request_assignment_upload. Single-use: the build claims it."
    • addedInput schema / properties / duplicate_part_policy / description
      Added value: +"When the same part_id maps to different territory_path values, keep_first (default) keeps the first row and skips the rest with a warning; keep_last keeps the last row; fail aborts with CLARIFICATION_REQUIRED."
    • 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 / missing_part_policy / description
      Added value: +"Controls assigned part IDs that are absent from the selected polygon part layer. fail returns UNKNOWN_PART_ID. drop_with_warning omits them, lists them in invalid_parts, and proceeds with geometry-covered assignments."
    • addedInput schema / properties / tal_id / description
      Added value: +"Optional caller-supplied TAL identifier. When omitted, the server derives a stable ID from tal_label. Supplied IDs must not collide with an existing TAL in the input TS."
    • 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."
    • 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": {
      +      "assignment_summary": {
      +        "type": "object"
      +      },
      +      "do_this_next": {
      +        "type": "object"
      +      },
      +      "expires_at": {
      +        "type": "string"
      +      },
      +      "geometry_summary": {
      +        "type": "object"
      +      },
      +      "hierarchy_summary": {
      +        "type": "object"
      +      },
      +      "invalid_parts": {
      +        "items": {
      +          "type": "string"
      +        },
      +        "type": "array"
      +      },
      +      "job_id": {
      +        "type": "string"
      +      },
      +      "next_action": {
      +        "type": "string"
      +      },
      +      "repair_summary": {
      +        "type": "object"
      +      },
      +      "sleep_ms": {
      +        "type": "integer"
      +      },
      +      "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: -"direct_buildDictOutput"
  2. Changed1 schema field changed
    • removedInput schema / properties / guidance_handle
      Removed value: -{
      -  "anyOf": [
      -    {
      -      "type": "string"
      -    },
      -    {
      -      "type": "null"
      -    }
      -  ],
      -  "default": null,
      -  "title": "Guidance Handle"
      -}
  3. 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"
      +]
  4. First observed

TDQS

A4.5/5.0
Behavior4/5

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

Goes well beyond the annotations by disclosing that the handle is single-use (the build claims it), that a task is returned asynchronously, that the result carries tal_id and ts_handle, and that the open map is painted as a side effect. It does not explain concurrency behavior around expected_revision or what happens on TAL id collision, which are the remaining material traits for a non-idempotent mutation.

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 input constraint, then routes to siblings, then states the return shape. It is a single dense block, but nearly every clause carries information an agent needs; the sheet-mapping sentence is the only one that could be trimmed.

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

Completeness4/5

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

For a non-idempotent, async mutation with 10 parameters and an output schema, the description covers input provenance, hierarchy shape, return contract (task, then tal_id/ts_handle), and side effects on the map. Preconditions such as requiring a valid ts_handle or map_session_id are left to the schema, which is acceptable given an output schema exists.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Adds real meaning beyond the 70%-covered schema: automatic mapping of sheets with Postal Code plus Territory/Region/Division columns, the three-level hierarchy via territory_path, and the duplicate_part_policy default. It leaves tal_id, expected_revision, missing_part_policy, and part_layer to the schema, which documents most of them adequately.

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 ('Builds territories from known part-to-territory assignments') plus the outcome ('adds them to the Territory Solution as a new alignment (TAL)'). This clearly separates it from seed_build, auto_build, and account_build, which derive territories from scratch or from points.

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

Usage Guidelines5/5

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

Explicitly states the required input path ('Assignments come only as an assignments_handle (aup_...) from request_assignment_upload') and names the three alternative builders with their selecting conditions: ingest_accounts for location points, auto_build for balanced partitions, account_build for column grouping. When-to-use and when-not-to-use are both covered.

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