Skip to content

Commit b65e961

Browse files
committed
Remove deprecated config-test.json and enhance documentation for upstream server management, including dynamic configuration, import mechanisms, and real-time updates. Update README with detailed MCP tools usage and configuration persistence details.
1 parent 0692da9 commit b65e961

15 files changed

Lines changed: 1161 additions & 73 deletions

File tree

DESIGN.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,76 @@ Returns `{total_tools, top:[{tool_name,count}]}`.
151151
* Hybrid BM25 + vector search.
152152
* Auto‑update channel.
153153
* GUI front‑end built with Wails.
154+
155+
## Upstream Server Management
156+
157+
### Dynamic Server Configuration
158+
159+
The proxy supports dynamic management of upstream MCP servers through the `upstream_servers` MCP tool. This enables:
160+
161+
- **Runtime Configuration**: Add, remove, and modify servers without restart
162+
- **Batch Operations**: Import multiple servers simultaneously
163+
- **Hot Reloading**: Immediate connection attempts and tool index updates
164+
- **Persistent Storage**: Configuration automatically saved to disk
165+
166+
### Configuration Persistence
167+
168+
#### Storage Architecture
169+
170+
```
171+
~/.mcpproxy/
172+
├── mcp_config.json # Main configuration file
173+
├── data.bolt # BoltDB storage (tool stats, metadata)
174+
└── index.bleve/ # Search index directory
175+
```
176+
177+
#### Configuration Flow
178+
179+
1. **Runtime Changes**: MCP tool calls modify server configurations
180+
2. **Storage Update**: Changes written to BoltDB for immediate persistence
181+
3. **Config Sync**: Configuration file updated with current state
182+
4. **Connection Management**: Upstream manager connects/disconnects servers
183+
5. **Index Update**: Tool discovery runs to update search index
184+
185+
### Server Types
186+
187+
#### HTTP Servers
188+
- **Transport**: HTTP/HTTPS requests
189+
- **Authentication**: Headers-based (API keys, tokens)
190+
- **Configuration**: URL + optional headers
191+
- **Example**: REST-based MCP servers
192+
193+
#### Stdio Servers
194+
- **Transport**: Standard input/output communication
195+
- **Process Management**: Command execution with arguments
196+
- **Environment**: Custom environment variables
197+
- **Example**: Python/Node.js MCP server scripts
198+
199+
### Import Mechanisms
200+
201+
#### Cursor IDE Compatibility
202+
- **Format**: Direct import of Cursor `mcp.json` configuration
203+
- **Conversion**: Automatic mapping to internal server configuration
204+
- **Validation**: Type detection and parameter validation
205+
206+
#### Batch Import
207+
- **Multiple Servers**: Array of server configurations
208+
- **Mixed Types**: HTTP and stdio servers in single operation
209+
- **Error Handling**: Individual server failures don't block others
210+
211+
### Real-time Updates
212+
213+
#### Connection Management
214+
- **Background Connections**: Non-blocking server connection attempts
215+
- **Retry Logic**: Exponential backoff for failed connections
216+
- **Status Tracking**: Real-time connection status updates
217+
218+
#### Tool Discovery
219+
- **Automatic Indexing**: New servers trigger tool discovery
220+
- **Search Updates**: BM25 index updated with new tools
221+
- **Statistics**: Tool usage tracking across servers
222+
223+
#### UI Integration
224+
- **Tray Updates**: System tray reflects server changes
225+
- **Status Broadcasting**: Real-time status updates to UI components
226+
- **Configuration Sync**: UI displays current server state

README.md

Lines changed: 198 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,201 @@ MIT License - see LICENSE file for details.
373373
- Verify network connectivity
374374
- Check firewall settings
375375

376-
For more detailed troubleshooting, see [TRAY_ICON_GUIDE.md](TRAY_ICON_GUIDE.md).
376+
For more detailed troubleshooting, see [TRAY_ICON_GUIDE.md](TRAY_ICON_GUIDE.md).
377+
378+
## MCP Tools
379+
380+
The Smart MCP Proxy provides several MCP tools for managing servers and discovering tools:
381+
382+
### `upstream_servers` - Server Management
383+
384+
Comprehensive tool for managing upstream MCP servers with support for multiple operations:
385+
386+
#### Operations
387+
388+
- **`list`** - List all configured upstream servers
389+
- **`add`** - Add a single upstream server
390+
- **`add_batch`** - Add multiple servers at once
391+
- **`remove`** - Remove an upstream server
392+
- **`update`** - Update an existing server
393+
- **`patch`** - Partially update server configuration
394+
- **`import_cursor`** - Import servers from Cursor IDE format
395+
396+
#### Adding Single Server
397+
398+
```json
399+
{
400+
"operation": "add",
401+
"name": "github-tools",
402+
"url": "http://localhost:3001",
403+
"headers": {
404+
"Authorization": "Bearer your-token-here"
405+
},
406+
"enabled": true
407+
}
408+
```
409+
410+
```json
411+
{
412+
"operation": "add",
413+
"name": "sqlite-tools",
414+
"command": "uvx",
415+
"args": ["mcp-server-sqlite", "--db-path", "/path/to/db.sqlite"],
416+
"env": {
417+
"MCP_SQLITE_PATH": "/path/to/db.sqlite"
418+
},
419+
"enabled": true
420+
}
421+
```
422+
423+
#### Batch Adding Servers
424+
425+
```json
426+
{
427+
"operation": "add_batch",
428+
"servers": [
429+
{
430+
"name": "github-tools",
431+
"url": "http://localhost:3001",
432+
"headers": {
433+
"Authorization": "Bearer token123"
434+
},
435+
"enabled": true
436+
},
437+
{
438+
"name": "sqlite-tools",
439+
"command": "uvx",
440+
"args": ["mcp-server-sqlite", "--db-path", "/tmp/test.db"],
441+
"env": {
442+
"MCP_SQLITE_PATH": "/tmp/test.db"
443+
},
444+
"enabled": true
445+
}
446+
]
447+
}
448+
```
449+
450+
#### Import from Cursor IDE
451+
452+
You can directly import your Cursor IDE MCP configuration:
453+
454+
```json
455+
{
456+
"operation": "import_cursor",
457+
"cursor_config": {
458+
"mcp-server-sqlite": {
459+
"command": "uvx",
460+
"args": ["mcp-server-sqlite", "--db-path", "/path/to/db.sqlite"],
461+
"env": {
462+
"MCP_SQLITE_PATH": "/path/to/db.sqlite"
463+
}
464+
},
465+
"mcp-server-github": {
466+
"url": "http://localhost:3000/mcp",
467+
"headers": {
468+
"Authorization": "Bearer github-token"
469+
}
470+
}
471+
}
472+
}
473+
```
474+
475+
#### Patch/Update Server
476+
477+
```json
478+
{
479+
"operation": "patch",
480+
"name": "github-tools",
481+
"enabled": false,
482+
"headers": {
483+
"Authorization": "Bearer new-token"
484+
}
485+
}
486+
```
487+
488+
### `retrieve_tools` - Tool Discovery
489+
490+
Search for tools across all upstream servers:
491+
492+
```json
493+
{
494+
"query": "github repository",
495+
"limit": 10
496+
}
497+
```
498+
499+
### `call_tool` - Tool Execution
500+
501+
Execute tools on upstream servers:
502+
503+
```json
504+
{
505+
"name": "github:create_repository",
506+
"args": {
507+
"name": "my-new-repo",
508+
"private": false
509+
}
510+
}
511+
```
512+
513+
### `tools_stats` - Usage Statistics
514+
515+
Get tool usage statistics:
516+
517+
```json
518+
{
519+
"top_n": 10
520+
}
521+
```
522+
523+
## Configuration Persistence
524+
525+
The proxy automatically saves configuration changes to `~/.mcpproxy/mcp_config.json`. This includes:
526+
527+
- All upstream server configurations
528+
- Server states (enabled/disabled)
529+
- Connection parameters (URLs, commands, environment variables)
530+
- Authentication headers
531+
532+
### Configuration File Location
533+
534+
The configuration file location can be customized:
535+
536+
```bash
537+
# Via environment variable
538+
export MCPPROXY_DATA_DIR=/custom/path
539+
./mcpproxy
540+
541+
# Via command line flag
542+
./mcpproxy --data-dir /custom/path
543+
```
544+
545+
### Hot Reloading
546+
547+
The proxy automatically:
548+
- Saves configuration after any server changes
549+
- Attempts to connect to newly added servers
550+
- Updates the tool index when servers are modified
551+
- Reflects changes in the system tray (if enabled)
552+
553+
## Basic Usage Scenarios
554+
555+
### Scenario 1: Import from Cursor IDE
556+
557+
1. Copy your Cursor IDE `mcp.json` configuration
558+
2. Use the `import_cursor` operation with the `upstream_servers` tool
559+
3. All servers will be automatically added and connected
560+
4. Configuration is persisted to `~/.mcpproxy/mcp_config.json`
561+
562+
### Scenario 2: Add Individual Servers
563+
564+
1. Use `upstream_servers` with `add` operation
565+
2. Specify either `url` (for HTTP) or `command`/`args` (for stdio)
566+
3. Include authentication headers if needed
567+
4. Server is immediately connected and tools indexed
568+
569+
### Scenario 3: Batch Server Management
570+
571+
1. Use `add_batch` operation with array of server configurations
572+
2. Mix HTTP and stdio servers in the same request
573+
3. All servers processed and connected simultaneously

config-test.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

internal/config/config.go

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,58 @@ type Config struct {
1717

1818
// ServerConfig represents upstream MCP server configuration
1919
type ServerConfig struct {
20-
Name string `json:"name,omitempty" mapstructure:"name"`
21-
URL string `json:"url,omitempty" mapstructure:"url"`
22-
Type string `json:"type,omitempty" mapstructure:"type"` // http, stdio, auto
23-
Command string `json:"command,omitempty" mapstructure:"command"`
24-
Args []string `json:"args,omitempty" mapstructure:"args"`
25-
Env map[string]string `json:"env,omitempty" mapstructure:"env"`
26-
Enabled bool `json:"enabled" mapstructure:"enabled"`
27-
Created time.Time `json:"created" mapstructure:"created"`
20+
Name string `json:"name,omitempty" mapstructure:"name"`
21+
URL string `json:"url,omitempty" mapstructure:"url"`
22+
Protocol string `json:"protocol,omitempty" mapstructure:"protocol"` // stdio, http, sse, streamable-http, auto
23+
Command string `json:"command,omitempty" mapstructure:"command"`
24+
Args []string `json:"args,omitempty" mapstructure:"args"`
25+
Env map[string]string `json:"env,omitempty" mapstructure:"env"`
26+
Headers map[string]string `json:"headers,omitempty" mapstructure:"headers"` // For HTTP servers
27+
Enabled bool `json:"enabled" mapstructure:"enabled"`
28+
Created time.Time `json:"created" mapstructure:"created"`
29+
Updated time.Time `json:"updated,omitempty" mapstructure:"updated"`
30+
}
31+
32+
// CursorMCPConfig represents the structure for Cursor IDE MCP configuration
33+
type CursorMCPConfig struct {
34+
MCPServers map[string]CursorServerConfig `json:"mcpServers"`
35+
}
36+
37+
// CursorServerConfig represents a single server configuration in Cursor format
38+
type CursorServerConfig struct {
39+
Command string `json:"command,omitempty"`
40+
Args []string `json:"args,omitempty"`
41+
Env map[string]string `json:"env,omitempty"`
42+
URL string `json:"url,omitempty"`
43+
Headers map[string]string `json:"headers,omitempty"`
44+
}
45+
46+
// ConvertFromCursorFormat converts Cursor IDE format to our internal format
47+
func ConvertFromCursorFormat(cursorConfig *CursorMCPConfig) []*ServerConfig {
48+
var servers []*ServerConfig
49+
50+
for name, serverConfig := range cursorConfig.MCPServers {
51+
server := &ServerConfig{
52+
Name: name,
53+
Enabled: true,
54+
Created: time.Now(),
55+
}
56+
57+
if serverConfig.Command != "" {
58+
server.Command = serverConfig.Command
59+
server.Args = serverConfig.Args
60+
server.Env = serverConfig.Env
61+
server.Protocol = "stdio"
62+
} else if serverConfig.URL != "" {
63+
server.URL = serverConfig.URL
64+
server.Headers = serverConfig.Headers
65+
server.Protocol = "http"
66+
}
67+
68+
servers = append(servers, server)
69+
}
70+
71+
return servers
2872
}
2973

3074
// ToolMetadata represents tool information stored in the index

0 commit comments

Comments
 (0)