|
2 | 2 |
|
3 | 3 | use OPGG\LaravelMcpServer\Server\MCPServer; |
4 | 4 | use OPGG\LaravelMcpServer\Services\ToolService\ToolRepository; |
| 5 | +use OPGG\LaravelMcpServer\Tests\Fixtures\Tools\AutoStructuredArrayTool; |
| 6 | +use OPGG\LaravelMcpServer\Tests\Fixtures\Tools\LegacyArrayTool; |
5 | 7 | use OPGG\LaravelMcpServer\Tests\Fixtures\Tools\TabularChampionsTool; |
6 | 8 |
|
7 | 9 | test('streamable http GET returns method not allowed', function () { |
|
43 | 45 | ->toContain('HelloWorld `Tester` developer'); |
44 | 46 | }); |
45 | 47 |
|
| 48 | +test('legacy array tool keeps payload in content by default', function () { |
| 49 | + $originalTools = config('mcp-server.tools'); |
| 50 | + $tools = $originalTools; |
| 51 | + $tools[] = LegacyArrayTool::class; |
| 52 | + config()->set('mcp-server.tools', array_values(array_unique($tools))); |
| 53 | + |
| 54 | + app()->forgetInstance(ToolRepository::class); |
| 55 | + app()->forgetInstance(MCPServer::class); |
| 56 | + |
| 57 | + $payload = [ |
| 58 | + 'jsonrpc' => '2.0', |
| 59 | + 'id' => 12, |
| 60 | + 'method' => 'tools/call', |
| 61 | + 'params' => [ |
| 62 | + 'name' => 'legacy-array-tool', |
| 63 | + 'arguments' => [ |
| 64 | + 'foo' => 'bar', |
| 65 | + ], |
| 66 | + ], |
| 67 | + ]; |
| 68 | + |
| 69 | + $response = $this->postJson('/mcp', $payload); |
| 70 | + |
| 71 | + $response->assertStatus(200); |
| 72 | + $data = $response->json('result'); |
| 73 | + |
| 74 | + expect($data)->toHaveKey('content'); |
| 75 | + expect($data)->not->toHaveKey('structuredContent'); |
| 76 | + expect($data['content'][0]['type'])->toBe('text'); |
| 77 | + |
| 78 | + $decoded = json_decode($data['content'][0]['text'], true, 512, JSON_THROW_ON_ERROR); |
| 79 | + expect($decoded)->toBe([ |
| 80 | + 'status' => 'ok', |
| 81 | + 'echo' => [ |
| 82 | + 'foo' => 'bar', |
| 83 | + ], |
| 84 | + ]); |
| 85 | + |
| 86 | + config()->set('mcp-server.tools', $originalTools); |
| 87 | + app()->forgetInstance(ToolRepository::class); |
| 88 | + app()->forgetInstance(MCPServer::class); |
| 89 | +}); |
| 90 | + |
| 91 | +test('tools can opt into automatic structuredContent detection', function () { |
| 92 | + $originalTools = config('mcp-server.tools'); |
| 93 | + $tools = $originalTools; |
| 94 | + $tools[] = AutoStructuredArrayTool::class; |
| 95 | + config()->set('mcp-server.tools', array_values(array_unique($tools))); |
| 96 | + |
| 97 | + app()->forgetInstance(ToolRepository::class); |
| 98 | + app()->forgetInstance(MCPServer::class); |
| 99 | + |
| 100 | + $payload = [ |
| 101 | + 'jsonrpc' => '2.0', |
| 102 | + 'id' => 13, |
| 103 | + 'method' => 'tools/call', |
| 104 | + 'params' => [ |
| 105 | + 'name' => 'auto-structured-array-tool', |
| 106 | + 'arguments' => [ |
| 107 | + 'alpha' => 'beta', |
| 108 | + ], |
| 109 | + ], |
| 110 | + ]; |
| 111 | + |
| 112 | + $response = $this->postJson('/mcp', $payload); |
| 113 | + |
| 114 | + $response->assertStatus(200); |
| 115 | + $data = $response->json('result'); |
| 116 | + |
| 117 | + expect($data)->not->toHaveKey('content'); |
| 118 | + expect($data)->toHaveKey('structuredContent'); |
| 119 | + expect($data['structuredContent'])->toBe([ |
| 120 | + 'status' => 'ok', |
| 121 | + 'echo' => [ |
| 122 | + 'alpha' => 'beta', |
| 123 | + ], |
| 124 | + ]); |
| 125 | + |
| 126 | + config()->set('mcp-server.tools', $originalTools); |
| 127 | + app()->forgetInstance(ToolRepository::class); |
| 128 | + app()->forgetInstance(MCPServer::class); |
| 129 | +}); |
| 130 | + |
46 | 131 | test('notification returns HTTP 202 with no body', function () { |
47 | 132 | $payload = [ |
48 | 133 | 'jsonrpc' => '2.0', |
|
0 commit comments