Skip to content

Support directory-scoped MCP tool calls#104

Merged
uchebnick merged 2 commits into
mainfrom
fix/mcp-directory-tools
Apr 26, 2026
Merged

Support directory-scoped MCP tool calls#104
uchebnick merged 2 commits into
mainfrom
fix/mcp-directory-tools

Conversation

@uchebnick
Copy link
Copy Markdown
Owner

@uchebnick uchebnick commented Apr 26, 2026

Summary

  • Add an optional directory argument to all unch MCP tools: workspace_status, search_code, and index_repository.
  • Route MCP calls to a backend scoped to the requested repository directory instead of always using the MCP process launch directory.
  • Keep workspace_status cheap: it previews the target state path and does not create .semsearch.
  • Document the directory argument in README and Mintlify MCP docs.

Fixes #98.

Tests

  • go test ./internal/mcp ./internal/cli
  • go test ./...
  • real stdio smoke via go run ./cmd/unch start mcp + workspace_status with directory

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds directory-scoped routing to the MCP server so tool calls can target the active workspace directory (instead of the MCP process launch directory), with documentation and tests to validate the new argument is plumbed through.

Changes:

  • Added optional directory parameter to MCP tool parameter structs and tool JSON schemas.
  • Updated MCP backend to route workspace_status, search_code, and index_repository to per-directory backends (with caching).
  • Added/updated tests and documentation for the new directory argument and behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
mintlify/commands/mcp.mdx Documents the new optional directory argument for MCP tools.
internal/mcp/types.go Adds WorkspaceStatusParams and Directory fields to MCP params; updates service interface signature.
internal/mcp/tools.go Exposes directory in tool input schemas and plumbs args into WorkspaceStatus.
internal/mcp/server_test.go Updates fake service interface and adds assertions that directory is present/forwarded.
internal/cli/start.go Switches MCP startup to preview paths and passes state/db inputs into backend config for per-directory routing.
internal/cli/mcp_backend_test.go Adds tests validating directory affects workspace_status and rejects file paths.
internal/cli/mcp_backend.go Implements directory routing via cached child backends and directory normalization/validation.
README.md Documents that MCP tools accept optional directory and the installed skill passes the active repo path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +363 to +367
func (b *mcpBackend) backendForDirectory(directory string) (*mcpBackend, error) {
rootAbs, ok, err := normalizeMCPDirectory(directory)
if err != nil {
return nil, err
}
Comment on lines +372 to +380
b.childrenMu.Lock()
defer b.childrenMu.Unlock()

if b.children == nil {
b.children = map[string]*mcpBackend{}
}
if child, ok := b.children[rootAbs]; ok {
return child, nil
}
@uchebnick uchebnick merged commit e163efa into main Apr 26, 2026
44 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.

MCP tools should honor per-call directory

2 participants