Skip to content

fix(mcp): Allow several tool groups in btw_mcp_server() - #221

Merged
gadenbuie merged 3 commits into
posit-dev:mainfrom
taekop:fix/mcp-server-multiple-tools
Sep 29, 2026
Merged

gadenbuie merged 3 commits into
posit-dev:mainfrom
taekop:fix/mcp-server-multiple-tools

Conversation

@taekop

@taekop taekop commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #206

Summary

btw_mcp_server() checks whether tools is a path to an R file with is.character(tools) && file.exists(tools) && .... When tools names more than one tool group, e.g. btw_mcp_server(c("docs", "env", "sessioninfo")), file.exists() returns a vector and && errors under R >= 4.3, so the server fails on startup. This swaps is.character() for is_string(), so the file branch only applies to a single path.

Verification

devtools::test(filter = "mcp")

The new test in test-mcp.R calls btw_mcp_server(tools = c("docs", "env")) with mcptools::mcp_server() mocked. It errors on main with 'length = 2' in coercion to 'logical(1)' and passes with this change.

The R file detection chained `is.character(tools) && file.exists(tools)`,
which errors under R >= 4.3 when `tools` names more than one tool group.
Use `is_string()` so the file branch only considers a single path.

Fixes posit-dev#206
@taekop
taekop force-pushed the fix/mcp-server-multiple-tools branch from e294d1e to 76c7dec Compare September 25, 2026 15:59
…e `tools` argument passed to mcptools::mcp_server() and check that a character vector of tool groups is flattened to tools from those groups, and that a path to an .R script is passed through unflattened. Follows up on posit-dev#206, PR posit-dev#221.

@gadenbuie gadenbuie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I pushed a few commits to improve the tests and increase the documentation around this feature. Thanks @taekop!

@gadenbuie
gadenbuie merged commit 0d4ba4c into posit-dev:main Sep 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

btw_mcp_server() errors at startup when tools is a character vector of length > 1

2 participants