Skip to content

Commit 0b83b6e

Browse files
docs(mcp): update strategy template with interface docs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 69d61cc commit 0b83b6e

1 file changed

Lines changed: 48 additions & 3 deletions

File tree

docs/articles/devs/implementation_guides/mcp_host_configuration_extension.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,67 @@ class YourHostStrategy(MCPHostStrategy):
177177
"""Return the key containing MCP servers."""
178178
return "mcpServers" # Most hosts use this
179179

180-
# read_configuration() and write_configuration()
181-
# can inherit from a base class or implement from scratch
180+
def get_adapter_host_name(self) -> str:
181+
"""Return the adapter host name for registry lookup."""
182+
return "your-host"
183+
184+
def validate_server_config(self, server_config: MCPServerConfig) -> bool:
185+
"""Basic transport validation before adapter processing."""
186+
return server_config.command is not None or server_config.url is not None
187+
188+
def read_configuration(self) -> HostConfiguration:
189+
"""Read and parse host configuration file."""
190+
# Implement JSON/TOML parsing for your host's config format
191+
...
192+
193+
def write_configuration(
194+
self, config: HostConfiguration, no_backup: bool = False
195+
) -> bool:
196+
"""Write configuration using adapter serialization."""
197+
# Use get_adapter(self.get_adapter_host_name()) for serialization
198+
...
182199
```
183200

201+
**The `@register_host_strategy` decorator** registers the strategy class in a global dictionary (`MCPHostRegistry._strategies`) keyed by `MCPHostType`. This enables `MCPHostRegistry.get_strategy(host_type)` to look up and instantiate the correct strategy at runtime. The decorator is defined in `host_management.py` as a convenience wrapper around `MCPHostRegistry.register()`.
202+
203+
#### MCPHostStrategy Interface
204+
205+
The base `MCPHostStrategy` class (defined in `host_management.py`) provides the full strategy interface. The table below shows which methods typically need overriding vs which can be inherited from family base classes.
206+
207+
| Method | Must Override | Can Inherit | Notes |
208+
|--------|:------------:|:-----------:|-------|
209+
| `get_config_path()` | Always | -- | Platform-specific path to config file |
210+
| `is_host_available()` | Always | -- | Check if host is installed on system |
211+
| `get_config_key()` | Usually | From family | Most hosts use `"mcpServers"` (default) |
212+
| `get_adapter_host_name()` | Usually | From family | Maps strategy to adapter registry entry |
213+
| `validate_server_config()` | Usually | From family | Basic transport presence check |
214+
| `read_configuration()` | Sometimes | From family | JSON read is identical across families |
215+
| `write_configuration()` | Sometimes | From family | JSON write with adapter serialization |
216+
217+
> **Cross-reference:** See the [Architecture Doc -- MCPHostStrategy](../architecture/mcp_host_configuration.md#key-components) for the full interface specification.
218+
184219
**Inheriting from existing strategy families:**
185220

221+
If your host uses a standard JSON format, inherit from an existing family base class to get `read_configuration()`, `write_configuration()`, and shared validation for free:
222+
186223
```python
187-
# If similar to Claude (standard JSON format)
224+
# If similar to Claude (standard JSON format with mcpServers key)
225+
@register_host_strategy(MCPHostType.YOUR_HOST)
188226
class YourHostStrategy(ClaudeHostStrategy):
189227
def get_config_path(self) -> Optional[Path]:
190228
return Path.home() / ".your_host" / "config.json"
191229

230+
def is_host_available(self) -> bool:
231+
return self.get_config_path().parent.exists()
232+
192233
# If similar to Cursor (flexible path handling)
234+
@register_host_strategy(MCPHostType.YOUR_HOST)
193235
class YourHostStrategy(CursorBasedHostStrategy):
194236
def get_config_path(self) -> Optional[Path]:
195237
return Path.home() / ".your_host" / "config.json"
238+
239+
def is_host_available(self) -> bool:
240+
return self.get_config_path().parent.exists()
196241
```
197242

198243
### Step 4: Add Tests

0 commit comments

Comments
 (0)