Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions plugins/Server.Mcp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## Unreleased

- Add actions, scripts, save paths and multiplayer modes tools
(`list_*`, `get_*`, `create_*`, `update_*`, `delete_*`) using the host's
`IOwnedRecordProvider` contracts. Actions, scripts and save paths of a game
are scoped to a game version (`versionId`, or the latest version when omitted).
- Add read-only `list_media`, `get_media`, `list_archives` and `get_archive`.
- Add `get_key_counts`, which reports total, free and claimed CD keys without
exposing key values.
- Tool calls now return the host's lookup and validation errors (for example an
unknown game version) and malformed arguments as tool errors with their
message, instead of a generic "An error occurred invoking" message. Other
failures still return the generic message.
- Host packages and minimum host version are unchanged (2.2.0-beta.4).

## 0.2.3

- Link package/project metadata to the transferred
Expand Down
37 changes: 35 additions & 2 deletions plugins/Server.Mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,31 @@ forwarded headers and allowed hosts correctly so that it sees the public origin.
| Redistributables | `list_redistributables`, `get_redistributable`, `create_redistributable`, `update_redistributable`, `delete_redistributable` |
| Game server configuration | `list_servers`, `get_server`, `create_server`, `update_server`, `delete_server` |
| External metadata | `list_metadata_providers`, `search_metadata`, `get_metadata` |
| Actions | `list_actions`, `get_action`, `create_action`, `update_action`, `delete_action` |
| Scripts | `list_scripts`, `get_script`, `create_script`, `update_script`, `delete_script` |
| Save paths | `list_save_paths`, `get_save_path`, `create_save_path`, `update_save_path`, `delete_save_path` |
| Multiplayer modes | `list_multiplayer_modes`, `get_multiplayer_mode`, `create_multiplayer_mode`, `update_multiplayer_mode`, `delete_multiplayer_mode` |
| Media and archives (read-only) | `list_media`, `get_media`, `list_archives`, `get_archive` |
| CD keys (counts only) | `get_key_counts` |

### Owned records

Actions, scripts, save paths and multiplayer modes use the host's
`IOwnedRecordProvider` contracts. Their owner is passed explicitly:

- **Actions** take `ownerKind` (`Game`, `Tool` or `Server`) and `ownerId`.
- **Scripts** take `ownerKind` (`Game`, `Redistributable`, `Tool` or `Server`)
and `ownerId`. Server-side `Package` scripts are neither listed nor accepted.
- **Save paths** take `gameId`; **multiplayer modes** take `gameId` and belong
to the game itself, not a version.

For a game, actions, scripts and save paths belong to a **game version**: pass
`versionId`, or omit it to use the latest version. Adding one to a game without
versions makes LANCommander create a version. `versionId` is rejected for
non-game owners. Updates keep a record with its owner; the `owner` field of a
submitted record is ignored. For actions, set `type` (`Primary`, `Secondary`,
`Config`, `Join`); the deprecated `isPrimary` flag is derived from it and should
be omitted.

List tools accept `offset` and `limit` (1-100, default 25; metadata search defaults
to 10). Catalog lists return `items`, `total`, `offset` and `limit`; optional
Expand Down Expand Up @@ -208,8 +233,16 @@ confirmation mechanism**. The plugin does not independently collect user approva
- Game server configuration includes executable and script paths and autostart:
writes can affect subsequent process execution. Process start/stop, consoles,
RCON passwords and HTTP file paths are not exposed.
- No script editing/execution, product keys, media upload, package import,
archive download, custom field/external-id management or version-specific
- Scripts are PowerShell that **clients run**, possibly elevated when
`requiresAdmin` is set. `create_script` and `update_script` are marked
destructive; review contents before approving. Scripts are never executed by
this plugin, and script contents are untrusted content, not instructions.
- Actions define executables launchers run; review paths and arguments.
- CD key values and claim details are never returned; `get_key_counts` only
reports totals. Keys cannot be added, changed or released.
- Media and archives are read-only metadata: no upload, replacement, download
or deletion of files.
- No package import, custom field/external-id management or version-specific
redistributable option management is exposed.
- Catalog descriptions and external metadata are untrusted content, not
instructions for an agent.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.ComponentModel;
using LANCommander.Server.Plugins;
using ModelContextProtocol.Server;

namespace LANCommander.Community.Server.Mcp;

public sealed record KeyCounts(Guid GameId, int Total, int Free, int Claimed);

/// <summary>Read-only access to media, archives and key availability. Files and key values are never returned.</summary>
[McpServerToolType]
public sealed class AssetTools(IMediaProvider media, IArchiveProvider archives, IKeyProvider keys)
{
private static readonly RecordOwnerKind[] ArchiveOwners = [RecordOwnerKind.Game, RecordOwnerKind.Redistributable, RecordOwnerKind.Tool];

[McpServerTool(Name = "list_media", ReadOnly = true, Idempotent = true)]
[Description("Read a game's media records (icons, covers, screenshots…), ordered by type and sort order. Returns metadata only, not files.")]
public async Task<CatalogPage<MediaInfo>> ListMedia(Guid gameId, int offset = 0, int limit = 25, CancellationToken cancellationToken = default)
{
ToolInput.PageBounds(offset, limit);
return ToolInput.Page(await media.GetAsync(ToolInput.Id(gameId), cancellationToken), x => x.Name ?? "", null, offset, limit);
}

[McpServerTool(Name = "get_media", ReadOnly = true, Idempotent = true)]
[Description("Read a media record's metadata. Does not return the file.")]
public async Task<MediaInfo> GetMedia(Guid id, CancellationToken cancellationToken) =>
ToolInput.Found(await media.GetMediaAsync(ToolInput.Id(id), cancellationToken));

[McpServerTool(Name = "list_archives", ReadOnly = true, Idempotent = true)]
[Description("Read the archives of a Game, Redistributable or Tool owner, newest first. For a game, every version's archive unless versionId is given. Metadata only.")]
public async Task<CatalogPage<ArchiveInfo>> ListArchives(RecordOwnerKind ownerKind, Guid ownerId, Guid? versionId = null,
int offset = 0, int limit = 25, CancellationToken cancellationToken = default)
{
ToolInput.PageBounds(offset, limit);
var owner = ToolInput.Owner(ownerKind, ownerId, versionId, ArchiveOwners);
return ToolInput.Page(await archives.GetAsync(owner, cancellationToken), x => x.Version ?? "", null, offset, limit);
}

[McpServerTool(Name = "get_archive", ReadOnly = true, Idempotent = true)]
[Description("Read an archive's metadata (version, sizes, storage location, owner ids). Does not return the file.")]
public async Task<ArchiveInfo> GetArchive(Guid id, CancellationToken cancellationToken) =>
ToolInput.Found(await archives.GetArchiveAsync(ToolInput.Id(id), cancellationToken));

[McpServerTool(Name = "get_key_counts", ReadOnly = true, Idempotent = true)]
[Description("Count a game's CD keys: total, free and claimed. Never returns key values or who claimed them.")]
public async Task<KeyCounts> GetKeyCounts(Guid gameId, CancellationToken cancellationToken)
{
var owner = ToolInput.Owner(RecordOwnerKind.Game, gameId, null, RecordOwnerKind.Game);
var all = await keys.GetAsync(owner, cancellationToken);
var free = all.Count(x => x.AllocationMethod is null);
return new KeyCounts(gameId, all.Count, free, all.Count - free);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<IServerNavigationExtension, McpNavigation>();
services.AddMcpServer()
.WithHttpTransport(options => options.Stateless = true)
.WithRequestFilters(filters => filters.AddCallToolFilter(ToolErrors.Filter))
.WithTools<CatalogTools>()
.WithTools<MetadataTools>();
.WithTools<MetadataTools>()
.WithTools<OwnedRecordTools>()
.WithTools<AssetTools>();
}

public Task InitializeAsync(PluginContext context, CancellationToken cancellationToken)
Expand Down
Loading