Skip to content

Commit 830d7b6

Browse files
committed
Auto-generate unique socket path in /tmp
- --socket flag now creates unique socket with timestamp and PID - Socket path is printed to stdout for clients to use - Automatic cleanup on server exit - Add Dates dependency for timestamp generation - Update documentation and test script
1 parent 40e4064 commit 830d7b6

File tree

5 files changed

+52
-26
lines changed

5 files changed

+52
-26
lines changed

Manifest.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
julia_version = "1.13.0-DEV"
44
manifest_format = "2.0"
5-
project_hash = "b80e681f4ebf05f6eba3c868de5fc47aa2cc335c"
5+
project_hash = "69b4d7cbdacd0be0af9965d9032956923b35b619"
66

77
[[deps.ClaudeMCPTools]]
8-
deps = ["JSON"]
9-
git-tree-sha1 = "9b896351226ba85681ccc8769549eab32812337e"
8+
deps = ["JSON", "Sockets"]
9+
git-tree-sha1 = "9081fe72fb82c35e8a7aa59d346293b9367218a9"
1010
repo-rev = "master"
1111
repo-url = "git@github.com:JuliaComputing/ClaudeMCPTools.jl.git"
1212
uuid = "b9bb1685-6a70-41d7-9793-2f9fb633d966"
@@ -24,7 +24,7 @@ uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
2424
version = "0.21.4"
2525

2626
[[deps.LLMBenchMCPServer]]
27-
deps = ["ClaudeMCPTools", "JSON", "LLMBenchSimple"]
27+
deps = ["ClaudeMCPTools", "Dates", "JSON", "LLMBenchSimple"]
2828
path = "."
2929
uuid = "78754875-2f68-464a-ac60-858ac662827f"
3030
version = "0.1.0"
@@ -72,6 +72,10 @@ version = "1.11.0"
7272
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
7373
version = "0.7.0"
7474

75+
[[deps.Sockets]]
76+
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
77+
version = "1.11.0"
78+
7579
[[deps.TOML]]
7680
deps = ["Dates"]
7781
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ authors = ["JuliaComputing"]
55

66
[deps]
77
ClaudeMCPTools = "b9bb1685-6a70-41d7-9793-2f9fb633d966"
8+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
89
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
910
LLMBenchSimple = "a7b3c4d5-e6f7-8901-2345-678901234567"
1011

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ julia --project -e 'using LLMBenchMCPServer; LLMBenchMCPServer.main()' -- MyBenc
6565

6666
Options:
6767
- `--workdir PATH`: Set the working directory (default: current directory)
68-
- `--socket PATH`: Run server on Unix domain socket instead of stdio
68+
- `--socket`: Run server on Unix domain socket (creates unique socket in /tmp)
6969
- `--no-basic-tools`: Disable basic tools (bash, str_replace_editor)
7070
- `--verbose`: Enable verbose output
7171
- `--help, -h`: Show help message
@@ -75,11 +75,18 @@ Options:
7575
Run the server on a Unix socket for integration with other tools:
7676

7777
```bash
78-
# Start server on Unix socket
79-
julia --project -m LLMBenchMCPServer MyBenchmark --socket /tmp/mcp.sock
80-
81-
# The server will listen on the socket for MCP protocol connections
82-
# Multiple clients can connect simultaneously
78+
# Start server on Unix socket (automatically creates unique socket in /tmp)
79+
julia --project -m LLMBenchMCPServer MyBenchmark --socket
80+
81+
# Output will show the socket path:
82+
# Socket path: /tmp/mcp_MyBenchmark_20240820_143022_12345.sock
83+
84+
# The server will:
85+
# - Create a unique socket file in /tmp with timestamp and PID
86+
# - Print the socket path for clients to connect to
87+
# - Listen for MCP protocol connections
88+
# - Support multiple concurrent client connections
89+
# - Automatically clean up the socket file on exit
8390
```
8491

8592
#### Programmatic Usage

src/LLMBenchMCPServer.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module LLMBenchMCPServer
22

33
using ClaudeMCPTools
44
using JSON
5+
using Dates
56

67
export LLMBenchServer, SetupProblemTool, GradeProblemTool
78
export main

src/server.jl

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function @main(args)
5959
6060
Options:
6161
--workdir PATH Working directory (default: current directory)
62-
--socket PATH Run server on Unix domain socket instead of stdio
62+
--socket Run server on Unix domain socket (creates socket in /tmp)
6363
--no-basic-tools Disable basic tools (bash, str_replace_editor)
6464
--verbose Enable verbose output
6565
--help, -h Show this help message
@@ -73,15 +73,15 @@ function @main(args)
7373
7474
Examples:
7575
julia --project -m LLMBenchMCPServer MyBenchmark
76-
julia --project -m LLMBenchMCPServer MyBenchmark --socket /tmp/mcp.sock
76+
julia --project -m LLMBenchMCPServer MyBenchmark --socket
7777
""")
7878
return 0
7979
end
8080

8181
# Parse arguments
8282
module_name = args[1]
8383
working_dir = pwd()
84-
socket_path = nothing
84+
use_socket = false
8585
include_basic_tools = true
8686
verbose = false
8787

@@ -90,9 +90,9 @@ function @main(args)
9090
if args[i] == "--workdir" && i + 1 <= length(args)
9191
working_dir = args[i + 1]
9292
i += 2
93-
elseif args[i] == "--socket" && i + 1 <= length(args)
94-
socket_path = args[i + 1]
95-
i += 2
93+
elseif args[i] == "--socket"
94+
use_socket = true
95+
i += 1
9696
elseif args[i] == "--no-basic-tools"
9797
include_basic_tools = false
9898
i += 1
@@ -152,14 +152,29 @@ function @main(args)
152152
println("Starting MCP server for $module_name")
153153
println("Working directory: $working_dir")
154154
println("Tools registered: $(keys(server.tools))")
155-
if socket_path !== nothing
156-
println("Socket path: $socket_path")
157-
end
158155
end
159156

160157
# Run the server in appropriate mode
161-
if socket_path !== nothing
162-
ClaudeMCPTools.run_unix_socket_server(server, socket_path, verbose=verbose)
158+
if use_socket
159+
# Generate a unique socket path in /tmp
160+
timestamp = Dates.format(Dates.now(), "yyyymmdd_HHMMSS")
161+
pid = getpid()
162+
socket_path = "/tmp/mcp_$(module_name)_$(timestamp)_$(pid).sock"
163+
164+
println("Socket path: $socket_path")
165+
166+
# Run server and ensure cleanup on exit
167+
try
168+
ClaudeMCPTools.run_unix_socket_server(server, socket_path, verbose=verbose, cleanup=true)
169+
finally
170+
# Ensure socket is cleaned up even on error
171+
if isfile(socket_path)
172+
rm(socket_path)
173+
if verbose
174+
println("Cleaned up socket: $socket_path")
175+
end
176+
end
177+
end
163178
else
164179
ClaudeMCPTools.run_stdio_server(server, verbose=verbose)
165180
end
@@ -172,8 +187,6 @@ function @main(args)
172187
return 0
173188
end
174189

175-
# Compatibility function for direct module usage
176-
function main(args=ARGS)
177-
# Delegate to @main function
178-
(@main)(args)
179-
end
190+
# Export a regular main function for programmatic use
191+
const main = @main
192+
export main

0 commit comments

Comments
 (0)