Skip to content
Merged
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
3 changes: 3 additions & 0 deletions facts/AI_CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ ids <packet-id> [--format json|toon]
ids --pv <N> [--ns namespace] [--direction toClient|toServer] [--format json|toon]
chunks [--kind all|packet|type] [--filter text] [--max-chars N] [--format json|toon]
stats [--format json|toon]
versions [--format json|toon]
order [--format json|toon]
graph [--ns play] [--direction toClient] [--include-types false] [--format json|toon]
```
Expand Down Expand Up @@ -117,6 +118,7 @@ get_protocol_usage
get_protocol_users
get_protocol_dependencies
get_protocol_stats
get_protocol_versions
get_protocol_graph
```

Expand All @@ -129,6 +131,7 @@ endpoints are useful when another process is already running the server:
GET /api/packets
GET /api/packets/{ns}/{dir}
GET /api/stats
GET /api/versions
GET /api/types
GET /api/native-types
GET /api/types-by-kind
Expand Down
3 changes: 3 additions & 0 deletions facts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ ids <packet-id> [--format json|toon]
ids --pv <N> [--ns play] [--direction toClient|toServer] [--format json|toon]
chunks [--kind all|packet|type] [--filter text] [--max-chars N] [--format json|toon]
stats [--format json|toon]
versions [--format json|toon] (protocol number -> Minecraft releases)
order [--format json|toon] (type build order, simple -> complex)
graph [--ns play] [--direction toClient] [--include-types false] [--format json|toon]
```
Expand Down Expand Up @@ -124,6 +125,7 @@ get_protocol_usage
get_protocol_users
get_protocol_dependencies
get_protocol_stats
get_protocol_versions
get_protocol_graph
```

Expand All @@ -135,6 +137,7 @@ get_protocol_graph
GET /api/packets
GET /api/packets/{ns}/{dir}
GET /api/stats
GET /api/versions
GET /api/types
GET /api/native-types
GET /api/types-by-kind
Expand Down
2 changes: 1 addition & 1 deletion facts/minecraft-data
Submodule minecraft-data updated 326 files
5 changes: 5 additions & 0 deletions facts/src/McProtoFacts.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ static async Task<int> RunAsync(string[] args)
Write(query.GetStats(), format);
return Ok;

case "versions":
Write(query.GetVersions(), format);
return Ok;

case "order":
case "build-order":
Write(query.GetBuildOrder(), format);
Expand Down Expand Up @@ -265,6 +269,7 @@ usage [--top N] [--kind packet|type|shape|native] [--format json|toon]
ids --pv <N> [--ns play] [--direction toClient|toServer] [--format json|toon]
chunks [--kind all|packet|type] [--filter text] [--max-chars N] [--format json|toon]
stats [--format json|toon]
versions [--format json|toon] (protocol number -> Minecraft releases)
order [--format json|toon] (type build order, simple -> complex)
graph [--ns play] [--direction toClient] [--include-types false] [--format json|toon]

Expand Down
5 changes: 5 additions & 0 deletions facts/src/McProtoFacts.McpStdio/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public static string GetProtocolDependencies(ProtocolUsageQueries usage, string
public static string GetProtocolStats(ProtocolQueryService query, string format = "json") =>
Serialize(query.GetStats(), format);

[McpServerTool(Name = "get_protocol_versions")]
[Description("Returns loaded protocol numbers with the Minecraft releases that speak them.")]
public static string GetProtocolVersions(ProtocolQueryService query, string format = "toon") =>
Serialize(query.GetVersions(), format);

[McpServerTool(Name = "get_protocol_graph")]
[Description("Returns protocol graph nodes/edges for packets, named types, native types, and protodef shapes.")]
public static string GetProtocolGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace McProtoFacts.Protocol.Loading;

public sealed record ProtocolDataOptions(int FromProtocol = 735, int ToProtocol = 772);
public sealed record ProtocolDataOptions(int FromProtocol = 735, int ToProtocol = 776);

public static class ProtocolDataLoader
{
Expand Down
26 changes: 26 additions & 0 deletions facts/src/McProtoFacts.Protocol/Queries/ProtocolQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ public PacketIdsResult GetPacketIds(string id)
.ToArray());
}

/// <summary>Loaded protocol numbers with the Minecraft releases that speak them.</summary>
public ProtocolVersionsResult GetVersions()
{
var entries = _repository.GetVersions()
.OrderBy(entry => entry.Protocol)
.Select(entry => new ProtocolVersionEntryResult(
entry.Protocol,
entry.Versions.ToArray(),
string.Join(", ", entry.Versions)))
.ToArray();

var supported = _repository.GetSupportedProtocols();
return new ProtocolVersionsResult(entries.Length, supported.From, supported.To, entries);
}

public PacketIdMapResult GetPacketIdMap(int protocolVersion, string? ns = null, string? direction = null)
{
var supported = _repository.GetSupportedProtocols();
Expand Down Expand Up @@ -428,6 +443,17 @@ public sealed record PacketIdsResult(
string Name,
IReadOnlyList<PacketIdRangeEntry> Ranges);

public sealed record ProtocolVersionEntryResult(
int Protocol,
IReadOnlyList<string> Versions,
string Display);

public sealed record ProtocolVersionsResult(
int Count,
int From,
int To,
IReadOnlyList<ProtocolVersionEntryResult> Protocols);

public sealed record PacketIdMapEntry(string Id, string Hex, int Dec);

public sealed record PacketIdMapResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

namespace McProtoFacts.Protocol.Repository;

/// <summary>One protocol number with the Minecraft releases that speak it.</summary>
public sealed record ProtocolVersionEntry(int Protocol, IReadOnlyList<string> Versions);

public interface IProtocolRepository
{
ProtocolRange GetSupportedProtocols();

/// <summary>Loaded protocol numbers with their Minecraft release names, ascending.</summary>
IReadOnlyList<ProtocolVersionEntry> GetVersions();

IEnumerable<string> GetTypes();
IEnumerable<string> GetNativeTypes();
Dictionary<string, Dictionary<string, PacketDefinition>> GetPackets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ public ProtocolRange GetSupportedProtocols()
return _range;
}

public IReadOnlyList<ProtocolVersionEntry> GetVersions()
{
return _map.Protocols
.Select(kv => new ProtocolVersionEntry(kv.Key, kv.Value.MinecraftVersions.ToArray()))
.ToArray();
}

public IEnumerable<string> GetTypes()
{
return
Expand Down
18 changes: 18 additions & 0 deletions facts/src/McpServer/Endpoints/PacketEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ public static void MapPacketApi(this WebApplication app)
});
});

app.MapGet("/api/versions", (ProtocolQueryService query) =>
{
var versions = query.GetVersions();

return Results.Ok(new
{
count = versions.Count,
from = versions.From,
to = versions.To,
protocols = versions.Protocols.Select(entry => new
{
protocol = entry.Protocol,
versions = entry.Versions,
display = entry.Display
}).ToArray()
});
});

app.MapGet("/api/types", (ProtocolQueryService query) =>
{
return Results.Ok(query.GetTypes());
Expand Down
2 changes: 1 addition & 1 deletion facts/src/McpServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using McProtoFacts.Protocol.Loading;

var start = 735;
var end = 772;
var end = 776;

Console.WriteLine($"[McpServer] Loading protocols {start}-{end}...");
var repository = await ProtocolDataLoader.LoadRepositoryAsync(new ProtocolDataOptions(start, end));
Expand Down
Loading
Loading