Skip to content

Commit f05ea6c

Browse files
authored
Misc cleanups (#75)
* Remove use of globalVariables * Remove todo comment * Reap any existing session socket when starting server
1 parent 0b9aeee commit f05ea6c

File tree

4 files changed

+4
-11
lines changed

4 files changed

+4
-11
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export(mcp_server)
44
export(mcp_session)
55
export(mcp_tools)
66
import(rlang)
7+
importFrom(stats,setNames)

R/mcptools-package.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
## usethis namespace: start
66
#' @import rlang
7+
#' @importFrom stats setNames
78
## usethis namespace: end
89
NULL
910

10-
utils::globalVariables(c("packageVersion", "setNames"))
11-
1211
.onLoad <- function(libname, pkgname) {
1312
the$socket_url <- switch(
1413
Sys.info()[["sysname"]],

R/server.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@
109109
#' @name server
110110
#' @export
111111
mcp_server <- function(tools = NULL, ..., session_tools = TRUE) {
112-
# TODO: should this actually be a check for being called within Rscript or not?
112+
113113
check_not_interactive()
114+
nanonext::reap(the$session_socket) # in case session was started in .Rprofile
114115
the$sessions_enabled <- isTRUE(session_tools)
115116
set_server_tools(tools, session_tools = the$sessions_enabled)
116117

R/session.R

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
#' @rdname server
22
#' @export
33
mcp_session <- function() {
4-
# HACK: If a session is already available from another session via `.Rprofile`,
5-
# `mcp_session()` will be called again when the client runs the command
6-
# Rscript -e "mcptools::mcp_server()" and the existing session connection
7-
# will be wiped. Returning early in this case allows for the desired R
8-
# session to be running already before the client initiates the server.
9-
if (!interactive()) {
10-
return(invisible())
11-
}
124

135
the$session_socket <- nanonext::socket("poly")
146
i <- 1L

0 commit comments

Comments
 (0)