Skip to content

Add working directory support for stdio MCP servers#57

Merged
Dumbris merged 1 commit into
mainfrom
bugfix/stdio-working-dir
Sep 15, 2025
Merged

Add working directory support for stdio MCP servers#57
Dumbris merged 1 commit into
mainfrom
bugfix/stdio-working-dir

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 13, 2025

Copy link
Copy Markdown
Member

Summary

  • Add working_dir field to ServerConfig for stdio servers
  • Implement working directory validation with proper error handling
  • Extend upstream_servers tool to accept working_dir parameter for add/update operations
  • Add comprehensive tests and documentation

Background

Resolves the issue where file-based MCP servers (like ast-grep-mcp, filesystem-mcp, git-mcp) operate from mcpproxy's directory instead of project directories when mcpproxy runs as a global daemon.

Changes Made

  • Config: Added WorkingDir field to ServerConfig struct
  • Validation: Added validateWorkingDir() function with directory existence checking
  • Transport: Custom CommandFunc using mcp-go's WithCommandFunc option
  • Management: Extended upstream_servers tool operations (add/update/patch)
  • Testing: Comprehensive test suite in workingdir_test.go
  • Documentation: Updated README.md and CLAUDE.md with examples

Example Usage

{
  "mcpServers": [
    {
      "name": "ast-grep-project-a",
      "command": "npx", 
      "args": ["ast-grep-mcp"],
      "working_dir": "/home/user/projects/project-a",
      "enabled": true
    }
  ]
}

Test Plan

  • Unit tests for working directory validation
  • Integration tests with Docker isolation
  • Error handling for non-existent directories
  • Backwards compatibility (empty working_dir)
  • Tool management operations
  • Linter and formatting checks

Backwards Compatibility

✅ Fully backwards compatible - empty/unspecified working_dir uses current directory (existing behavior)

- Introduced `working_dir` field in ServerConfig to specify the working directory for stdio servers.
- Enhanced documentation in CLAUDE.md and README.md to explain working directory configuration and its benefits.
- Implemented validation for working directories to ensure they exist and are accessible.
- Updated connection handling to support working directory context for stdio transports.
- Added comprehensive unit tests for working directory validation and integration with Docker isolation.

This feature improves project context management and allows for better separation of work and personal projects.
@Dumbris
Dumbris merged commit 9af475b into main Sep 15, 2025
33 checks passed
@Dumbris
Dumbris deleted the bugfix/stdio-working-dir branch September 15, 2025 17:35
rannow pushed a commit to rannow/mcpproxy-go that referenced this pull request Sep 23, 2025
…io-working-dir

Add working directory support for stdio MCP servers
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.

1 participant