feat: alignment on missing MCP ressources
This commit is contained in:
@@ -13,7 +13,7 @@ defmodule BDS.MCPServerTest do
|
||||
{:ok, project} = BDS.Projects.create_project(%{name: "MCP Server", data_path: temp_dir})
|
||||
{:ok, _active} = BDS.Projects.set_active_project(project.id)
|
||||
|
||||
%{project: project}
|
||||
%{project: project, temp_dir: temp_dir}
|
||||
end
|
||||
|
||||
test "HTTP MCP server binds localhost, answers initialize, and exposes tool capabilities" do
|
||||
@@ -94,4 +94,50 @@ defmodule BDS.MCPServerTest do
|
||||
|
||||
assert :ok = BDS.MCP.Server.stop()
|
||||
end
|
||||
|
||||
test "HTTP MCP server returns media image resources as blob contents", %{
|
||||
project: project,
|
||||
temp_dir: temp_dir
|
||||
} do
|
||||
:inets.start()
|
||||
|
||||
source_path = Path.join(temp_dir, "server-image.png")
|
||||
image_bytes = <<137, 80, 78, 71, 13, 10, 26, 10, "server-bytes">>
|
||||
File.write!(source_path, image_bytes)
|
||||
|
||||
assert {:ok, media} =
|
||||
BDS.Media.import_media(%{
|
||||
project_id: project.id,
|
||||
source_path: source_path,
|
||||
title: "Server Image"
|
||||
})
|
||||
|
||||
assert {:ok, server} = BDS.MCP.Server.start(0)
|
||||
|
||||
read_body =
|
||||
Jason.encode!(%{
|
||||
jsonrpc: "2.0",
|
||||
id: 3,
|
||||
method: "resources/read",
|
||||
params: %{uri: "bds://media/#{media.id}/image"}
|
||||
})
|
||||
|
||||
assert {:ok, {{_version, 200, _reason}, _headers, body}} =
|
||||
:httpc.request(
|
||||
:post,
|
||||
{to_charlist("http://127.0.0.1:#{server.port}/mcp"),
|
||||
[{~c"content-type", ~c"application/json"}], ~c"application/json", read_body},
|
||||
[],
|
||||
body_format: :binary
|
||||
)
|
||||
|
||||
decoded = Jason.decode!(body)
|
||||
assert [content] = decoded["result"]["contents"]
|
||||
assert content["uri"] == "bds://media/#{media.id}/image"
|
||||
assert content["mimeType"] == "image/png"
|
||||
assert Base.decode64!(content["blob"]) == image_bytes
|
||||
refute Map.has_key?(content, "text")
|
||||
|
||||
assert :ok = BDS.MCP.Server.stop()
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user