@@ -4,21 +4,28 @@ namespace McpDotNet.Tests;
4
4
5
5
public class EverythingSseServerFixture : IAsyncDisposable
6
6
{
7
- private Process ? _process ;
7
+ private int _port ;
8
+ private string _containerName ;
9
+
10
+ public EverythingSseServerFixture ( int port )
11
+ {
12
+ _port = port ;
13
+ _containerName = $ "mcp-everything-server-{ _port } ";
14
+ }
8
15
9
16
public async Task StartAsync ( )
10
17
{
11
18
var processStartInfo = new ProcessStartInfo
12
19
{
13
20
FileName = "docker" ,
14
- Arguments = "run -p 3001 :3001 --rm tzolov/mcp-everything-server:v1" ,
21
+ Arguments = $ "run -p { _port } :3001 --name { _containerName } --rm tzolov/mcp-everything-server:v1",
15
22
RedirectStandardInput = true ,
16
23
RedirectStandardOutput = true ,
17
24
RedirectStandardError = true ,
18
25
UseShellExecute = false ,
19
26
} ;
20
27
21
- _process = Process . Start ( processStartInfo )
28
+ _ = Process . Start ( processStartInfo )
22
29
?? throw new InvalidOperationException ( $ "Could not start process for { processStartInfo . FileName } with '{ processStartInfo . Arguments } '.") ;
23
30
24
31
// Wait for the server to start
@@ -28,34 +35,18 @@ public async ValueTask DisposeAsync()
28
35
{
29
36
try
30
37
{
31
- // Find the container ID
32
- var psInfo = new ProcessStartInfo
38
+
39
+ // Stop the container
40
+ var stopInfo = new ProcessStartInfo
33
41
{
34
42
FileName = "docker" ,
35
- Arguments = "ps -q --filter ancestor=tzolov/mcp-everything-server:v1" ,
36
- RedirectStandardOutput = true ,
43
+ Arguments = $ "stop { _containerName } ",
37
44
UseShellExecute = false
38
45
} ;
39
46
40
- using var psProcess = Process . Start ( psInfo )
41
- ?? throw new InvalidOperationException ( $ "Could not start process for { psInfo . FileName } with '{ psInfo . Arguments } '.") ;
42
- string containerId = await psProcess . StandardOutput . ReadToEndAsync ( ) ;
43
- containerId = containerId . Trim ( ) ;
44
-
45
- if ( ! string . IsNullOrEmpty ( containerId ) )
46
- {
47
- // Stop the container
48
- var stopInfo = new ProcessStartInfo
49
- {
50
- FileName = "docker" ,
51
- Arguments = $ "stop { containerId } ",
52
- UseShellExecute = false
53
- } ;
54
-
55
- using var stopProcess = Process . Start ( stopInfo )
56
- ?? throw new InvalidOperationException ( $ "Could not start process for { stopInfo . FileName } with '{ stopInfo . Arguments } '.") ;
57
- await stopProcess . WaitForExitAsync ( ) ;
58
- }
47
+ using var stopProcess = Process . Start ( stopInfo )
48
+ ?? throw new InvalidOperationException ( $ "Could not stop process for { stopInfo . FileName } with '{ stopInfo . Arguments } '.") ;
49
+ await stopProcess . WaitForExitAsync ( ) ;
59
50
}
60
51
catch ( Exception ex )
61
52
{
0 commit comments