insightfactory-cli 1.1.2.dev28__tar.gz → 1.1.2.dev29__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/CHANGELOG.md +16 -0
  2. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/PKG-INFO +62 -4
  3. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/README.md +61 -3
  4. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/pyproject.toml +1 -1
  5. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/commands/mcp.py +17 -2
  6. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/config.py +16 -2
  7. insightfactory_cli-1.1.2.dev29/src/if_cli/router/content.py +298 -0
  8. insightfactory_cli-1.1.2.dev29/src/if_cli/router/server.py +571 -0
  9. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/router/upstream.py +69 -7
  10. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_config.py +30 -0
  11. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_mcp_command.py +210 -1
  12. insightfactory_cli-1.1.2.dev29/tests/test_router_content.py +310 -0
  13. insightfactory_cli-1.1.2.dev29/tests/test_router_resources.py +436 -0
  14. insightfactory_cli-1.1.2.dev28/src/if_cli/router/server.py +0 -281
  15. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/.github/workflows/ci.yml +0 -0
  16. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/.github/workflows/claude.yml +0 -0
  17. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/.github/workflows/release.yml +0 -0
  18. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/.gitignore +0 -0
  19. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/.python-version +0 -0
  20. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/AGENTS.md +0 -0
  21. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/CLAUDE.md +0 -0
  22. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/LICENSE +0 -0
  23. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/__init__.py +0 -0
  24. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/__main__.py +0 -0
  25. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/assets/__init__.py +0 -0
  26. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/assets/insightfactoryai-logo.svg +0 -0
  27. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/cache.py +0 -0
  28. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/callback_page.py +0 -0
  29. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/cli.py +0 -0
  30. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/colour.py +0 -0
  31. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/commands/__init__.py +0 -0
  32. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/commands/api.py +0 -0
  33. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/commands/config.py +0 -0
  34. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/commands/login.py +0 -0
  35. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/commands/logout.py +0 -0
  36. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/commands/profiles.py +0 -0
  37. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/commands/set_token.py +0 -0
  38. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/commands/token.py +0 -0
  39. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/constants.py +0 -0
  40. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/http.py +0 -0
  41. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/main.py +0 -0
  42. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/oauth.py +0 -0
  43. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/router/__init__.py +0 -0
  44. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/router/catalog.py +0 -0
  45. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/router/log.py +0 -0
  46. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/router/policy.py +0 -0
  47. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/src/if_cli/runtime.py +0 -0
  48. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/__init__.py +0 -0
  49. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/cache_writer.py +0 -0
  50. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/conftest.py +0 -0
  51. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/helpers.py +0 -0
  52. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/servers.py +0 -0
  53. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_api.py +0 -0
  54. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_api_command.py +0 -0
  55. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_cache.py +0 -0
  56. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_cli.py +0 -0
  57. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_config_command.py +0 -0
  58. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_login.py +0 -0
  59. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_oauth.py +0 -0
  60. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_oauth_flow.py +0 -0
  61. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_oauth_force_refresh.py +0 -0
  62. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_profiles.py +0 -0
  63. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_programmatic_api.py +0 -0
  64. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_release_tools.py +0 -0
  65. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_router_catalog.py +0 -0
  66. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_router_policy.py +0 -0
  67. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_router_server.py +0 -0
  68. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_router_upstream.py +0 -0
  69. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_runtime.py +0 -0
  70. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_set_token.py +0 -0
  71. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tests/test_token.py +0 -0
  72. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tools/check_release.py +0 -0
  73. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/tools/release_notes.py +0 -0
  74. {insightfactory_cli-1.1.2.dev28 → insightfactory_cli-1.1.2.dev29}/uv.lock +0 -0
@@ -13,6 +13,22 @@ last one has been released, so a cycle's PRs share a section.
13
13
 
14
14
  ## 1.1.2
15
15
 
16
+ ### Added
17
+
18
+ - The MCP router serves resources, prompts and completion as well as tools, so a
19
+ factory's hosted skills reach a client through `if-cli mcp` instead of only through a
20
+ direct connection. `skill://` bodies come from the `--catalog` environment as
21
+ published; a resource template is republished with an `environment` variable added so
22
+ the client picks the factory when it expands the URI; a prompt gains the same required
23
+ `environment` argument a tool gets, plus a line naming the chosen environment in the
24
+ rendered text.
25
+ - `--skills` / `--no-skills`, and `skills = true` in a `[factory <name>]` section,
26
+ advertise the experimental skills extension (SEP-2640). Off by default: the handshake
27
+ is answered before any factory has been reached, so the claim is made only when
28
+ someone asks for it. The resources themselves are served either way, and only a
29
+ client on protocol 2026-07-28 or later can see the advertisement, since the
30
+ `initialize` handshake predates `capabilities.extensions`.
31
+
16
32
  ### Changed
17
33
 
18
34
  - `release-guard` asks every PR into `develop` for a `CHANGELOG.md` entry, and asks
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: insightfactory-cli
3
- Version: 1.1.2.dev28
3
+ Version: 1.1.2.dev29
4
4
  Summary: Profile-based authentication CLI for the InsightFactory Interfaces API
5
5
  Project-URL: Homepage, https://insightfactory.ai
6
6
  Author-email: "insightfactory.ai Support" <support@insightfactory.ai>
@@ -255,9 +255,10 @@ tst = example-tst
255
255
  writable = dev
256
256
  ```
257
257
 
258
- Every key except `writable` and `catalog` is `<environment code> = <profile name>`; file
259
- order is the environment order. `writable` is a comma-separated list of codes (default
260
- none); `catalog` is one code (default the first environment). Then:
258
+ Every key except `writable`, `catalog` and `skills` is `<environment code> = <profile name>`;
259
+ file order is the environment order. `writable` is a comma-separated list of codes (default
260
+ none); `catalog` is one code (default the first environment); `skills` is `true` or `false`
261
+ (default false). Then:
261
262
 
262
263
  ```bash
263
264
  uv tool install 'insightfactory-cli[mcp]'
@@ -290,6 +291,7 @@ passed at all, replace the section's value outright, and `--allow-tool` is alway
290
291
  | `--read-only` | Forces every environment read-only, overriding both the section's `writable` and any `--writable`. Cannot be combined with `--writable`. |
291
292
  | `--catalog CODE` (default: the first environment) | Whose tool list is published; its schemas are the reference every environment is checked against. |
292
293
  | `--allow-tool NAME` (repeatable) | Extra tool names treated as read-only, beyond the shipped list. |
294
+ | `--skills` / `--no-skills` | Whether to advertise the experimental skills extension. Off unless the section says `skills = true` or `--skills` is passed. The two cannot be combined. |
293
295
  | `--timeout SECONDS` (default `120`) | Per upstream request; higher than the `api` command's default because some tools are slow. |
294
296
 
295
297
  `mcp`'s `--timeout` does not read `INSIGHTFACTORY_REQUEST_TIMEOUT`: it parses the flag with
@@ -304,6 +306,62 @@ Passing dev-only writes to production means changing an argument value, not
304
306
  connecting to a different server, so keep `--writable` scoped to the
305
307
  environments meant to be written by hand.
306
308
 
309
+ ### Resources, prompts and completion
310
+
311
+ Resources and prompts are not merged across environments the way tools are, because
312
+ a factory's non-tool content splits in two.
313
+
314
+ `skill://` bodies are documentation that belongs to a release, identical on every
315
+ environment running it, and they cross-reference each other by bare URI. So they are
316
+ served from the `--catalog` environment exactly as published. Rewriting those URIs to
317
+ carry an environment would leave every link inside them pointing at nothing.
318
+
319
+ A resource template is the other half: `if://task-config-schemas/{taskType}` resolves
320
+ to one factory's own activity catalogue, not to a shared document. The router
321
+ republishes each template with its own variable appended, so the client chooses the
322
+ environment when it expands the URI:
323
+
324
+ ```text
325
+ if://task-config-schemas/{taskType}{?environment}
326
+ ```
327
+
328
+ A template that already opens a query gets `{&environment}` instead, and one that
329
+ ends in a fragment gets the variable in front of it, because a `?` after a `#` is an
330
+ ordinary character rather than a query. A template that already declares an
331
+ `environment` variable is skipped with a line on stderr, so one nonconforming item
332
+ does not hide the rest of the list.
333
+
334
+ Reading a URI with no `?environment=` is answered by the catalogue environment,
335
+ unless the URI could be an expansion of a published template, which is refused
336
+ naming the codes to choose from. Membership of `resources/list` is deliberately not
337
+ the test: a skill body may link to a sibling document the factory never advertised,
338
+ and such a link carries no `environment` and could not be given one.
339
+ `completion/complete` reads the environment from the request's context arguments,
340
+ then from the reference URI, and falls back to the catalogue environment for anything
341
+ it does not recognise, because a half-typed context value is the normal state of a
342
+ completion request and completion should degrade rather than fail. The router answers
343
+ for the `environment` variable itself rather than asking a factory about an argument
344
+ it has never heard of.
345
+
346
+ Prompts gain a required `environment` argument like tools. The router also prepends a
347
+ line to every rendered prompt naming the environment chosen, because a factory writes
348
+ its prompts for a client talking to one factory and they tell the model to call tools
349
+ without one. Prepended rather than appended, and marked `[if-cli router]`: the
350
+ factory's own last turn may be an assistant prefill, which a trailing user turn would
351
+ silently end.
352
+
353
+ `--skills` only controls the advertisement. The handshake is answered before any
354
+ factory has been reached, so the router cannot ask the catalogue environment whether
355
+ it serves skills in time to repeat the claim, and an experimental capability is not
356
+ worth guessing at. The `skill://` resources are served either way.
357
+
358
+ The advertisement reaches only a client on MCP protocol 2026-07-28 or later.
359
+ `capabilities.extensions` was added in that revision, and the `initialize` handshake
360
+ every current client opens with negotiates a 2025 revision whose capability schema
361
+ has no such field, so the SDK strips it before it reaches the wire. Against
362
+ `foundryaz-dev` with `--skills` on, Claude Code sees no extension and still finds
363
+ every skill through `resources/list`, which is how clients discover them today.
364
+
307
365
  A tool the factory will not run until someone finishes a step in a browser, such
308
366
  as linking a personal Databricks identity, comes back as a failed call naming the
309
367
  page to visit rather than as a prompt. The router never relays the factory's
@@ -231,9 +231,10 @@ tst = example-tst
231
231
  writable = dev
232
232
  ```
233
233
 
234
- Every key except `writable` and `catalog` is `<environment code> = <profile name>`; file
235
- order is the environment order. `writable` is a comma-separated list of codes (default
236
- none); `catalog` is one code (default the first environment). Then:
234
+ Every key except `writable`, `catalog` and `skills` is `<environment code> = <profile name>`;
235
+ file order is the environment order. `writable` is a comma-separated list of codes (default
236
+ none); `catalog` is one code (default the first environment); `skills` is `true` or `false`
237
+ (default false). Then:
237
238
 
238
239
  ```bash
239
240
  uv tool install 'insightfactory-cli[mcp]'
@@ -266,6 +267,7 @@ passed at all, replace the section's value outright, and `--allow-tool` is alway
266
267
  | `--read-only` | Forces every environment read-only, overriding both the section's `writable` and any `--writable`. Cannot be combined with `--writable`. |
267
268
  | `--catalog CODE` (default: the first environment) | Whose tool list is published; its schemas are the reference every environment is checked against. |
268
269
  | `--allow-tool NAME` (repeatable) | Extra tool names treated as read-only, beyond the shipped list. |
270
+ | `--skills` / `--no-skills` | Whether to advertise the experimental skills extension. Off unless the section says `skills = true` or `--skills` is passed. The two cannot be combined. |
269
271
  | `--timeout SECONDS` (default `120`) | Per upstream request; higher than the `api` command's default because some tools are slow. |
270
272
 
271
273
  `mcp`'s `--timeout` does not read `INSIGHTFACTORY_REQUEST_TIMEOUT`: it parses the flag with
@@ -280,6 +282,62 @@ Passing dev-only writes to production means changing an argument value, not
280
282
  connecting to a different server, so keep `--writable` scoped to the
281
283
  environments meant to be written by hand.
282
284
 
285
+ ### Resources, prompts and completion
286
+
287
+ Resources and prompts are not merged across environments the way tools are, because
288
+ a factory's non-tool content splits in two.
289
+
290
+ `skill://` bodies are documentation that belongs to a release, identical on every
291
+ environment running it, and they cross-reference each other by bare URI. So they are
292
+ served from the `--catalog` environment exactly as published. Rewriting those URIs to
293
+ carry an environment would leave every link inside them pointing at nothing.
294
+
295
+ A resource template is the other half: `if://task-config-schemas/{taskType}` resolves
296
+ to one factory's own activity catalogue, not to a shared document. The router
297
+ republishes each template with its own variable appended, so the client chooses the
298
+ environment when it expands the URI:
299
+
300
+ ```text
301
+ if://task-config-schemas/{taskType}{?environment}
302
+ ```
303
+
304
+ A template that already opens a query gets `{&environment}` instead, and one that
305
+ ends in a fragment gets the variable in front of it, because a `?` after a `#` is an
306
+ ordinary character rather than a query. A template that already declares an
307
+ `environment` variable is skipped with a line on stderr, so one nonconforming item
308
+ does not hide the rest of the list.
309
+
310
+ Reading a URI with no `?environment=` is answered by the catalogue environment,
311
+ unless the URI could be an expansion of a published template, which is refused
312
+ naming the codes to choose from. Membership of `resources/list` is deliberately not
313
+ the test: a skill body may link to a sibling document the factory never advertised,
314
+ and such a link carries no `environment` and could not be given one.
315
+ `completion/complete` reads the environment from the request's context arguments,
316
+ then from the reference URI, and falls back to the catalogue environment for anything
317
+ it does not recognise, because a half-typed context value is the normal state of a
318
+ completion request and completion should degrade rather than fail. The router answers
319
+ for the `environment` variable itself rather than asking a factory about an argument
320
+ it has never heard of.
321
+
322
+ Prompts gain a required `environment` argument like tools. The router also prepends a
323
+ line to every rendered prompt naming the environment chosen, because a factory writes
324
+ its prompts for a client talking to one factory and they tell the model to call tools
325
+ without one. Prepended rather than appended, and marked `[if-cli router]`: the
326
+ factory's own last turn may be an assistant prefill, which a trailing user turn would
327
+ silently end.
328
+
329
+ `--skills` only controls the advertisement. The handshake is answered before any
330
+ factory has been reached, so the router cannot ask the catalogue environment whether
331
+ it serves skills in time to repeat the claim, and an experimental capability is not
332
+ worth guessing at. The `skill://` resources are served either way.
333
+
334
+ The advertisement reaches only a client on MCP protocol 2026-07-28 or later.
335
+ `capabilities.extensions` was added in that revision, and the `initialize` handshake
336
+ every current client opens with negotiates a 2025 revision whose capability schema
337
+ has no such field, so the SDK strips it before it reaches the wire. Against
338
+ `foundryaz-dev` with `--skills` on, Claude Code sees no extension and still finds
339
+ every skill through `resources/list`, which is how clients discover them today.
340
+
283
341
  A tool the factory will not run until someone finishes a step in a browser, such
284
342
  as linking a personal Databricks identity, comes back as a failed call naming the
285
343
  page to visit rather than as a prompt. The router never relays the factory's
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "insightfactory-cli"
3
- version = "1.1.2.dev28"
3
+ version = "1.1.2.dev29"
4
4
  description = "Profile-based authentication CLI for the InsightFactory Interfaces API"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -15,12 +15,15 @@ MCP_OPTIONS: Options = {
15
15
  "catalog": {"type": "string"},
16
16
  "allow-tool": {"type": "string", "repeat": True},
17
17
  "timeout": {"type": "string", "default": "120"},
18
+ "skills": {"type": "boolean"},
19
+ "no-skills": {"type": "boolean"},
18
20
  }
19
21
 
20
22
  MCP_USAGE = (
21
23
  "usage: if-cli mcp [FACTORY] [--env CODE=PROFILE ...]\n"
22
24
  " [--writable CODE ... | --read-only] [--catalog CODE]\n"
23
25
  " [--allow-tool NAME ...] [--timeout SECONDS]\n"
26
+ " [--skills | --no-skills]\n"
24
27
  "\n"
25
28
  "Runs one MCP server over stdio that fronts several factory environments: every\n"
26
29
  "tool gets a required 'environment' argument, routed to that environment's own\n"
@@ -29,7 +32,9 @@ MCP_USAGE = (
29
32
  "section. Without FACTORY, --env is required at least once. --catalog defaults\n"
30
33
  "to the first environment; environments not passed to --writable are read-only;\n"
31
34
  "--read-only forces every environment read-only and cannot be combined with\n"
32
- "--writable.\n"
35
+ "--writable. --skills advertises the experimental skills extension; the\n"
36
+ "catalog environment's skill:// resources are served either way. It is off\n"
37
+ "unless the factory section says 'skills = true' or --skills is passed.\n"
33
38
  )
34
39
 
35
40
  MISSING_MCP_EXTRA = (
@@ -91,6 +96,9 @@ def mcp_command(argv: list[str]) -> None:
91
96
  if read_only and raw_writable is not None:
92
97
  die(f"--read-only cannot be combined with --writable\n\n{MCP_USAGE}")
93
98
 
99
+ if values["skills"] and values["no-skills"]:
100
+ die(f"--skills cannot be combined with --no-skills\n\n{MCP_USAGE}")
101
+
94
102
  config = load_config()
95
103
 
96
104
  # A dict, not a list of pairs: --env "adds or replaces that code's profile"
@@ -102,12 +110,14 @@ def mcp_command(argv: list[str]) -> None:
102
110
  mappings: dict[str, str] = {}
103
111
  writable_codes: frozenset[str] = frozenset()
104
112
  catalog_source: str | None = None
113
+ skills = False
105
114
 
106
115
  if factory_name is not None:
107
116
  factory = parse_factory_section(config, factory_name)
108
117
  mappings.update(factory["environments"])
109
118
  writable_codes = factory["writable"]
110
119
  catalog_source = factory["catalog"]
120
+ skills = factory["skills"]
111
121
 
112
122
  for raw in raw_envs:
113
123
  code, profile_name = _parse_env_mapping(raw)
@@ -125,6 +135,10 @@ def mcp_command(argv: list[str]) -> None:
125
135
  writable_codes = frozenset(raw_writable)
126
136
  if values["catalog"] is not None:
127
137
  catalog_source = values["catalog"]
138
+ if values["skills"]:
139
+ skills = True
140
+ elif values["no-skills"]:
141
+ skills = False
128
142
  if catalog_source is None:
129
143
  catalog_source = codes[0]
130
144
 
@@ -153,7 +167,7 @@ def mcp_command(argv: list[str]) -> None:
153
167
  f"{code}={mappings[code]} {profiles[code]['host']}{' (writable)' if code in writable_codes else ''}"
154
168
  for code in codes
155
169
  ]
156
- log(f"{label}: {'; '.join(parts)}; catalog={catalog_source}")
170
+ log(f"{label}: {'; '.join(parts)}; catalog={catalog_source}; skills={'on' if skills else 'off'}")
157
171
 
158
172
  router = build_router(
159
173
  profiles=profiles,
@@ -161,5 +175,6 @@ def mcp_command(argv: list[str]) -> None:
161
175
  catalog_source=catalog_source,
162
176
  extra_read_only=extra_read_only,
163
177
  timeout=timeout,
178
+ skills=skills,
164
179
  )
165
180
  run_server(router)
@@ -28,10 +28,13 @@ class Factory(TypedDict):
28
28
  environments: list[tuple[str, str]]
29
29
  writable: frozenset[str]
30
30
  catalog: str
31
+ skills: bool
31
32
 
32
33
 
33
34
  FACTORY_SECTION_PREFIX = "factory "
34
- FACTORY_RESERVED_KEYS = {"writable", "catalog"}
35
+ FACTORY_RESERVED_KEYS = {"writable", "catalog", "skills"}
36
+ FACTORY_TRUE = {"true", "yes", "on", "1"}
37
+ FACTORY_FALSE = {"false", "no", "off", "0", ""}
35
38
 
36
39
 
37
40
  def config_dir() -> str:
@@ -217,7 +220,18 @@ def parse_factory_section(config: dict[str, dict[str, str]], name: str) -> Facto
217
220
  catalog_value = section.get("catalog")
218
221
  catalog = catalog_value.strip() if catalog_value is not None and catalog_value.strip() else codes[0]
219
222
 
220
- return {"name": name, "environments": environments, "writable": writable, "catalog": catalog}
223
+ skills_value = section.get("skills", "").strip().lower()
224
+ if skills_value not in FACTORY_TRUE and skills_value not in FACTORY_FALSE:
225
+ die(f"factory '{name}' in {config_file()}: skills must be true or false (found '{skills_value}')")
226
+ skills = skills_value in FACTORY_TRUE
227
+
228
+ return {
229
+ "name": name,
230
+ "environments": environments,
231
+ "writable": writable,
232
+ "catalog": catalog,
233
+ "skills": skills,
234
+ }
221
235
 
222
236
 
223
237
  def get_factory(config: dict[str, dict[str, str]], name: str) -> Factory:
@@ -0,0 +1,298 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from collections.abc import Mapping, Sequence
5
+ from typing import Any
6
+ from urllib.parse import unquote, unquote_plus, urlsplit, urlunsplit
7
+
8
+ from if_cli.router.catalog import ENV_ARG, EnvironmentSpec
9
+
10
+ # RFC 6570 query expansion. A client that expands the published template fills
11
+ # `environment` like any other variable, so selecting the factory reads the same
12
+ # way for a resource as the spliced enum does for a tool. Form style opens a
13
+ # query with `?`; continuation style adds to one that is already open, and a
14
+ # template carrying its own query needs the second (see `scope_template`).
15
+ TEMPLATE_SUFFIX = "{?" + ENV_ARG + "}"
16
+ TEMPLATE_CONTINUATION = "{&" + ENV_ARG + "}"
17
+
18
+ # The variable expression inside a URI template, for reading its variable list
19
+ # and for turning the template into a matcher.
20
+ _EXPRESSION = re.compile(r"\{[^}]*\}")
21
+
22
+ # The operator an expression may open with, and the modifiers a varspec may
23
+ # carry: `{+path}`, `{?a,b}`, `{#frag}`, `{x:3}`, `{y*}`.
24
+ _OPERATORS = "+#./;?&=,!@|"
25
+
26
+ # An expression that expands into the fragment, where a `?` is no longer a query.
27
+ _FRAGMENT = re.compile(r"\{#[^}]*\}")
28
+
29
+ # An expression that continues a query rather than opening one.
30
+ _CONTINUATION = re.compile(r"\{&[^}]*\}")
31
+
32
+
33
+ class ContentError(Exception):
34
+ """A routing decision this router cannot make, reported to the client as an error.
35
+
36
+ Distinct from `CliError`: that ends the process at startup, this one answers
37
+ a single request and leaves the server running.
38
+ """
39
+
40
+
41
+ def _variable_names(expression: str) -> list[str]:
42
+ """The variable names one RFC 6570 expression declares.
43
+
44
+ `{?deploy.environment}` declares `deploy.environment`, not `environment`:
45
+ a dot is legal in a varname, so matching on a word boundary would refuse a
46
+ template that never names ours. Modifiers are stripped, because `{x:3}` and
47
+ `{x*}` are both the variable `x`.
48
+
49
+ Names are decoded before they are compared, because a varname may be
50
+ percent-encoded and `split_environment` decodes the field name it reads.
51
+ The two have to agree about that, or a name claims our field without
52
+ tripping the guard.
53
+ """
54
+ body = expression[1:-1].lstrip(_OPERATORS)
55
+ return [unquote(name.split(":", 1)[0].rstrip("*")) for name in body.split(",") if name]
56
+
57
+
58
+ def _literal_query_names(uri_template: str) -> list[str]:
59
+ """The names of the query fields a template spells out for itself.
60
+
61
+ `if://search?environment=fixed{&q}` declares no variable at all, so reading
62
+ the expressions alone would miss that it has already taken our field.
63
+ """
64
+ stem = _EXPRESSION.sub("", _split_fragment(uri_template)[0])
65
+ # Split on both delimiters: `if://x{?a}&environment=fixed` opens its query
66
+ # inside an expression, so partitioning on `?` alone would see no query at
67
+ # all. Neither character can appear in a path, so the first segment is the
68
+ # only one that is not a field.
69
+ return [unquote_plus(field.split("=", 1)[0]) for field in re.split(r"[?&]", stem)[1:] if field]
70
+
71
+
72
+ def declares_environment(uri_template: str) -> bool:
73
+ if ENV_ARG in _literal_query_names(uri_template):
74
+ return True
75
+ return any(ENV_ARG in _variable_names(expression) for expression in _EXPRESSION.findall(uri_template))
76
+
77
+
78
+ def _environment_list(environments: Sequence[EnvironmentSpec]) -> str:
79
+ return "; ".join(f"{env.code} = {env.label}{'' if env.writable else ' (read-only)'}" for env in environments)
80
+
81
+
82
+ def split_environment(uri: str) -> tuple[str, str | None]:
83
+ """Peel `?environment=<code>` off a resource URI, returning the rest and the code.
84
+
85
+ Only this router's own parameter is removed, and every other field is
86
+ carried across as the exact bytes the client sent: the URI belongs to the
87
+ factory, which may parse or sign it, so decoding and re-encoding it would
88
+ hand upstream something the client never wrote. Only the field *name* is
89
+ decoded, and only to compare it.
90
+
91
+ A blank `environment=` is what an RFC 6570 client emits when it expands the
92
+ variable with nothing, so it counts as unset, but it is still stripped: it
93
+ is our field either way and the factory has no use for it.
94
+ """
95
+ parts = urlsplit(uri)
96
+ if not parts.query:
97
+ return uri, None
98
+ fields = parts.query.split("&")
99
+ # Last wins, and exactly one field is ours. The router appends its own
100
+ # variable after whatever the factory published, so when a URI carries two
101
+ # the later one is the client's and the earlier one belongs to the factory:
102
+ # removing both would delete a field this module exists to forward intact.
103
+ ours = [at for at, field in enumerate(fields) if unquote_plus(field.split("=", 1)[0]) == ENV_ARG]
104
+ if not ours:
105
+ return uri, None
106
+ mine = ours[-1]
107
+ _, _, value = fields[mine].partition("=")
108
+ kept = [field for at, field in enumerate(fields) if at != mine]
109
+ bare = urlunsplit((parts.scheme, parts.netloc, parts.path, "&".join(kept), parts.fragment))
110
+ # The blank is read after the pick, not used to choose: a client that
111
+ # expanded the variable with nothing has said "unset", and saying it last
112
+ # does not hand the choice back to an earlier field.
113
+ return bare, unquote_plus(value) if value else None
114
+
115
+
116
+ def scope_template(template: Mapping[str, Any], environments: Sequence[EnvironmentSpec]) -> dict[str, Any]:
117
+ """Publish one resource template with `environment` appended as a variable.
118
+
119
+ A template is the only resource shape whose contents are per-environment:
120
+ `if://task-config-schemas/{taskType}` resolves to that factory's own
121
+ activity catalogue. Concrete resources are not scoped this way (see
122
+ `resolve_resource`), because `skill://` bodies cross-reference each other by
123
+ bare URI and rewriting them would leave those links pointing at nothing.
124
+ """
125
+ uri_template = template.get("uriTemplate") or ""
126
+ if not uri_template:
127
+ raise ContentError("resource template has no uriTemplate.")
128
+ if declares_environment(uri_template):
129
+ raise ContentError(
130
+ f'resource template "{uri_template}" already declares an "{ENV_ARG}" variable, which the router '
131
+ "reserves to select the factory environment."
132
+ )
133
+ # A template that already opens a query gets the continuation operator;
134
+ # a second `{?...}` would expand to a second literal `?` and the parameter
135
+ # would be read as part of the previous value.
136
+ stem, fragment = _split_fragment(uri_template)
137
+ suffix = TEMPLATE_CONTINUATION if _opens_a_query(stem) else TEMPLATE_SUFFIX
138
+ description = (template.get("description") or "").rstrip()
139
+ note = f"Set {ENV_ARG} to choose which factory environment answers: {_environment_list(environments)}."
140
+ return {
141
+ **template,
142
+ "uriTemplate": f"{stem}{suffix}{fragment}",
143
+ "description": f"{description}\n\n{note}" if description else note,
144
+ }
145
+
146
+
147
+ def _split_fragment(uri_template: str) -> tuple[str, str]:
148
+ """Split a template before whatever expands into its fragment.
149
+
150
+ Everything after a `#` is the fragment, where a `?` is an ordinary
151
+ character rather than a query opener, so the router's own variable has to
152
+ go in front of it or it never reaches `split_environment`.
153
+ """
154
+ match = _FRAGMENT.search(uri_template)
155
+ cuts = [at for at in (match.start() if match else -1, uri_template.find("#")) if at >= 0]
156
+ if not cuts:
157
+ return uri_template, ""
158
+ cut = min(cuts)
159
+ return uri_template[:cut], uri_template[cut:]
160
+
161
+
162
+ def _opens_a_query(uri_template: str) -> bool:
163
+ """Whether expanding this template can already have produced a `?`.
164
+
165
+ `{&x}` counts only alongside a reserved expansion, which is the one way a
166
+ query can be open without the template text saying so. On its own, `{&x}`
167
+ with no `?` anywhere is a template whose expansion has no query at all, and
168
+ there form style is right: it opens one rather than continuing it, so
169
+ `if://x{&q}{?environment}` expands to `if://x&q=1?environment=prd`, which
170
+ routes and hands the factory back exactly what its own template produces.
171
+ """
172
+ reduced = _EXPRESSION.sub(lambda match: match.group(0)[:2], uri_template)
173
+ return "?" in reduced or ("{&" in reduced and "{+" in reduced)
174
+
175
+
176
+ def unscope_template(uri_template: str) -> str:
177
+ """Remove the variable `scope_template` added, wherever it was put.
178
+
179
+ Not a suffix strip: a template with a fragment carries it in the middle,
180
+ and the factory has never heard of it in any position.
181
+ """
182
+ return uri_template.replace(TEMPLATE_SUFFIX, "", 1).replace(TEMPLATE_CONTINUATION, "", 1)
183
+
184
+
185
+ def template_matcher(uri_template: str) -> re.Pattern[str]:
186
+ """A matcher for URIs that are expansions of `uri_template`.
187
+
188
+ Deliberately loose: every variable expression becomes "any characters,
189
+ including none", because an undefined RFC 6570 variable expands to nothing
190
+ and `{id}{?format}` with no format is still an expansion. It is only ever
191
+ asked whether a URI *could* be one, and being loose makes it fail towards
192
+ refusing to guess an environment rather than towards silently answering
193
+ from the wrong factory.
194
+
195
+ A template of nothing but variables matches every URI, so it discriminates
196
+ nothing and is given a matcher that matches nothing instead. That guard is
197
+ for "matches literally everything", not for "too loose to be useful":
198
+ `if://{path}` keeps its scheme literal and so still claims the whole
199
+ `if://` space, which makes every static `if://` resource need an
200
+ environment. Refusing is the safe direction, but it is a real cost.
201
+
202
+ A reserved expansion (`{+var}`, `{#var}`) can expand into `?` and `#`
203
+ itself, so whether a URI opens a query is not decidable from the template
204
+ text. Everything here is a heuristic over the literal characters.
205
+
206
+ The matcher is built from the catalogue source's templates alone, so a
207
+ template only another environment publishes is invisible here. A client can
208
+ only learn of one out of band, since `resources/templates/list` publishes
209
+ the catalogue source's, so the gap is narrow; it is the reason this is a
210
+ routing hint rather than a guarantee.
211
+ """
212
+ literals = _EXPRESSION.split(uri_template)
213
+ if not any(literals):
214
+ return re.compile(r"(?!)")
215
+ return re.compile(".*".join(re.escape(literal) for literal in literals))
216
+
217
+
218
+ def resolve_resource(
219
+ uri: str,
220
+ *,
221
+ templates: Sequence[str],
222
+ catalog_source: str,
223
+ codes: Sequence[str],
224
+ reserved: Sequence[str] = (),
225
+ ) -> tuple[str, str]:
226
+ """Which environment answers `uri`, and the URI to ask it for.
227
+
228
+ Two cases, and the URI itself says which. A template expansion is
229
+ per-environment content (`if://task-config-schemas/AZSQL` is that factory's
230
+ own activity catalogue), so it is read from the environment its query names
231
+ and refused without one rather than answered from the wrong factory.
232
+ Anything else is static content the release publishes identically
233
+ everywhere (the `skill://` bodies), so it is read from the catalogue source.
234
+
235
+ Membership of `resources/list` is deliberately not the test: a skill body
236
+ may link to a sibling document the factory never advertised, and such a link
237
+ carries no `environment` and could not be given one.
238
+ """
239
+ bare, chosen = split_environment(uri)
240
+ if chosen is not None:
241
+ if chosen not in codes:
242
+ # A template this router refused to publish takes the field for
243
+ # itself, so what looks like a bad environment code is the
244
+ # factory's own value. The operator reads that on stderr when the
245
+ # listing skips it; the client deserves the same sentence.
246
+ claimed = next((template for template in reserved if template_matcher(template).fullmatch(uri)), None)
247
+ if claimed is not None:
248
+ raise ContentError(
249
+ f'"{uri}" expands the resource template "{claimed}", which takes the "{ENV_ARG}" field for '
250
+ "itself. This router reserves that field to select the factory environment, so it cannot "
251
+ "route this template and does not publish it."
252
+ )
253
+ raise ContentError(f'Unknown environment "{chosen}". Choose one of: {", ".join(codes)}')
254
+ return bare, chosen
255
+ matched = next((template for template in templates if template_matcher(template).fullmatch(bare)), None)
256
+ if matched is not None:
257
+ raise ContentError(
258
+ f'"{bare}" expands the resource template "{matched}", whose contents differ per factory, so it needs '
259
+ f"an environment: append ?{ENV_ARG}=<code> to the URI. Choose one of: {', '.join(codes)}"
260
+ )
261
+ return bare, catalog_source
262
+
263
+
264
+ def splice_prompt_environment(prompt: Mapping[str, Any], environments: Sequence[EnvironmentSpec]) -> dict[str, Any]:
265
+ """Publish one prompt with `environment` added as a required argument."""
266
+ arguments = [dict(argument) for argument in (prompt.get("arguments") or [])]
267
+ if any(argument.get("name") == ENV_ARG for argument in arguments):
268
+ raise ContentError(
269
+ f'prompt "{prompt.get("name")}" already declares an "{ENV_ARG}" argument, which the router reserves '
270
+ "to select the factory environment."
271
+ )
272
+ arguments.append(
273
+ {
274
+ "name": ENV_ARG,
275
+ "description": f"Which factory environment to run this against. {_environment_list(environments)}.",
276
+ "required": True,
277
+ }
278
+ )
279
+ return {**prompt, "arguments": arguments}
280
+
281
+
282
+ def environment_instruction(code: str, label: str) -> str:
283
+ """The line the router prepends to a rendered prompt.
284
+
285
+ The factory writes its prompts for a client talking to one factory, so they
286
+ name tools without an environment. Through the router every one of those
287
+ calls needs the argument, and a model following the prompt verbatim would
288
+ omit it on the first call and be told off for it.
289
+
290
+ Prepended rather than appended, and attributed: the factory's own last turn
291
+ may be an assistant prefill, which a trailing user turn would silently end,
292
+ and a bare instruction in the factory's voice is indistinguishable from the
293
+ prompt it is wrapping.
294
+ """
295
+ return (
296
+ f'[if-cli router] Every tool call while following this prompt must pass {ENV_ARG}="{code}" ({label}). '
297
+ "This router fronts several factory environments and the instructions below do not name one."
298
+ )