Skip to content

Commit f3ef76a

Browse files
committed
ci: debug issue
1 parent 8a48803 commit f3ef76a

File tree

3 files changed

+150
-2
lines changed

3 files changed

+150
-2
lines changed

src/Server/McpServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Laravel\Mcp\Console\Commands\MakeToolCommand;
1515
use Laravel\Mcp\Console\Commands\StartCommand;
1616
use Laravel\Mcp\Request;
17+
use Laravel\Mcp\Server\Support\LoggingManager;
1718
use Laravel\Mcp\Server\Support\SessionStoreManager;
1819

1920
class McpServiceProvider extends ServiceProvider
@@ -105,6 +106,10 @@ protected function registerSessionBindings(): void
105106
$sessionId
106107
);
107108
});
109+
110+
$this->app->bind(LoggingManager::class, fn ($app): LoggingManager => new LoggingManager(
111+
$app->make(SessionStoreManager::class)
112+
));
108113
}
109114

110115
protected function registerCommands(): void

src/Server/Methods/Concerns/InteractsWithResponses.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Laravel\Mcp\Server\Contracts\Errable;
1515
use Laravel\Mcp\Server\Exceptions\JsonRpcException;
1616
use Laravel\Mcp\Server\Support\LoggingManager;
17-
use Laravel\Mcp\Server\Support\SessionStoreManager;
1817
use Laravel\Mcp\Server\Transport\JsonRpcRequest;
1918
use Laravel\Mcp\Server\Transport\JsonRpcResponse;
2019

@@ -57,7 +56,7 @@ protected function toJsonRpcStreamedResponse(JsonRpcRequest $request, iterable $
5756
$content = $response->content();
5857

5958
if ($content instanceof LogNotification) {
60-
$loggingManager ??= new LoggingManager(app(SessionStoreManager::class));
59+
$loggingManager ??= app(LoggingManager::class);
6160

6261
if (! $loggingManager->shouldLog($content->level())) {
6362
continue;
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Laravel\Mcp\Server\Support\LoggingManager;
6+
use Laravel\Mcp\Server\Support\SessionStoreManager;
7+
8+
it('resolves LoggingManager from container without producing output', function (): void {
9+
// Capture any output that might be produced during resolution
10+
ob_start();
11+
12+
// Capture any errors/warnings
13+
$errors = [];
14+
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) use (&$errors): bool {
15+
$errors[] = [
16+
'type' => $errno,
17+
'message' => $errstr,
18+
'file' => $errfile,
19+
'line' => $errline,
20+
];
21+
return true; // Don't execute PHP's internal error handler
22+
});
23+
24+
try {
25+
// First, bind LoggingManager in the container (simulating what we want to test)
26+
app()->bind(LoggingManager::class, fn ($app): LoggingManager => new LoggingManager(
27+
$app->make(SessionStoreManager::class)
28+
));
29+
30+
// Now resolve it
31+
$manager = app(LoggingManager::class);
32+
33+
expect($manager)->toBeInstanceOf(LoggingManager::class);
34+
} finally {
35+
restore_error_handler();
36+
}
37+
38+
$output = ob_get_clean();
39+
40+
// If there was any output, fail with diagnostic info
41+
if ($output !== '' && $output !== false) {
42+
$hexDump = bin2hex(substr($output, 0, 200));
43+
throw new \RuntimeException(sprintf(
44+
"Unexpected output during LoggingManager resolution!\nLength: %d bytes\nContent: %s\nHex: %s",
45+
strlen($output),
46+
substr($output, 0, 500),
47+
$hexDump
48+
));
49+
}
50+
51+
// If there were any errors/warnings, fail with diagnostic info
52+
if (count($errors) > 0) {
53+
throw new \RuntimeException(sprintf(
54+
"Errors/warnings during LoggingManager resolution:\n%s",
55+
json_encode($errors, JSON_PRETTY_PRINT)
56+
));
57+
}
58+
59+
expect($output)->toBe('');
60+
expect($errors)->toBe([]);
61+
});
62+
63+
it('resolves SessionStoreManager from container without producing output', function (): void {
64+
ob_start();
65+
66+
$errors = [];
67+
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) use (&$errors): bool {
68+
$errors[] = [
69+
'type' => $errno,
70+
'message' => $errstr,
71+
'file' => $errfile,
72+
'line' => $errline,
73+
];
74+
return true;
75+
});
76+
77+
try {
78+
$manager = app(SessionStoreManager::class);
79+
expect($manager)->toBeInstanceOf(SessionStoreManager::class);
80+
} finally {
81+
restore_error_handler();
82+
}
83+
84+
$output = ob_get_clean();
85+
86+
if ($output !== '' && $output !== false) {
87+
throw new \RuntimeException(sprintf(
88+
"Unexpected output during SessionStoreManager resolution!\nLength: %d bytes\nContent: %s",
89+
strlen($output),
90+
substr($output, 0, 500)
91+
));
92+
}
93+
94+
if (count($errors) > 0) {
95+
throw new \RuntimeException(sprintf(
96+
"Errors/warnings during SessionStoreManager resolution:\n%s",
97+
json_encode($errors, JSON_PRETTY_PRINT)
98+
));
99+
}
100+
101+
expect($output)->toBe('');
102+
});
103+
104+
it('resolves Cache repository without producing output', function (): void {
105+
ob_start();
106+
107+
$errors = [];
108+
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) use (&$errors): bool {
109+
$errors[] = [
110+
'type' => $errno,
111+
'message' => $errstr,
112+
'file' => $errfile,
113+
'line' => $errline,
114+
];
115+
return true;
116+
});
117+
118+
try {
119+
$cache = app(\Illuminate\Contracts\Cache\Repository::class);
120+
expect($cache)->toBeInstanceOf(\Illuminate\Contracts\Cache\Repository::class);
121+
} finally {
122+
restore_error_handler();
123+
}
124+
125+
$output = ob_get_clean();
126+
127+
if ($output !== '' && $output !== false) {
128+
throw new \RuntimeException(sprintf(
129+
"Unexpected output during Cache resolution!\nLength: %d bytes\nContent: %s",
130+
strlen($output),
131+
substr($output, 0, 500)
132+
));
133+
}
134+
135+
if (count($errors) > 0) {
136+
throw new \RuntimeException(sprintf(
137+
"Errors/warnings during Cache resolution:\n%s",
138+
json_encode($errors, JSON_PRETTY_PRINT)
139+
));
140+
}
141+
142+
expect($output)->toBe('');
143+
});
144+

0 commit comments

Comments
 (0)