Wiki source code of Farm Script Service

Last modified by Vincent Massol on 2026/09/04 19:20

Show last authors
1 {{code}}MCPFarmScriptService{{/code}} is the Script API behind the main wiki's MCP farm dashboard: it reads and writes each wiki's MCP state from wiki pages, with the rights check on every write. It is registered under the hint {{code}}mcp{{/code}}, so pages reach it as {{code}}$services.mcp{{/code}}.
2
3 {{code language="velocity"}}
4 #foreach ($wikiId in $services.wiki.getAllIds())
5 $wikiId: enabled=$services.mcp.isEnabled($wikiId) reach=$services.mcp.isCrossWikiReach($wikiId)
6 #end
7 {{/code}}
8
9 == Reading ==
10
11 |=Method |=Returns
12 |{{code}}isEnabled(wikiId){{/code}} |Whether that wiki's MCP endpoint is enabled
13 |{{code}}getServerUrl(wikiId){{/code}} |That wiki's externally reachable endpoint URL, ready to paste into an MCP client configuration
14 |{{code}}getToolStates(wikiId){{/code}} |Every registered tool's state on that wiki, sorted by category then id for a stable tree order
15 |{{code}}isCrossWikiReach(wikiId){{/code}} |Whether that wiki's endpoint may reach other wikis
16 |{{code}}canAdmin(wikiId){{/code}} |Whether the current user may administer that wiki
17 |{{code}}canFarmAdmin(){{/code}} |Whether the current user may administer the farm
18
19 Reads are not rights-gated, consistently with the configuration they expose. Writes are.
20
21 == Writing ==
22
23 |=Method |=Does |=Rights checked on
24 |{{code}}setEnabled(wikiId, enabled){{/code}} |Sets that wiki's MCP enabled flag |That wiki
25 |{{code}}setEnabledTools(wikiId, toolIds){{/code}} |Stores the explicit set of enabled tool ids; a {{code}}null{{/code}} array stores an explicit empty set |That wiki
26 |{{code}}setCrossWikiReach(wikiId, allowed){{/code}} |Sets that wiki's cross-wiki reach grant |The MAIN wiki
27 |{{code}}applyEnabled(managedWikiIds, enabledWikiIds){{/code}} |Sets each managed wiki enabled if and only if it is also listed as enabled |Each wiki
28 |{{code}}applyReach(managedWikiIds, reachWikiIds){{/code}} |The same for cross-wiki reach |The MAIN wiki, once
29
30 Cross-wiki reach is a farm-level decision, which is why its rights check is on the main wiki: a subwiki administrator cannot grant reach to their own wiki. The bulk methods only write a wiki whose state actually changes, and report how many they changed.
31
32 == Returned types ==
33
34 |=Type |=Members
35 |{{code}}MCPToolState{{/code}} |{{code}}getId(){{/code}}, {{code}}getCategory(){{/code}}, {{code}}getSummary(){{/code}}, {{code}}isMandatory(){{/code}}, {{code}}isWrite(){{/code}}, {{code}}isEnabled(){{/code}}
36 |{{code}}BulkResult{{/code}} |{{code}}getChanged(){{/code}}, {{code}}getSkipped(){{/code}}

Get Connected