Clawith不支持本地的MCP服务吗?
Pre-checks
- [x] I have searched existing issues and this is not a duplicate.
What problem does this solve?
Clawith不支持本地的MCP服务吗?
Proposed solution
No response
Willing to contribute?
- [ ] I'd be interested in working on this.
还请放开本地私有MCP Server的接入,用处很大
还请放开本地MCP服务器的接入点,用处很大
要支持,我们想想方案
Proposal: Support Local MCP Servers (stdio transport)
Hi @wisdomqin and everyone, I did some research on the current MCP implementation in Clawith and came up with a design proposal for supporting local MCP servers. Would love your feedback!
Current State
Clawith already has a complete MCP ecosystem supporting:
- ✅ Streamable HTTP transport
- ✅ SSE transport
- ✅ Smithery / ModelScope registry integration
- ✅ Direct URL import
- ✅ Atlassian Rovo integration
However, stdio transport (local subprocess communication via stdin/stdout) is not yet supported. This means configurations like:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"]
}
}
}
cannot be used in Clawith today.
Proposed Solution
1. Add stdio transport to MCPClient (backend/app/services/mcp_client.py)
Use asyncio.create_subprocess_exec to spawn local MCP servers and communicate via stdin/stdout JSON-RPC. No new dependency needed — this uses only the Python standard library.
class MCPClient:
def __init__(self, server_url=None, api_key=None, *,
command=None, args=None, env=None):
self.command = command
self.args = args or []
self.env = env or {}
# ... existing HTTP logic unchanged ...
async def _stdio_start(self):
self._process = await asyncio.create_subprocess_exec(
self.command, *self.args,
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
env={**os.environ, **self.env},
)
await self._stdio_handshake()
async def _stdio_request(self, method, params=None):
if not self._process or self._process.returncode is not None:
await self._stdio_start()
body = {"jsonrpc": "2.0", "id": 1, "method": method, "params": params or {}}
self._process.stdin.write((json.dumps(body) + "\n").encode())
await self._process.stdin.drain()
response = await asyncio.wait_for(self._process.stdout.readline(), timeout=60)
return json.loads(response.decode())
async def close(self):
if self._process and self._process.returncode is None:
self._process.terminate()
await self._process.wait()
2. Extend the Tool data model (backend/app/models/tool.py)
Add new nullable columns (fully backward-compatible):
| Field | Type | Description |
|---|---|---|
mcp_transport |
String(20), default "http" |
"http" or "stdio" |
mcp_command |
String(500), nullable |
e.g. "npx", "python", "uvx" |
mcp_args |
JSON, nullable |
e.g. ["-y", "@mcp/server-filesystem"] |
mcp_env |
JSON, nullable |
e.g. {"GITHUB_TOKEN": "xxx"} (encrypted) |
Alembic migration for these new columns.
3. Extend API endpoints (backend/app/api/tools.py)
ToolCreateschema: addmcp_transport,mcp_command,mcp_args,mcp_envfieldsMCPTestRequestschema: addcommand,args,envfields/tools/test-mcpendpoint: support stdio mode whencommandis provided/tools/mcp-serverendpoint: support updating stdio-based MCP servers
4. Update tool execution engine (backend/app/services/agent_tools.py)
In _execute_mcp_tool(), add a branch for stdio transport:
if tool.mcp_transport == "stdio":
client = MCPClient(command=tool.mcp_command, args=tool.mcp_args, env=resolved_env)
try:
return await client.call_tool(mcp_name, arguments)
finally:
await client.close()
5. Frontend UI (frontend/src/pages/EnterpriseSettings.tsx)
- Add transport type selector:
HTTP/SSE|Local (stdio) - When stdio is selected, show fields for command, args, and env variables
- Support pasting standard MCP config JSON (like
claude_desktop_config.json) with auto-parsing
6. Resource discovery & Agent skill (resource_discovery.py, MCP_INSTALLER.md)
- Add
import_mcp_stdio()function for importing local MCP servers - Update the MCP Installer skill to support local server import (currently it says "local-only tools cannot be imported")
7. Process lifecycle management (Phase 2)
MCPProcessManager— singleton to manage subprocess reuse across requests- Health checks and auto-restart for crashed processes
- Graceful shutdown on server exit
- Configurable max process count
Security Considerations
| Risk | Mitigation |
|---|---|
| Arbitrary command execution | Only platform_admin / org_admin can add local MCP servers |
| Sensitive env vars leakage | Encrypt env values in DB, mask in API responses |
| Subprocess resource leaks | Auto-timeout, process count limit |
| Malicious MCP server | stderr logging, optional sandbox |
Implementation Phases
Phase 1 (Core backend):
mcp_client.py— stdio transporttool.py— new fields + Alembic migrationtools.py— API endpoint extensionsagent_tools.py— execution engine support
Phase 2 (Frontend + Agent integration):
EnterpriseSettings.tsx— UI for stdio configresource_discovery.py— local importMCP_INSTALLER.md— skill doc update- i18n updates
Phase 3 (Process management + security):
- Process pool manager
- Security policies (command allowlist, etc.)
Impact Assessment
- Backward compatible: ✅ All new columns are nullable with defaults. Existing HTTP/SSE MCP is completely unaffected.
- No new dependencies: Uses only
asyncio.create_subprocess_execfrom stdlib. - Database: Only additive columns, no breaking changes.
- Docker deployment: May need
node/npmpre-installed in the container image fornpx-based MCP servers.
@wisdomqin, what do you think of this approach? Happy to adjust the design based on your feedback and start implementing once we align on the direction.
Feedback on the stdio MCP Proposal
@39499740 Thank you for the thorough and well-researched proposal! The design is solid — you clearly understand the MCP protocol, our codebase structure, and the integration points. A few thoughts from our side:
Security is NOT the blocker
We already have execute_code which allows agents to run arbitrary commands inside the backend container. So stdio MCP would be at the same security level — no new risk is introduced. The security argument against it does not hold.
The real challenges are practical
-
Container runtime limitations: Our backend Docker image is a Python runtime. Most stdio MCP servers need
node/npm(npx -y @modelcontextprotocol/server-xxx),uvx, or other runtimes that are not pre-installed and should not bloat the image. -
Process lifecycle complexity: Unlike
execute_code(one-shot execution), stdio MCP servers are long-running processes that need process pool management, health checks, crash recovery, and graceful shutdown. This is a significant engineering investment. -
Dependency fragmentation: Different MCP servers need different runtimes (Node.js, Python, Go binaries, etc.). We cannot pre-install all of them.
Short-term workaround (available today)
Users can already use tools like mcp-proxy or similar bridges to expose local stdio MCP servers as HTTP/SSE endpoints, then import them into Clawith via our existing MCP URL import. No code changes needed on our side.
We want to understand your use cases better
Before we commit to an implementation direction, we would love to hear from everyone interested in this feature:
1. Which deployment mode are you using?
- Server deployment (shared, multi-user): Clawith deployed on a server, accessed by many team members via browser. In this mode, "local" MCP servers would actually run on the server, not on each user's machine — which limits the usefulness of stdio transport.
- Personal deployment (single user, local machine): Clawith deployed on your own laptop/desktop as a personal AI assistant or one-person-company setup. In this mode, stdio MCP makes a lot of sense because you want the agent to control your local environment (filesystem, databases, dev tools, etc.).
2. Which specific MCP servers do you want to use, and for what scenarios? For example:
@modelcontextprotocol/server-filesystem— local file management?@modelcontextprotocol/server-sqlite— local database access?- Custom MCP servers you built yourself?
- Something else?
This will help us prioritize the right approach. For personal deployments, we may consider a lightweight "local mode" in the architecture. For shared server deployments, the mcp-proxy bridge approach might be sufficient.
@Tyyabb @anonxiaozi @liuwenfeng-lwf123 — would love to hear your input too!
Update: Bug Found in MCPClient + Answers to Your Questions
@wisdomqin Thanks for the detailed feedback! Let me answer your questions and share an important bug I discovered while testing.
Answers to Your Questions
1. Deployment mode: Personal deployment — Clawith on my own machine as a personal AI assistant. 2. Specific MCP servers I want to use: I am using the GLM Coding Plan from Zhipu AI (智谱), which provides 4 MCP servers:
| MCP Server | Transport | Endpoint / Command | Status in Clawith |
|---|---|---|---|
| Web Reader | HTTP/SSE | https://open.bigmodel.cn/api/mcp/web_reader/mcp |
❌ "Connected, 0 tools found" |
| Web Search | HTTP/SSE | https://open.bigmodel.cn/api/mcp/web_search_prime/mcp |
❌ "Connected, 0 tools found" |
| ZRead (GitHub repos | HTTP/SSE | https://open.bigmodel.cn/api/mcp/zread/mcp |
❌ "Connected, 0 tools found" |
| Vision | stdio | npx -y @z_ai/mcp-server |
❌ Not supported |
The first 3 are remote HTTP/SSE servers — they should work with Clawith's existing MCPClient, but they don't. I found the root cause.
🐛 Bug: MCPClient silently swallows non-standard error responses
Root cause: The Zhipu MCP servers return authentication errors in a non-standard JSON-RPC format:
{"code": 1001, "msg": "Header中未收到Authorization参数,无法进行身份验证。", "success": false}
This is NOT valid JSON-RPC (no jsonrpc, error, or orresultkeys). ButMCPClient.list_tools()only checks for"error" in data`:
# mcp_client.py
if "error" in data: # ← Zhipu's response has no "error" key
raise Exception(f"MCP error: {msg}") # ← this is never reached
result = data.get("result", {}) # → {} empty, no "result" key
tools = result.get("tools", []) # → [] empty
# Returns [] → "Connected, 0 tools found" ✅ but actually failed
I confirmed this by testing directly:
POST https://open.bigmodel.cn/api/mcp/web_search_prime/mcp
→ HTTP 200
→ {"code":1001, "msg":"Header中未收到Authorization参数...", "success":false}
The server returns HTTP 200 with a non-standard error body. Clawith treats this as a successful response with no tools.
Additionally, _streamable_initialize() silently catches ALL exceptions with except Exception: pass, (line 111), so even if the MCP handshake fails, tools/list proceeds anyway and gets an uninitialized-server response.
Why This matters beyond Zhipu
This bug affects any MCP server that:
- Returns non-standard error formats (not
{jsonrpc, error: {...}}) - Returns HTTP 200 with error payloads instead of proper JSON-RPC errors
- Requires specific handshake sequences that fail silently
Proposed fix (separate from the stdio feature)
async def list_tools(self) -> list[dict]:
data = await self._detect_and_request("tools/list")
if "error" in data:
raise Exception(f"MCP error: {data[error]}")
if "result" not in data:
raise Exception(f"Unexpected response from MCP server: {json.dumps(data)[:200]}")
result = data.get("result", {})
tools = result.get("tools", []) if isinstance(result, dict) else []
...
And make _streamable_initialize propagate errors instead of swallowing them.
Summary
There are actually two separate issues here:
- Bug fix (urgent): MCPClient should properly validate JSON-RPC responses and surface errors instead of returning empty tool lists. This would fix the 3 Zhipu HTTP MCP servers and potentially many other MCP servers that users try to connect.
- Feature request: stdio transport support for local MCP servers (like Zhipu's Vision MCP). This is the harder problem you described — container runtime limitations, process lifecycle management, etc.
✅ Local MCP Support is Now Available
Clawith now fully supports MCP services through LiteLLM integration. We've successfully integrated 17 MCP servers with 996+ tools on staging.
Current Implementation
Architecture:
- MCP servers are configured in LiteLLM
- Clawith backend connects to LiteLLM MCP endpoints
- Tools are imported into Clawith database with semantic embeddings
- Semantic filtering reduces tokens by 99% while maintaining 97% hit rate
Supported MCP Servers:
- GitHub (82 tools)
- Hetzner Cloud (185 tools)
- SSH Bridge (359 tools)
- Coolify (42 tools)
- Infisical (10 tools)
- AgentMail (11 tools)
- WordPress (55 tools)
- DataForSEO (27 tools)
- ClickUp (172 tools)
- ZAI (5 tools)
- HTML Fetch (3 tools)
- PDF Generator (2 tools)
- Figma (31 tools)
- Lark Admin (10 tools)
- MiniMax (11 tools)
How to Use
-
Configure MCP server in LiteLLM ():
-
Import tools into Clawith:
-
Tools are automatically available to agents with semantic filtering
Documentation
Status
✅ Staging: Fully operational with 996 tools
🔄 Production: Ready to deploy after UI testing
Note: For local MCP servers, you can configure them in LiteLLM using transport. The server will be accessible through the LiteLLM MCP proxy.