get-zhihu-trending
get-zhihu-trendingRetrieve trending discussions from Zhihu, covering current affairs, social topics, technology updates, and entertainment news in Chinese.
Instructions
获取知乎热榜,包含时事热点、社会话题、科技动态、娱乐八卦等多领域的热门问答和讨论的中文资讯
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get-zhihu-trending"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No |
Implementation Reference
- src/mcp.ts:15-36 (handler)Core handler function that proxies tool execution to remote API at https://mcp.xiaobenyang.com/api, using toolName ('get-zhihu-trending') as 'func' header and passing arguments as body.
const calcXiaoBenYangApi = async function (fullArgs: Record<string, any>) { // 发起 POST 请求 let response = await fetch('https://mcp.xiaobenyang.com/api', { method: 'POST', headers: { 'XBY-APIKEY': apiKey, 'func': fullArgs.toolName, 'mcpid': mcpID }, body: new URLSearchParams(fullArgs) }); const apiResult = await response.text(); return { content: [ { type: "text", text: apiResult // 将字符串结果放入 content 中 } ] } as { [x: string]: unknown; content: [{ type: "text"; text: string }] }; }; - src/mcp.ts:39-48 (handler)Wrapper handler that prepares arguments with toolName and calls the core proxy function for tools like get-zhihu-trending.
const handleXiaoBenYangApi = async (args: Record<string, any>, toolName: string) => { // 校验aid是否存在 if (toolName === undefined || toolName === null) { throw new Error("缺少必要参数 'aid'"); } // 合并参数 const fullArgs = {...args, toolName: toolName}; // 调用API return calcXiaoBenYangApi(fullArgs); }; - src/mcp.ts:73-144 (registration)Dynamic registration function that fetches tool list from remote API (for mcpId 1777316659328003), builds Zod schemas, and registers each tool (including get-zhihu-trending if present) using server.registerTool.
const getServer = async () => { console.log("getServer start.........") if(!isRegistered) { try { state.isLoading = true; const res = await fetch('https://mcp.xiaobenyang.com/getMcpDesc?mcpId=' + mcpID, { method: 'GET', }); if (!res.ok) { throw new Error(`请求失败:${res.status}`); } const data = await res.json(); const apiDescList = data.tools; for (const apiDesc of apiDescList) { let inputSchema = JSON.parse(apiDesc.inputSchema); const zodDict: Record<string, z.ZodTypeAny> = {}; Object.entries(inputSchema.properties).forEach(([name, propConfig]) => { let zodType; let pt = (propConfig as { type: string }).type; switch (pt) { case 'string': zodType = z.string(); break; case 'number': zodType = z.number(); break; case 'boolean': zodType = z.boolean(); break; case 'integer': zodType = z.int32(); break; case 'array': zodType = z.array(z.any()); break; case 'object': zodType = z.object(z.any()); break; default: zodType = z.any(); } if (inputSchema.required?.includes(name)) { zodDict[name] = zodType; } else { zodDict[name] = zodType.optional(); } }); addToolXiaoBenYangApi( apiDesc.name, apiDesc.description ? apiDesc.description : apiDesc.name, zodDict); } isRegistered = true; state.isLoading = false; console.log("state.isLoading: " + state.isLoading) return server; } catch (error) { console.error("getServer 执行失败:", error); state.isLoading = false; // 异常时也需要重置加载状态 throw error; // 抛出错误,让调用方捕获 } } else { return server; } - src/mcp.ts:50-65 (helper)Helper function to register a tool with schema and generic handler bound to the tool name.
const addToolXiaoBenYangApi = function ( name: string, desc: string, params: Record<string, ZodType> ) { server.registerTool( name, { title: name, description: desc, inputSchema: params, } , async (args: Record<string, any>) => handleXiaoBenYangApi(args, name) ) }; - src/mcp.ts:91-125 (schema)Dynamic schema construction from remote tool description JSON schema, mapping to Zod types for input validation.
let inputSchema = JSON.parse(apiDesc.inputSchema); const zodDict: Record<string, z.ZodTypeAny> = {}; Object.entries(inputSchema.properties).forEach(([name, propConfig]) => { let zodType; let pt = (propConfig as { type: string }).type; switch (pt) { case 'string': zodType = z.string(); break; case 'number': zodType = z.number(); break; case 'boolean': zodType = z.boolean(); break; case 'integer': zodType = z.int32(); break; case 'array': zodType = z.array(z.any()); break; case 'object': zodType = z.object(z.any()); break; default: zodType = z.any(); } if (inputSchema.required?.includes(name)) { zodDict[name] = zodType; } else { zodDict[name] = zodType.optional(); } });