goal-mcp) Integration Guidegoal-mcp is a standalone, modular Model Context Protocol (MCP) server written in Python (zero external PyPI dependencies, Python 3.6+ and Docker Python 3.11 compatible) that exposes GOAL Platform REST APIs to AI assistants (Antigravity, Claude Desktop, Cursor, etc.).
territories.draft_paths and never mutate productive territories.paths.create_rebalance_scenario creates a PENDING_APPROVAL scenario with before/after metrics; approve, reject, and confirm-draft are intentionally not exposed to MCP so human approval in GOAL is always enforced.goal-mcp connects to goal-backend using a dedicated Technical User (Service Account) configured with a GOAL Personal Access Token and explicit connection settings.
mcp-tech-user@company.com) and assign it to the target company (companyId).SALES_TEAM: LISTPORTFOLIO: LIST, UPDATEPORTFOLIO_ASSIGNMENT: LIST, INSERTPORTFOLIO_SCHEDULE: LIST, INSERT, UPDATESALES_TEAM_CUSTOMER: LISTTERRITORY: LIST, DRAWING_UPDATEROUTE_REBALANCE_SCENARIO: LIST, DETAILS, INSERT (do not grant APPROVE / REJECT to the technical user if you want strict separation of duties from human supervisors)POST /v1/core/users/generate-api-key (see Authentication API) or from the user's profile API Keys screen. Copy the raw token immediately (it is shown only once).Create /khayyam/home/mgonzalo/apps/goal-mcp/.env from .env.example (or pass the variables via mcp_config.json / docker-compose.yml):
GOAL_API_BASE_URL=https://goal-dev-gm-api.dsroma.info/v1
GOAL_API_TOKEN=<technical-user-bearer-token>
GOAL_COMPANY_UUID=<company-uuid>
GOAL_APP_STAGE=dev
GOAL_APP_UID=goal-mcp
GOAL_API_TIMEOUT=30.0
| Setting | Required | Default | Description |
|---|---|---|---|
GOAL_API_BASE_URL |
Yes | https://goal-dev-gm-api.dsroma.info/v1 |
Base URL of the goal-backend /v1 API. |
GOAL_API_TOKEN |
No* | "" |
Optional default Bearer token (e.g. for stdio). In HTTP mode, each remote user can send their own GOAL Frontend token via Authorization: Bearer <token>. |
GOAL_COMPANY_UUID |
No* | "" |
Default company UUID; resolved to companyId via GET /v1/base/master/companies/{uuid}. |
GOAL_DEFAULT_COMPANY_ID |
No* | "" |
Optional numeric companyId fallback when GOAL_COMPANY_UUID is not set. |
GOAL_APP_STAGE |
Yes | dev |
Sent in the x-app-stage header (dev, test, or prod). |
GOAL_APP_UID |
Yes | goal-mcp |
Sent in the x-app-uid header to identify the MCP client in backend logs/audits. |
GOAL_API_TIMEOUT |
No | 30.0 |
HTTP request timeout in seconds for calls to goal-backend. |
goal-mcp in Two Stages (dev & prod via Streamable HTTP + Nginx)goal-mcp runs as two isolated containers bound strictly to 127.0.0.1 (goal-mcp-dev on port 8095, goal-mcp-prod on port 8096), hardened with non-root execution, read-only rootfs, and no-new-privileges:
/khayyam/home/mgonzalo/apps/goal-mcp/.env from .env.example:GOAL_API_TIMEOUT=30.0
MCP_MAX_BODY_BYTES=2097152
# DEV Stage (goal-mcp-dev -> 127.0.0.1:8095)
GOAL_DEV_API_BASE_URL=https://goal-dev-gm-api.dsroma.info/v1
MCP_DEV_BIND_PORT=8095
MCP_DEV_REQUIRE_USER_TOKEN=true
# PROD Stage (goal-mcp-prod -> 127.0.0.1:8096)
GOAL_PROD_API_BASE_URL=https://goal-gm-api.dsroma.info/v1
MCP_PROD_BIND_PORT=8096
dev and/or prod containers:cd /khayyam/home/mgonzalo/apps/goal-mcp
# Dev (docker-compose-dev.yml -> 127.0.0.1:8095)
docker compose -f docker-compose-dev.yml up -d --build
# Production (docker-compose.yml -> 127.0.0.1:8096)
docker compose up -d --build
curl -sS http://127.0.0.1:8095/health
curl -sS http://127.0.0.1:8096/health
server block per stage with TLS + rate limiting):limit_req_zone $binary_remote_addr zone=goal_mcp_limit:10m rate=20r/s;
server {
listen 443 ssl http2;
server_name goal-mcp-dev.dsroma.info;
ssl_certificate /etc/letsencrypt/live/goal-mcp-dev.dsroma.info/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/goal-mcp-dev.dsroma.info/privkey.pem;
client_max_body_size 2m;
location /mcp {
limit_req zone=goal_mcp_limit burst=40 nodelay;
proxy_pass http://127.0.0.1:8095/mcp;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_read_timeout 120s;
}
location /health {
proxy_pass http://127.0.0.1:8095/health;
}
}
(Duplicate the server block for goal-mcp.dsroma.info pointing to 127.0.0.1:8096.)mcp_config.json (Session Isolation & Per-User Token)Each user generates their own Personal Access Token from GOAL Frontend (User Profile API Keys) and configures dev and prod separately with X-App-Stage and X-Company-UUID so sessions never cross environments or companies:
{
"mcpServers": {
"goal-mcp-dev": {
"url": "https://goal-mcp-dev.dsroma.info/mcp",
"headers": {
"Authorization": "Bearer <dev-user-goal-token>",
"X-Company-UUID": "<dev-company-uuid>",
"X-App-Stage": "dev"
}
},
"goal-mcp-prod": {
"url": "https://goal-mcp.dsroma.info/mcp",
"headers": {
"Authorization": "Bearer <prod-user-goal-token>",
"X-Company-UUID": "<prod-company-uuid>",
"X-App-Stage": "prod"
}
}
}
}
X-App-Stage: Verified against the server's GOAL_APP_STAGE; mismatched requests are rejected with 403.Mcp-Session-Id: Returned by the server and bound to (stage, company, token). If a client reuses a stale session ID after switching token, company, or stage, the server rejects with 409."X-Company-Id": "<numeric-id>" instead of X-Company-UUID, or override company_uuid / company_id per tool call.).mcp.json / CLI)Add to your project .mcp.json (or ~/.claude.json):
{
"mcpServers": {
"goal-mcp-dev": {
"type": "http",
"url": "https://goal-mcp-dev.dsroma.info/mcp",
"headers": {
"Authorization": "Bearer <dev-user-goal-token>",
"X-Company-UUID": "<dev-company-uuid>",
"X-App-Stage": "dev"
}
},
"goal-mcp-prod": {
"type": "http",
"url": "https://goal-mcp.dsroma.info/mcp",
"headers": {
"Authorization": "Bearer <prod-user-goal-token>",
"X-Company-UUID": "<prod-company-uuid>",
"X-App-Stage": "prod"
}
}
}
}
Or register directly from the CLI:
claude mcp add --transport http goal-mcp-dev https://goal-mcp-dev.dsroma.info/mcp \
--header "Authorization: Bearer <dev-user-goal-token>" \
--header "X-Company-UUID: <dev-company-uuid>" \
--header "X-App-Stage: dev"
claude_desktop_config.json)Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json on macOS, %APPDATA%\Claude\claude_desktop_config.json on Windows, ~/.config/Claude/claude_desktop_config.json on Linux) bridges remote HTTP servers with custom headers via mcp-remote (requires Node.js):
{
"mcpServers": {
"goal-mcp-dev": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"https://goal-mcp-dev.dsroma.info/mcp",
"--header",
"Authorization: Bearer <dev-user-goal-token>",
"--header",
"X-Company-UUID: <dev-company-uuid>",
"--header",
"X-App-Stage: dev"
]
},
"goal-mcp-prod": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"https://goal-mcp.dsroma.info/mcp",
"--header",
"Authorization: Bearer <prod-user-goal-token>",
"--header",
"X-Company-UUID: <prod-company-uuid>",
"--header",
"X-App-Stage: prod"
]
}
}
}
tools/customers.py)| Tool | Purpose |
|---|---|
list_sales_teams_and_zones |
List active Sales Teams and L3 Zones (SalesTeamGroups). |
get_route_workload_balance_report |
Analyze L4 route customer load vs daily visit capacity (BALANCED, OVERLOADED, UNDERLOADED, UNSCHEDULED). |
get_portfolio_seller_workload_report |
Weekly workload (Mon–Sun) by Portfolio (portfolio.code) and Seller. |
get_routes_scheduled_for_day |
Routes and portfolios scheduled for a given journal day (1..7 or today). |
search_sales_team_customers |
Search active customers by L3 zone, L4 route, portfolio, day, or unassigned status. |
get_portfolio_assignment_history |
Seller assignment history (assigned_at, unassigned_at) for portfolios. |
get_territory_polygon |
Read productive paths, draft_paths, and centroid for a territory. |
list_rebalance_scenarios |
List rebalance scenarios filtered by team, zone, or status. |
get_rebalance_scenario_detail |
Get before/after route comparison and itemized changes for a scenario. |
| Tool | Purpose |
|---|---|
clone_territory_polygon_to_draft |
Clone productive paths into draft_paths. |
update_territory_draft_polygon |
Update only draft_paths from GeoJSON Polygon/MultiPolygon. |
create_rebalance_scenario |
Propose a PENDING_APPROVAL rebalance scenario with before/after diff. |
assign_customers_to_portfolio |
Assign active SalesTeamCustomer IDs to a portfolio. |
assign_or_swap_portfolio_seller |
Assign or swap a Seller on a Portfolio while keeping portfolio.code. |
upsert_route_schedule |
Create or update an L4 Route PortfolioSchedule. |
tools/master_crud.py + tools/master_registry.py)Metadata-driven CRUD covering 53 master data entities across 9 domains (base, sales, inventory, delivery, fleet, purchase, payroll, accounting, wms), gated by MCP_MASTER_WRITE_ENABLED (default true in dev, false in prod) and company-scoped GOAL V2 permissions:
| Tool | Purpose |
|---|---|
list_master_entities |
Discover all registered master data entities filtered by domain or keyword. |
describe_master_entity |
Inspect schema fields, required attributes, allowed filters, write policy, and V2 object code. |
list_master_records |
Paginated search/filter/sort (per_page capped at 100). |
get_master_record |
Retrieve a single master record by id or uuid. |
create_master_record |
Create a record with schema validation and optional dry_run=true. |
update_master_record |
Update a record while blocking protected fields (id, uuid, company_id, productive territory paths). |
delete_master_record |
Soft-delete (status='D') requiring explicit confirm=true. |
restore_master_record |
Restore a soft-deleted record (PUT /{id}/restore) for entities that support it. |
audit_territory_route_balance: Guides the AI to audit L4 route capacity and create a PENDING_APPROVAL rebalance scenario.commercial_portfolio_seller_summary: Generates an executive summary of portfolio coverage, seller vacancies, and weekly load.master_data_crud_assistant: Guided workflow to inspect, validate, and execute CRUD on any registered GOAL master entity.goal-mcp with New Modules/khayyam/home/mgonzalo/apps/goal-mcp/tools/<module>.py defining TOOLS, PROMPTS, and handle_tool_call(api, name, args).tools/__init__.py inside get_all_tools(), get_all_prompts(), and dispatch_tool_call().cli_test.py and run docker compose build && docker compose run --rm --entrypoint python goal-mcp cli_test.py.