Observed since 21 Oct, 11:15 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
MCP server for dynamic AI model switching in ai-lib ecosystem
MCP (Model Context Protocol) server that enables agents to dynamically switch AI models from the ai-lib ecosystem.
# Clone the repository
git clone https://github.com/yourorg/ai-mcp-model-switcher.git
cd ai-mcp-model-switcher
# Install dependencies
pip install -e .
Set up your API keys:
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GOOGLE_API_KEY="..."
Recommended provider key mapping:
| Provider | Environment Variable |
|---|---|
| openai | OPENAI_API_KEY |
| anthropic | ANTHROPIC_API_KEY |
GOOGLE_API_KEY or GEMINI_API_KEY | |
| deepseek | DEEPSEEK_API_KEY |
| cohere | COHERE_API_KEY |
| mistral | MISTRAL_API_KEY |
Security note:
api_key in tool arguments.Add to your MCP client configuration (e.g., Cursor, Claude Desktop):
{
"mcpServers": {
"ai-model-switcher": {
"command": "python",
"args": ["-m", "ai_mcp_model_switcher.server"],
"env": {
"AI_PROTOCOL_PATH": "/path/to/ai-protocol"
}
}
}
}
In your agent, call MCP tools:
# List available models
models = await mcp_client.call_tool("list_models", {})
# Switch to Claude 3.5 Sonnet
await mcp_client.call_tool(
"switch_model",
{"model": "anthropic/claude-3-5-sonnet"}
)
# Check current status
status = await mcp_client.call_tool("get_status", {})
Switches to a different AI model/provider.
Parameters:
model (string, required): Model identifier (e.g., openai/gpt-4o, anthropic/claude-3-5-sonnet)api_key (string, optional): Explicit API key (overrides environment variable; not recommended for production)base_url (string, optional): Custom base URL for testing/mockReturns:
{
"status": "success",
"current_provider": "anthropic",
"current_model": "claude-3-5-sonnet",
"capabilities": ["streaming", "tools", "vision"]
}
Lists all available models from registered providers.
Parameters:
filter_provider (string, optional): Filter by provider IDfilter_capability (string, optional): Filter by capability (streaming, tools, vision, embeddings)Returns:
{
"models": [
{
"id": "openai/gpt-4o",
"provider": "openai",
"capabilities": ["streaming", "tools", "vision"]
},
{
"id": "anthropic/claude-3-5-sonnet",
"provider": "anthropic",
"capabilities": ["streaming", "tools", "vision"]
}
]
}
Gets current model status and configuration.
Returns:
{
"provider": "anthropic",
"model": "claude-3-5-sonnet",
"capabilities": ["streaming", "tools", "vision"],
"is_configured": true,
"connection_epoch": 3,
"last_switched_at": "2026-03-02T09:00:00+00:00"
}
When switch_model fails due to missing credentials, the response includes:
provider: which provider is missing credentialsexpected_env_vars: accepted environment variable nameshint: actionable setup instructionTypical setup flow:
switch_model.get_status.This MCP server manages model client lifecycle internally. To avoid conflicts with an agent's own connection manager:
get_status.connection_epoch.connection_epoch increases.This pattern prevents stale session reuse after model switches and supports deterministic synchronization.
ai-mcp-model-switcher/
├── src/
│ ├── server.py # MCP server main entry point
│ ├── tools/ # MCP tool implementations
│ │ ├── switch.py # switch_model tool
│ │ ├── list.py # list_models tool
│ │ └── status.py # get_status tool
│ ├── runtime/ # Runtime abstraction layer
│ │ ├── base.py # Base runtime interface
│ │ ├── python_runtime.py # ai-lib-python implementation
│ │ └── loader.py # ProtocolLoader wrapper
│ └── state.py # State management
├── tests/ # Test suite
└── pyproject.toml # Project configuration
# Install test dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=src/ai_mcp_model_switcher
Use ai-protocol-mock:
# Start mock server
docker-compose up -d ai-protocol-mock
# Run with mock
MOCK_HTTP_URL=http://localhost:4010 python -m ai_mcp_model_switcher.server
# Format code
ruff format src tests
# Lint
ruff check src tests
# Type check
mypy src
This server follows the ai-lib design principle:
一切逻辑皆算子,一切配置皆协议
All provider configurations are loaded from ai-protocol manifests. No provider-specific logic is hardcoded. Adding a new provider requires only a manifest file in ai-protocol.
This project is licensed under either of:
at your option.
Contributions are welcome! Please ensure:
ruff checkmypy --strictai-mcp-model-switcher - Where MCP meets ai-lib. 🤖🔀
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.0 | 1 Mar 2026 | 10 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 21 Oct, 11:15 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:b56607d61a0fa2b3065faccd2b6f6392a40bb44482b603525a3337060f9e929e