进阶 zcode.z.ai 2026-11-25 14:51:22 · 0 阅读
第46章 MCP
Core FeaturesMCP
MCP (Model Context Protocol) connects external capabilities such as file systems, browsers, memory, databases, and web search to ZCode Agent. Once your commonly used MCP servers are configured, ZCode Agent can call these tools directly during multi-step tasks.
1Switch scope2Import, refresh, and create3Trust or revoke trust4Enable or disable
Entry point: open Settings → MCP Servers.
Three Ways to Connect
An MCP server can be a command started on your computer, a remote service URL, or a service that comes with a plugin. Once it connects, its tools appear in the session and ZCode Agent calls them as needed.
ZCode AgentTools in this sessionmemory · create_entitiesfigma · get_design_contextimage_search · searchOnce a server connects, its tools appear in the sessionLocal command · stdioStarts a process on the device that runs the projectPass keys and paths as environment variablesRemote service · HTTP / SSEConnects to a service URLAuth via headers; without one, OAuth in the browserFrom a pluginTurns on and off with the plugin; no separate setupOfficial services need a ZCode sign-in and a Coding PlanScopeUseravailable in every projectWorkspaceconnects only after you trust it on this computerAfter changesnew sessions pick them up; send /reload in an open task
Local commands suit tools that need local resources, such as file system, memory, or database clients. Remote services suit online services such as Figma or search. Servers from plugins need no setup of your own; install the plugin and they are ready.
Official Server MCP
Official Server MCP connects ZCode Agent to image search, financial data, and other services through official ZCode plugins. Calls use your signed-in account; no separate API key for these data services is needed. Available tools depend on what the current session has loaded.
Official plugin / servicePurposeAvailabilityImage Search (image_search)Find illustrations and reference images for documents, presentations, posters, and websitesBuilt in and enabled by defaultRoyalFlush iFinDQuery stocks, global stocks, indices, funds, and bondsInstall and enable the pluginWindQuery stocks, global stocks, indices, funds, bonds, macroeconomic data, announcements, and research reportsInstall and enable the pluginTianyanchaQuery company informationInstall and enable the pluginFinancial Aggregated SearchSearch SEC EDGAR filings, financial web pages, and newsInstall and enable the plugin
Install or enable the plugin in Settings → Plugins, then check its connection in Settings → MCP Servers. Servers are grouped by their plugin, such as Image Search, RoyalFlush iFinD, and Wind. Use the switch on the Plugins page to enable or disable them.
Sign in to ZCode and make sure your account has the required service entitlement. The four financial data plugins above require a paid plan; actual access depends on your account's entitlements. A service being visible or connected does not mean your account has quota to call it. ZCode shows a notice when the required entitlement is unavailable or the daily quota is exhausted.
Open Settings → Usage stats and select the relevant plan to view ZCode MCP quota remaining and its next reset time. ZCode MCP shows the daily aggregate quota for ZCode built-in plugin MCPs. Quota resets daily; refer to the values shown in the app. See Usage Stats for more details.
Manage MCP Servers
Use the scope selector at the top of the page to choose what to view: servers in the User scope apply to all projects, and selecting a project under Workspaces shows the servers specific to that project. The list shows only the servers of the current scope, grouped by source:
Installed: servers you created or imported. In the User scope, each row shows the name and how the server starts (a local command or a remote URL). In a workspace scope, a row shows only the name and type, plus its trust state and a Trust or Revoke trust button; see Workspace MCP Servers Must Be Trusted First. The status dot on the left shows the connection state, and the switch on the right enables or disables the server. When a connection fails, the row shows the reason and Suggested steps. Click a row to open its editor, where you can also delete it.
Plugin-provided servers: grouped by plugin. They are enabled and disabled together with their plugin; manage them in Manage Plugins.
Use the search box to find servers. The … menu contains Import, and the refresh button next to it reloads the configuration and connection status.
After you add, import, enable, or disable a server, new sessions use the updated configuration right away (servers in a workspace scope must also be trusted first). Tasks that are already open do not pick up the change automatically: send /reload in that task's input box to reconnect MCP servers and load their tools while keeping the conversation history. See Reload the Current Task.
Create an MCP Server
Click New, fill in the server using the Form or JSON tab, and click Save.
Local command · stdioRemote service · HTTP
FieldDescriptionNameThe server name, such as memory. It cannot be changed after savingScopeSave to User (all projects) or a Workspace (that project only). It cannot be changed after savingTypestdio (local command): starts a process on your computer; HTTP / SSE (Server-Sent Events): connects to a remote serviceTimeout MSHow long to wait for the server to respond, in millisecondsProtocol versionAuto (recommended) by default; choose Legacy compatibility for older serversCommand / Arguments (space separated)For stdio servers, for example command npx and arguments -y @modelcontextprotocol/server-memory, separated by spacesURLFor HTTP / SSE servers, the service addressEnvironment variables (optional) / Headers (optional)Entered as JSON. Pass keys, paths, and similar values to local servers through environment variables, and authentication such as Authorization to remote services through headers
If you already have a JSON configuration, switch to the JSON tab and paste it into Full configuration. Both {"server-name": {...}} and {"mcpServers": {...}} are supported, one server at a time.
Remote Services That Require OAuth
Some remote MCP services, such as Figma's official MCP, use browser authorization instead of a fixed key. For HTTP / SSE servers without an Authorization header, ZCode connects using the OAuth flow automatically:
When authorization is needed, the server's row shows Open authorization. Click it to authorize in your system browser; ZCode then reconnects and loads the server's tools. ZCode never opens the browser on its own.
The same applies to remote services provided by plugins; the row shows "Open authorization to finish connecting this plugin MCP server."
If authorization is not completed when a session starts, only that server is marked as failed; the rest of the session continues. Changing the service URL or authorization scope requires authorizing again.
Import from External Agents
If you have already configured MCP servers in other AI coding tools, you can import them into ZCode. Choose Import from the … menu (or click Import directly when the list is empty), and ZCode scans the configuration files of external agents on your computer:
MCP Servers page · Choose Import from the … menuImport window · Select servers and where to import them
SourceGlobal configurationProject configurationClaude Code~/.claude/settings.json.claude/settings.json, .mcp.jsonCodex CLI~/.codex/config.toml.codex/config.tomlOpenCode~/.config/opencode/opencode.json.opencode/opencode.jsonShared .agents~/.agents/mcp.json.agents/mcp.json
OpenClaw, Qwen Code, Qoder, Trae, Kiro, Roo Code, CodeBuddy, and other tools are also supported. In the import window you can:
Switch between scanning Global and Project configuration at the top right, or scan again.
Select the servers you need, or use Select all. Servers with the same name as an existing server are skipped.
Use the button at the bottom to choose Import to Global or Import to Project.
Imported servers are copied into the ZCode configuration of the chosen scope and enabled by default. The original tool's configuration files are not modified.
Configuration Files
Besides Settings, you can edit configuration files directly to manage servers in bulk:
ScopeFile pathKeyUser~/.zcode/cli/config.jsonmcp.serversWorkspace/.zcode/config.jsonmcp.serversUser · .agents compatible~/.agents/mcp.jsonmcpServersWorkspace · .agents compatible/.agents/mcp.jsonmcpServers
The user-level file is under .zcode/cli/, while the workspace-level file is directly under .zcode/. Both are named config.json but live at different levels.
The MCP section of the ZCode configuration looks like this:
{
"mcp": {
"servers": {
"memory": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"],
"env": {}
}
}
}
}
.agents/mcp.json uses the common {"mcpServers": {...}} structure, so the configuration can be shared with other tools that follow the .agents convention.
Load Rules
Usermcp.servers in ~/.zcode/cli/config.jsonCompatible: ~/.agents/mcp.jsonAvailable in every projectWorkspacemcp.servers in /.zcode/config.jsonCompatible: /.agents/mcp.jsonWins when a server name is duplicatedWithin a scope, any server in .zcode makes .agents/mcp.json ignored entirely; Settings always writes to .zcode
.zcode takes precedence within a scope: if the .zcode configuration contains any MCP server, the .agents/mcp.json of the same scope is ignored entirely; the two are not merged.
Workspace wins for duplicate names: when the workspace and user configurations contain a server with the same name, the workspace configuration is used.
Enabled state is stored in the configuration: disabling a server writes "enabled": false to its configuration; servers without this field are enabled.
Create and edit write to .zcode: servers created, edited, or deleted in Settings are written to the .zcode configuration of the corresponding scope. Servers from .agents can only be enabled or disabled in Settings, not edited.
Tip: if you maintain servers in .agents/mcp.json and then create a server in Settings, the servers in .agents stop being loaded because .zcode takes precedence. Merge the .agents configuration into the .zcode configuration to keep them.
Workspace MCP Servers Must Be Trusted First
MCP servers can run commands, read and write files, and access the network, so servers in a project's configuration do not connect automatically. Each one connects only after you trust it on your computer, including servers you created or imported into a workspace scope yourself. Servers in the User scope and servers provided by plugins do not need this step.
Trust: in Settings → MCP Servers, switch to the project. Untrusted servers show "Current declaration awaits trust". Click Trust on the row; the confirmation dialog lists the configuration file path and the server configuration. Review it, then click Trust.
Revoke trust: trusted servers show "Current declaration trusted". Click Revoke trust to withdraw it.
When it takes effect: trust does not enable MCP; the switch on the row still enables or disables the server. Existing chats keep their authorization, and changes apply to new or restarted chats.
Trust again after the configuration changes: trust applies to the current configuration. After a server's configuration is modified, for example when you pull someone else's change, trust it again.
The working directory line is omitted from the sample configuration
When a project has servers awaiting trust, a Workspace MCP servers awaiting trust icon appears in the composer toolbar. Click it and choose Review to open the MCP Servers settings for that project, or Dismiss to keep chatting.
Teams can commit the MCP configuration to the repository; each member trusts the servers after pulling. Before trusting servers in a repository from an unknown source, check their command, arguments, and URL in the confirmation dialog.
When a Server Fails to Connect
When a server fails to connect, its status dot turns red and the row shows the reason and a suggested fix. Common causes:
The MCP process failed to start / The MCP runtime is unavailableOn the device that runs the MCP server, check the start command, working directory, script path, and execute permissions, and make sure the required runtime (such as Node.js or Python) is installed and ZCode can find it. Install Python dependencies into the interpreter or virtual environment that the command actually uses.The MCP configuration is invalidCheck the command, arguments, URL, and environment variables in the configuration, fix them, and refresh.Cannot reach the MCP server / The connection timed outMake sure the service is running and that the device running the MCP server can reach its URL; check proxy, VPN, firewall, and port settings. For services that start slowly, increase Timeout MS.MCP protocol negotiation failedThe server may be on an older version. Edit the server and switch Protocol version to Legacy compatibility, and check that the local command does not print regular logs to standard output.Connected, but listing tools failed / The connection dropped unexpectedlyCheck the server logs to make sure the process has not exited, dependencies are complete, and it returns its tool list, then refresh.MCP authorization was not completed or timed outSelect Open authorization on the row, finish authorizing in the browser, and refresh in ZCode. See Remote Services That Require OAuth.Not signed in / No Coding Plan on this accountOfficial services need a ZCode sign-in and a valid Coding Plan. After signing in, check the current Coding Plan and the selected team or project in Settings → Model settings, then refresh.Too many MCP requests / The service is temporarily unavailableStop retrying for a while and refresh later. If it keeps failing, send the error details and any request ID to the service provider.
If a workspace-scope server never connects, first make sure you have trusted it; open tasks need /reload to pick up new connections.
Recommended Setup
The following official Z.ai MCP services work well with ZCode Agent. Click a link for full instructions and configuration:
zai-mcp-server: vision understanding for images, screenshots, and interfaces.
web-search-prime: web search for up-to-date information.
web-reader: web page reading that extracts the main content, structure, and key information.
These services usually require a Z.ai API key. For teams, configure shared services in the User scope and add project-specific services in the Workspace scope.
Next Steps
PluginBrowse, install, and manage ZCode plugins. Plugins can include MCP servers.SkillCapture reusable ways of working as skills.CommandSave common prompts as commands and invoke them from the input box with /.