Add research page with MCP write tools, longer hold for repeat offenders and svn/hg decoys
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a25072e6fb
commit
e88dc415f9
48 files changed
+1983
-57
No files matched your search
@@ -62,7 +62,7 @@ public sealed class McpEndpointTests : IDisposable
|
||||
var tools = await ReadAsync(await client.SendAsync(Rpc("tools/list", token)));
|
||||
var listed = tools.GetProperty("result").GetProperty("tools").EnumerateArray().ToList();
|
||||
listed.Select(t => t.GetProperty("name").GetString())
|
||||
.ShouldBe(["get_stats", "list_catches", "longest_catches", "lookup_ip", "top"], ignoreOrder: true);
|
||||
.ShouldBe(["get_stats", "list_catches", "list_entries", "list_ideas", "longest_catches", "lookup_ip", "top"], ignoreOrder: true);
|
||||
listed.ShouldAllBe(t => t.GetProperty("annotations").GetProperty("readOnlyHint").GetBoolean());
|
||||
listed.Where(t => !t.TryGetProperty("outputSchema", out var schema) || schema.ValueKind != JsonValueKind.Object).ShouldBeEmpty();
|
||||
|
||||
@@ -87,7 +87,11 @@ public sealed class McpEndpointTests : IDisposable
|
||||
{ "top", """{"dimension":"user_agents","period":"all"}""" },
|
||||
{ "longest_catches", """{"period":"all"}""" },
|
||||
{ "lookup_ip", """{"ip":"203.0.113.9"}""" },
|
||||
{ "lookup_ip", """{"ip":"192.0.2.1"}""" }
|
||||
{ "lookup_ip", """{"ip":"192.0.2.1"}""" },
|
||||
{ "list_entries", """{}""" },
|
||||
{ "list_entries", """{"kind":"experiment","strategy":"git-drip","limit":5}""" },
|
||||
{ "list_ideas", """{}""" },
|
||||
{ "list_ideas", """{"status":"in_progress"}""" }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
@@ -134,6 +138,41 @@ public sealed class McpEndpointTests : IDisposable
|
||||
result.GetProperty("content")[0].GetProperty("text").GetString().ShouldNotBeNull().ShouldContain(expected, Case.Sensitive);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Write_tools_are_only_offered_to_and_usable_by_tokens_with_write_permission()
|
||||
{
|
||||
using var client = _factory.CreateClient();
|
||||
var tokens = _factory.Services.GetRequiredService<McpTokenService>();
|
||||
var readOnly = await tokens.CreateAsync("read");
|
||||
var writer = await tokens.CreateAsync("write", canWrite: true);
|
||||
|
||||
var writerTools = (await ReadAsync(await client.SendAsync(Rpc("tools/list", writer)))).GetProperty("result").GetProperty("tools")
|
||||
.EnumerateArray().Select(t => t.GetProperty("name").GetString()).ToList();
|
||||
writerTools.ShouldBe(
|
||||
["get_stats", "list_catches", "list_entries", "list_ideas", "longest_catches", "lookup_ip", "top", "create_entry", "update_entry", "create_idea", "update_idea", "set_idea_status"],
|
||||
ignoreOrder: true);
|
||||
|
||||
var denied = (await ReadAsync(await client.SendAsync(Rpc("tools/call", readOnly, new
|
||||
{
|
||||
name = "create_entry",
|
||||
arguments = new { title = "Test", kind = "observation", text = "Text" }
|
||||
})))).GetProperty("result");
|
||||
denied.GetProperty("isError").GetBoolean().ShouldBeTrue();
|
||||
denied.GetProperty("content")[0].GetProperty("text").GetString().ShouldNotBeNull().ShouldContain("write permission");
|
||||
|
||||
var created = (await ReadAsync(await client.SendAsync(Rpc("tools/call", writer, new
|
||||
{
|
||||
name = "create_entry",
|
||||
arguments = new { title = "Test", kind = "observation", text = "**Text**", strategies = new[] { "git-drip" } }
|
||||
})))).GetProperty("result");
|
||||
(created.TryGetProperty("isError", out var isError) && isError.GetBoolean()).ShouldBeFalse(created.ToString());
|
||||
created.GetProperty("structuredContent").GetProperty("kind").GetString().ShouldBe("observation");
|
||||
|
||||
var listed = (await ReadAsync(await client.SendAsync(Rpc("tools/call", readOnly, new { name = "list_entries", arguments = new { } }))))
|
||||
.GetProperty("result").GetProperty("structuredContent");
|
||||
listed.GetProperty("count").GetInt32().ShouldBe(1);
|
||||
}
|
||||
|
||||
private static async Task<Dictionary<string, JsonElement>> OutputSchemasAsync(HttpClient client, string token)
|
||||
{
|
||||
var tools = await ReadAsync(await client.SendAsync(Rpc("tools/list", token)));
|
||||
|
||||
Reference in new issue
Block a user