feat(mcp): hosted instance read tools - #7727
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7727 +/- ##
==========================================
+ Coverage 76.19% 76.24% +0.05%
==========================================
Files 443 443
Lines 23726 23776 +50
Branches 6314 6321 +7
==========================================
+ Hits 18079 18129 +50
Misses 5647 5647
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
04324b4 to
6af352f
Compare
8bfb22e to
9742987
Compare
6af352f to
fdafd47
Compare
fdafd47 to
df8ad04
Compare
103f9ae to
5773bdb
Compare
Add forge/ee/lib/mcp/schemas.js, a shared module of composable zod fragments the platform read tools import instead of redefining entity-id and pagination/search/sort/audit-log query fields in each tool file. - entity-id params: teamId, applicationId, hostedInstanceId (UUID), remoteInstanceId, snapshotId - query fragments composed per route by spreading only the params the backing finder honors: cursorParam/limitParam (basePagination), pageParam, searchQuery, sortParams, auditLogFilters - appendQuery serialises a tool's supported params onto the request URL The module lives one level above tools/ so the tool loader does not register it as a tool module. Closes #7669
eae081f to
e04360f
Compare
283ad01 to
4206424
Compare
4206424 to
526dcd3
Compare
526dcd3 to
da1f501
Compare
…ayload shape
Return each platform_get_instance_config section as { statusCode, data }
so array payloads such as the autoUpdateStack schedule survive instead of
being spread into numeric keys.
Reword platform_get_hosted_instance_resources to describe a time-series of
usage samples rather than a point-in-time snapshot, and drop the claim in
both that tool and platform_get_instance_history that the not-enabled case
is rewritten into a friendly message (the routes return a plain not-found).
Note that flowLastUpdatedAt sort and orderByMostRecentFlows only apply when
includeLiveStatus is set, and drop the inert device:history token scope
(the remote history route checks project:history).
The audit-log export route responds with text/csv, but the MCP response formatter always parses a success body as JSON, so requesting format=csv failed. A downloadable CSV file cannot be delivered over the tool transport anyway, so remove the format argument and always return JSON entries.
Testing results of new/edited tools@cstns for visibility Every tool below was invoked against a running local platform (team DEV, 10 hosted instances, primary instance platform_list_hosted_instancesReturns a list of hosted instances.
platform_get_hosted_instanceReturns the full settings/metadata of one instance: id, name, url, its application and team, current state, and specification (instance type, stack, template).
platform_get_hosted_instance_statusReturns the live runtime status only.
platform_get_hosted_instance_logsReturns Node-RED console log entries, newest first, with cursor pagination.
platform_check_hosted_instance_name_availabilityReturns whether a proposed instance name is free.
platform_get_instance_configReturns the requested config sections, each independently as {statusCode, data}. data is an object for ha/protection and an array of weekly restart windows for autoUpdateStack.
Confirms both fixes shipped in this PR: per-section {statusCode, data} and the autoUpdateStack array shape (no array-spread corruption). platform_get_instance_custom_hostnameReturns the configured custom hostname; with includeStatus, also the live CNAME verification status.
platform_list_instance_filesReturns the files/directories at a path in the instance file store. Tested on
platform_list_instance_http_tokensReturns the HTTP bearer tokens for a hosted or remote instance (token secrets not included).
platform_get_hosted_instance_audit_logReturns audit entries (paginated), each = {id, createdAt, username, event, scope, trigger, source, body}, plus {meta:{next_cursor}, count, associations:{applications,instances,devices}}. The tool always returns JSON entries (the former format="csv" option was removed in this pass).
platform_get_instance_historyReturns a chronological timeline for a hosted or remote instance, cursor-paginated.
platform_get_hosted_instance_resourcesReturns stored CPU/memory usage as a time-series (a list of samples over time), not a live feed.
platform_list_team_dashboard_instancesReturns the team's hosted instances that have the Node-RED dashboard installed.
ConclusionAll 13 tools verified against their descriptions, including the fixes shipped in this PR (get_instance_config {statusCode, data} + autoUpdateStack array shape; flowLastUpdatedAt / orderByMostRecentFlows requiring includeLiveStatus). No open defects. |
Summary
Phase 1 read-only MCP tools for the hosted instance resource, added to
forge/ee/lib/mcp/tools/instances.js. This covers per-instance configuration surfaces, instance observability, and the team-scoped instance lists:platform_get_instance_config- one configuration reader taking asectionsarray (any subset ofha,protection,autoUpdateStack; defaults to all). Backed byGET /projects/:id/ha,GET /projects/:id/protectInstance, andGET /projects/:id/autoUpdateStack, returning each requested section independently.platform_get_instance_custom_hostname-GET /projects/:id/customHostname, with anincludeStatusboolean that additionally fetches the live verification status fromGET /projects/:id/customHostname/status.platform_list_instance_files-GET /projects/:id/files/_/:pathplatform_list_instance_http_tokens- takesinstanceType(hostedorremote); lists the HTTP bearer tokens for a hosted or remote instance.platform_get_hosted_instance_audit_log-GET /projects/:id/audit-log, returning audit entries as JSON.platform_get_instance_history- takesinstanceType(hostedorremote); returns the timeline for a hosted or remote instance.platform_get_hosted_instance_resources-GET /projects/:id/resourcesplatform_list_team_dashboard_instances-GET /teams/:teamId/dashboard-instancesEach tool describes the hosted instance resource, so all are filed with the existing hosted instance tools, following the one-file-per-resource convention.
platform_list_team_dashboard_instanceshangs off a team URL but lists hosted instances.All tools are annotated
readOnlyHint: true, destructiveHint: false. Several backing routes are plan-gated per team (High Availability, custom hostnames, protected instance, static file storage, HTTP bearer tokens, instance history, instance resources); since a disabled feature and a genuine not-found both return a 404, the affected tools turn that 404 into a descriptive "feature not enabled for this team" message. The auto-update-stack route has no feature gate, so that section passes through unchanged. The/resources/streamWebSocket route is intentionally not exposed; only the point-in-time/resourcessnapshot is implemented.Scopes allow-listed for
user:expert-mcpinforge/routes/auth/permissions.js:project:edit(custom-hostname and HTTP-token reads)project:files:list(instance file listing)project:audit-log(instance audit log)project:history(hosted instance history)device:history(remote instance history, via the generalized history tool)(
project:readandteam:projects:listwere already present.)Write, delete and admin-only tools for this resource are out of scope for this PR.
Consolidation notes
platform_get_instance_ha,platform_get_instance_protection, andplatform_get_instance_auto_update_stackare merged intoplatform_get_instance_config, which takes asectionsarray (subset ofha/protection/autoUpdateStack, defaults to all) and returns each requested section independently.platform_get_instance_custom_hostnameandplatform_get_instance_custom_hostname_statusare merged intoplatform_get_instance_custom_hostname, with anincludeStatusboolean that also fetches the live verification status.platform_export_hosted_instance_audit_logis removed;platform_get_hosted_instance_audit_logreturns audit entries as JSON.platform_list_instance_http_tokensandplatform_get_instance_history(renamed fromplatform_get_hosted_instance_history) take aninstanceType(hostedorremote) and now also serve remote instances, replacing the remote-only variants dropped from feat(mcp): remote instance (device) read tools #7726.platform_list_team_projectsis dropped; its capability is folded intoplatform_list_hosted_instances, which gainedsort,dir, andorderByMostRecentFlowsfor the team-wide listing.platform_list_hosted_instancesreuses the shared fragments (teamId,applicationId,searchQuery,sortParams.dir) fromforge/ee/lib/mcp/schemas.jsinstead of re-declaring them inline; its bespokelimit(max 10) andsortenum stay inline.Closes #7705
Test plan
eslintclean on the changed filesmochaunit tests