MCP server calling is based on the Model Context Protocol (MCP) standard, dynamically connecting and calling tools and resources provided by external MCP servers in chat/completions. Through MCP server calling, you can extend the model’s capability boundaries, implementing various functions such as search, visual understanding, file processing, data analysis, and more, providing powerful tool ecosystem support for AI applications.
The MCP server calling feature integrates MCP tool calling capabilities in chat, supporting direct calls to chat/completions to connect and use various MCP servers to extend model functionality without requiring an MCP client. Through MCP server calling, AI can:
Dynamic Tool Discovery: Automatically discover and enumerate tools provided by MCP servers
Real-time Tool Calling: Call various tools and functions from external MCP servers
Multi-protocol Support: Support SSE and Streamable-HTTP transport protocols
Flexible Configuration: Support custom server addresses, authentication information, and tool permissions
Zhipu Ecosystem: Built-in official Zhipu MCP servers, direct use without URL configuration
Standard Compatibility: Fully compatible with MCP protocol standards, supporting third-party MCP servers
from zai import ZaiClient# Initialize clientclient = ZaiClient(api_key='Your API Key')# Use official Zhipu MCP server (no need to configure server_url)response = client.chat.completions.create( model="glm-4.6", messages=[ { "role": "user", "content": "Help me search for the latest AI technology development trends" } ], tools=[ { "type": "mcp", "mcp": { "server_label": "mcp code", "transport_type": "streamable-http", "allowed_tools": ["webSearchPrime"] # Only allow search tools } } ], tool_choice="auto")print("Search Results:")print(response.choices[0].message.content)
Connect to Third-party MCP Server
Copy
from zai import ZaiClient# Initialize clientclient = ZaiClient(api_key='Your API Key')# Connect to third-party MCP serverresponse = client.chat.completions.create( model="glm-4.6", messages=[ { "role": "user", "content": "Analyze the content of this image" } ], tools=[ { "type": "mcp", "mcp": { "server_label": "vision-server", "server_url": "https://your-mcp-server.com/mcp", "transport_type": "streamable-http", "headers": { "Authorization": "Bearer your_mcp_token", "Content-Type": "application/json" }, "allowed_tools": ["image_analysis", "video_analysis"] } } ], tool_choice="auto")print("Analysis Results:")print(response.choices[0].message.content)