|
1 | 1 | // Plugin MCP serve tests cover serving plugin tools over MCP. |
| 2 | +import { Client } from "@modelcontextprotocol/sdk/client/index.js"; |
| 3 | +import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js"; |
2 | 4 | import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js"; |
3 | 5 | import { afterEach, describe, expect, it, vi } from "vitest"; |
4 | 6 | import { |
@@ -210,6 +212,48 @@ describe("plugin tools MCP server", () => { |
210 | 212 | expect(() => CallToolResultSchema.parse(result)).not.toThrow(); |
211 | 213 | }); |
212 | 214 |
|
| 215 | + it("delivers source-shaped images through a real MCP client", async () => { |
| 216 | + const execute = vi.fn().mockResolvedValue({ |
| 217 | + content: [ |
| 218 | + { type: "text", text: "browser screenshot" }, |
| 219 | + { |
| 220 | + type: "image", |
| 221 | + source: { |
| 222 | + type: "base64", |
| 223 | + media_type: "image/png", |
| 224 | + data: "iVBORw0KGgo=", |
| 225 | + }, |
| 226 | + }, |
| 227 | + ], |
| 228 | + }); |
| 229 | + const tool = { |
| 230 | + name: "browser_screenshot", |
| 231 | + description: "Capture a browser screenshot", |
| 232 | + parameters: { type: "object", properties: {} }, |
| 233 | + execute, |
| 234 | + } as unknown as AnyAgentTool; |
| 235 | + const { createToolsMcpServer } = |
| 236 | + await vi.importActual<typeof import("./tools-stdio-server.js")>("./tools-stdio-server.js"); |
| 237 | + const server = createToolsMcpServer({ name: "plugin-tools-image-test", tools: [tool] }); |
| 238 | + const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); |
| 239 | + const client = new Client( |
| 240 | + { name: "plugin-tools-image-test-client", version: "0.0.0" }, |
| 241 | + { capabilities: {} }, |
| 242 | + ); |
| 243 | + |
| 244 | + await Promise.all([server.connect(serverTransport), client.connect(clientTransport)]); |
| 245 | + try { |
| 246 | + const result = await client.callTool({ name: "browser_screenshot", arguments: {} }); |
| 247 | + expect(result.content).toEqual([ |
| 248 | + { type: "text", text: "browser screenshot" }, |
| 249 | + { type: "image", data: "iVBORw0KGgo=", mimeType: "image/png" }, |
| 250 | + ]); |
| 251 | + } finally { |
| 252 | + await client.close(); |
| 253 | + await server.close(); |
| 254 | + } |
| 255 | + }); |
| 256 | + |
213 | 257 | it("serializes plugin tool results that do not use the MCP content envelope", async () => { |
214 | 258 | const execute = vi.fn().mockResolvedValue({ |
215 | 259 | provider: "kitchen-sink-search", |
|
0 commit comments