{"id":4047,"date":"2025-10-26T14:40:50","date_gmt":"2025-10-26T06:40:50","guid":{"rendered":"https:\/\/saludpcb.com\/zh\/?p=4047"},"modified":"2025-11-03T20:11:28","modified_gmt":"2025-11-03T12:11:28","slug":"mcp-server-c-ai-coding-agent","status":"publish","type":"post","link":"https:\/\/saludpcb.com\/zh\/mcp-server-c-ai-coding-agent\/","title":{"rendered":"2025 \u81ea\u5efa MCP Server | \u6253\u9020\u4f60\u7684 C++ AI \u4ee3\u7406\u7de8\u7a0b\u52a9\u624b"},"content":{"rendered":"\n<hr class=\"wp-block-separator alignwide has-text-color has-palette-color-1-color has-alpha-channel-opacity has-palette-color-1-background-color has-background is-style-wide\"\/>\n\n\n\n<p><strong>MCP Server<\/strong> \u2014 \u96d6\u7136\u807d\u8d77\u4f86\u5f88\u6280\u8853\u6027\uff0c\u4f46\u5b83\u6b63\u5728\u6084\u6084\u6539\u8b8a\u6211\u5011\u8207 AI \u7684\u4e92\u52d5\u65b9\u5f0f\u3002<br>\u56de\u60f3\u4f60\u7b2c\u4e00\u6b21\u4f7f\u7528 AI \u7de8\u7a0b\u52a9\u624b\u7684\u7d93\u9a57\uff1a\u5b83\u53ef\u4ee5\u5beb\u51fa\u512a\u96c5\u7684\u7a0b\u5f0f\u78bc\uff0c\u89e3\u91cb\u8907\u96dc\u7684\u6982\u5ff5\uff0c\u4f46\u7576\u4f60\u554f\uff1a\u300c\u9019\u6bb5\u7a0b\u5f0f\u78bc\u80fd\u771f\u6b63\u904b\u884c\u55ce\uff1f\u300d\u6642\uff0c\u5f97\u5230\u7684\u7e3d\u662f\uff1a\u300c\u8acb\u60a8\u81ea\u884c\u7de8\u8b6f\u6e2c\u8a66\u3002\u300d<\/p>\n\n\n\n<p><strong>MCP Server<\/strong> \u6b63\u597d\u5f4c\u88dc\u4e86\u9019\u500b\u7a7a\u7f3a\u3002\u5b83\u5c07 AI \u5f9e\u4e00\u500b\u975c\u614b\u7684\u77e5\u8b58\u4f86\u6e90\uff0c\u8f49\u8b8a\u70ba\u80fd\u5920\u5be6\u969b\u884c\u52d5\u7684\u667a\u80fd\u5925\u4f34\u2014\u2014\u53ef\u4ee5\u7de8\u8b6f\u7a0b\u5f0f\u78bc\u3001\u904b\u884c\u6e2c\u8a66\u3001\u5206\u6790\u6578\u64da\uff0c\u751a\u81f3\u5f9e\u7db2\u8def\u4e0a\u7372\u53d6\u8cc7\u8a0a\u3002<br>\u5b83\u4e0d\u53ea\u662f\u4e00\u500b\u5354\u8b70\uff0c\u800c\u662f\u8b93 AI \u771f\u6b63\u8207\u73fe\u5be6\u4e16\u754c\u4e92\u52d5\u7684\u6a4b\u6a11\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/saludpcb.com\/zh\/wp-content\/uploads\/2025\/10\/Build-a-Powerful-MCP-Server-Supercharge-Your-C-AI-Coding-Agent.jpg\" alt=\"MCP Server\" class=\"wp-image-4059\" title=\"\" srcset=\"https:\/\/saludpcb.com\/zh\/wp-content\/uploads\/2025\/10\/Build-a-Powerful-MCP-Server-Supercharge-Your-C-AI-Coding-Agent.jpg 1024w, https:\/\/saludpcb.com\/zh\/wp-content\/uploads\/2025\/10\/Build-a-Powerful-MCP-Server-Supercharge-Your-C-AI-Coding-Agent-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>\u5167\u5bb9<\/h2><nav><ul><li class=\"\"><a href=\"#\u4ec0\u9ebc\u662f-ollama\uff1f\">\u4ec0\u9ebc\u662f MCP Server\uff1f<\/a><\/li><li class=\"\"><a href=\"#ai-agent-\u7684\u6838\u5fc3\u904b\u4f5c\u6a21\u5f0f\">MCP \u4f3a\u670d\u5668\u6838\u5fc3\u904b\u4f5c\u6a21\u5f0f<\/a><\/li><li class=\"\"><a href=\"#\u70ba\u4ec0\u9ebc-c-\u958b\u767c\u8005\u9700\u8981\u81ea\u5efa-mcp-server\uff1f\">\u70ba\u4ec0\u9ebc C++ \u958b\u767c\u8005\u9700\u8981\u81ea\u5efa MCP Server\uff1f<\/a><\/li><li class=\"\"><a href=\"#\u958b\u767c\u74b0\u5883\u6e96\u5099\">\u958b\u767c\u74b0\u5883<\/a><\/li><li class=\"\"><a href=\"#\u5be6\u6230\u958b\u59cb\uff1a\u6253\u9020\u4f60\u7684-c-mcp-server\">\u5be6\u6230\u958b\u59cb\uff1a\u6253\u9020\u4f60\u7684 C++ MCP \u4f3a\u670d\u5668<\/a><\/li><li class=\"\"><a href=\"#\u5c08\u6848\u7d50\u69cb\">\u5c08\u6848\u7d50\u69cb<\/a><\/li><li class=\"\"><a href=\"#\u6e2c\u8a66\u4f60\u7684-mcp-server-1\">\u6e2c\u8a66 C++ MCP<\/a><\/li><li class=\"\"><a href=\"#\u8aaa\">\u8aaa\u660e server.js <\/a><\/li><li class=\"\"><a href=\"#\u7d50\u8ad6-1\">\u7d50\u8ad6<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4ec0\u9ebc\u662f-ollama\uff1f\">\u4ec0\u9ebc\u662f MCP Server\uff1f<\/h2>\n\n\n\n<p><strong>MCP Server<\/strong> \u662f\u57fa\u65bc <strong>Model Context Protocol\uff08MCP\uff09<\/strong> \u7684\u4f3a\u670d\u5668\u670d\u52d9\uff0c<br>\u5b83\u53ef\u4ee5\u8b93 AI \u52a9\u624b\uff08\u5982 ChatGPT\u3001Claude \u6216 Gemini\uff09\u5b89\u5168\u5730\u8207\u5916\u90e8\u5de5\u5177\u3001\u672c\u5730\u6a94\u6848\u548c\u7cfb\u7d71\u74b0\u5883\u4e92\u52d5\u3002<\/p>\n\n\n\n<p>\u7c21\u55ae\u4f86\u8aaa\uff0c\u5b83\u662f <strong>AI \u8207\u73fe\u5be6\u4e16\u754c\u4e4b\u9593\u7684\u6a4b\u6a11<\/strong>\u3002<br>\u900f\u904e MCP \u4f3a\u670d\u5668\uff0cAI \u4e0d\u518d\u53ea\u662f\u4f9d\u64da\u8a13\u7df4\u8cc7\u6599\u751f\u6210\u6587\u5b57\uff0c\u800c\u662f\u53ef\u4ee5\u771f\u6b63\u300c\u52d5\u624b\u300d\u64cd\u4f5c\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8b80\u53d6\u6216\u4fee\u6539\u5c08\u6848\u6a94\u6848<\/li>\n\n\n\n<li>\u57f7\u884c\u7cfb\u7d71\u6307\u4ee4\u6216\u7de8\u8b6f\u7a0b\u5f0f\u78bc<\/li>\n\n\n\n<li>\u67e5\u8a62\u8cc7\u6599\u5eab\u6216 API<\/li>\n\n\n\n<li>\u904b\u884c\u6e2c\u8a66\u4e26\u5206\u6790\u7d50\u679c<\/li>\n<\/ul>\n\n\n\n<p>\u63db\u53e5\u8a71\u8aaa\uff0cMCP \u4f3a\u670d\u5668 \u5c07 AI \u5f9e\u975c\u614b\u7684\u300c\u77e5\u8b58\u5eab\u300d\u8f49\u8b8a\u70ba <strong>\u80fd\u5920\u7a4d\u6975\u53c3\u8207\u5de5\u4f5c\u6d41\u7a0b\u7684\u667a\u80fd\u5925\u4f34<\/strong>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ai-agent-\u7684\u6838\u5fc3\u904b\u4f5c\u6a21\u5f0f\">MCP \u4f3a\u670d\u5668\u6838\u5fc3\u904b\u4f5c\u6a21\u5f0f<\/h2>\n\n\n\n<p><a href=\"https:\/\/modelcontextprotocol.io\/docs\/getting-started\/intro\" target=\"_blank\" rel=\"noopener\">MCP Server<\/a> \u7684\u904b\u4f5c\u6a21\u5f0f\u672c\u8cea\u4e0a\u662f <strong>\u4e00\u500b AI \u8207\u5916\u90e8\u5de5\u5177\u4e4b\u9593\u7684\u6a4b\u6a11<\/strong>\uff0c\u5176\u6838\u5fc3\u6d41\u7a0b\u53ef\u4ee5\u5206\u70ba\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8a3b\u518a\u5de5\u5177\uff08Tool Registration\uff09<\/strong><\/li>\n\n\n\n<li><strong>\u5efa\u7acb\u901a\u8a0a\u901a\u9053\uff08Transport Layer\uff09<\/strong><\/li>\n\n\n\n<li><strong>\u63a5\u6536 AI \u8acb\u6c42\uff08Request Handling\uff09<\/strong><\/li>\n\n\n\n<li><strong>\u57f7\u884c\u5de5\u5177\uff08Tool Execution\uff09<\/strong><\/li>\n\n\n\n<li><strong>\u56de\u50b3\u7d50\u679c\u7d66 AI\uff08Response Delivery\uff09<\/strong><\/li>\n\n\n\n<li><strong>\u5b89\u5168\u8207\u6b0a\u9650\u63a7\u5236\uff08Optional Security Layer\uff09<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u70ba\u4ec0\u9ebc-c-\u958b\u767c\u8005\u9700\u8981\u81ea\u5efa-mcp-server\uff1f\">\u70ba\u4ec0\u9ebc C++ \u958b\u767c\u8005\u9700\u8981\u81ea\u5efa MCP Server\uff1f<\/h2>\n\n\n\n<p>\u5c0d C++ \u958b\u767c\u8005\u4f86\u8aaa\uff0cMCP Server \u7684\u597d\u8655\u975e\u5e38\u660e\u986f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u529f\u80fd<\/th><th>\u50b3\u7d71 AI \u52a9\u624b<\/th><th>MCP Server \u52a0\u6301\u5f8c<\/th><\/tr><\/thead><tbody><tr><td>\u8b80\u53d6\u5c08\u6848\u4ee3\u78bc<\/td><td>\u274c \u9700\u624b\u52d5\u8cbc\u4e0a\u4ee3\u78bc<\/td><td>\u2705 \u81ea\u52d5\u8b80\u53d6\u6307\u5b9a\u8cc7\u6599\u593e<\/td><\/tr><tr><td>\u7de8\u8b6f\u6e2c\u8a66<\/td><td>\u274c \u7121\u6cd5\u57f7\u884c\u6307\u4ee4<\/td><td>\u2705 \u53ef\u547c\u53eb <code>g++<\/code> \u6216 <code>cmake<\/code><\/td><\/tr><tr><td>\u55ae\u5143\u6e2c\u8a66<\/td><td>\u274c \u7121\u6cd5\u57f7\u884c<\/td><td>\u2705 \u76f4\u63a5\u8dd1\u6e2c\u8a66\u4e26\u56de\u5831\u7d50\u679c<\/td><\/tr><tr><td>\u932f\u8aa4\u5206\u6790<\/td><td>\u274c \u50c5\u8a9e\u6cd5\u63a8\u6e2c<\/td><td>\u2705 \u6839\u64da\u5be6\u969b\u932f\u8aa4\u8a0a\u606f\u5206\u6790<\/td><\/tr><tr><td>\u81ea\u52d5\u4fee\u6b63<\/td><td>\u274c \u88ab\u52d5\u5efa\u8b70<\/td><td>\u2705 \u4e3b\u52d5\u4fee\u6539\u4e26\u91cd\u65b0\u7de8\u8b6f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u958b\u767c\u74b0\u5883\u6e96\u5099\">\u958b\u767c\u74b0\u5883<\/h2>\n\n\n\n<p>\u5728\u958b\u59cb\u81ea\u5efa MCP \u4f3a\u670d\u5668\u524d\uff0c\u9700\u8981\u5148\u6e96\u5099\u597d <strong>\u672c\u5730 C++ \u7de8\u8b6f\u5668<\/strong>\uff08\u5982 <code>g++<\/code> \u6216 <code>cmake<\/code>\uff0c\u4e26\u78ba\u4fdd\u5728\u7cfb\u7d71 PATH \u4e2d\uff09\uff0c\u4ee5\u53ca <strong>\u958b\u767c\u5de5\u5177<\/strong>\uff08\u5efa\u8b70\u4f7f\u7528 VS Code\uff0c\u53ef\u5b89\u88dd <a href=\"https:\/\/saludpcb.com\/zh\/ai-agent-vscode-model-coding-assistant-ollama\/\">Continue<\/a> \u63d2\u4ef6\uff0c\u63d0\u4f9b\u8a9e\u6cd5\u88dc\u5168\u3001\u7a0b\u5f0f\u78bc\u5c0e\u822a\u8207\u7de8\u8f2f\u4fbf\u5229\uff09\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u4f86\uff0c\u5efa\u7acb MCP \u4f3a\u670d\u5668\u5c08\u6848\u7684\u57fa\u672c\u6b65\u9a5f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b89\u88dd Node.js<\/strong><\/li>\n<\/ul>\n\n\n\n<p>Node.js \u662f MCP \u4f3a\u670d\u5668\u904b\u884c\u7684\u6838\u5fc3\u74b0\u5883\uff0c\u5efa\u8b70\u5b89\u88dd <strong>LTS\uff08Long Term Support\uff09\u7248\u672c<\/strong>\uff0c\u4ee5\u78ba\u4fdd\u7a69\u5b9a\u6027\u3002<\/p>\n\n\n\n<p>\u5b98\u65b9\u4e0b\u8f09\uff1a<a href=\"https:\/\/nodejs.org\/\" target=\"_blank\" rel=\"noopener\">Node<\/a><\/p>\n\n\n\n<p>\u5b89\u88dd Node.js \u5f8c\uff0c\u5728\u7d42\u7aef\u8f38\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">node -v\nnpm -v\nnpx -v<\/code><\/pre>\n\n\n\n<p>\u82e5\u4e09\u8005\u90fd\u80fd\u6b63\u5e38\u986f\u793a\u7248\u672c\u865f\uff08\u4f8b\u5982 v18.x.x\u3001v10.x.x \u7b49\uff09\uff0c\u4ee3\u8868 Node.js\u3001npm\u3001npx \u90fd\u5df2\u6210\u529f\u5b89\u88dd\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5efa\u7acb\u5c08\u6848\u8cc7\u6599\u593e<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u5efa\u8b70\u5efa\u7acb\u7368\u7acb\u8cc7\u6599\u593e\u7ba1\u7406\u5c08\u6848\uff0c\u4f8b\u5982\uff1a<code>cpp-mcp<\/code>\uff0c\u65b9\u4fbf\u7d44\u7e54\u4ee3\u78bc\u8207\u4f9d\u8cf4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">mkdir cpp-mcp\ncd cpp-mcp<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u521d\u59cb\u5316 Node \u5c08\u6848<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><code>npm init -y<\/code><\/code><\/pre>\n\n\n\n<p>\u9019\u500b\u6307\u4ee4\u6703\u751f\u6210 <code>package.json<\/code> \u6587\u4ef6\uff0c\u7528\u65bc\u7ba1\u7406\u5c08\u6848\u4f9d\u8cf4\u3001\u7248\u672c\u8207\u8173\u672c\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b89\u88dd MCP SDK<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><code>install @modelcontextprotocol\/sdk<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5be6\u6230\u958b\u59cb\uff1a\u6253\u9020\u4f60\u7684-c-mcp-server\">\u5be6\u6230\u958b\u59cb\uff1a\u6253\u9020\u4f60\u7684 C++ MCP \u4f3a\u670d\u5668<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u5c08\u6848\u76ee\u9304\u4e2d\u5efa\u7acb\u00a0<code>server.js<\/code>\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">import { Server } from \"@modelcontextprotocol\/sdk\/server\/index.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol\/sdk\/server\/stdio.js\";\nimport { CallToolRequestSchema, ListToolsRequestSchema } from \"@modelcontextprotocol\/sdk\/types.js\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { execSync } from \"child_process\";\n\nconsole.error(\"\ud83d\ude80 Starting C++ MCP Server...\");\n\n\/\/ Define available tools\nconst tools = [\n  {\n    name: \"write_file_proxy\",\n    description: \"Write content to file\",\n    inputSchema: {\n      type: \"object\",\n      properties: {\n        path: { type: \"string\" },\n        content: { type: \"string\" },\n        mode: { \n          type: \"string\", \n          enum: [\"overwrite\", \"append\", \"error\"],\n          default: \"overwrite\" \n        },\n      },\n      required: [\"path\", \"content\"],\n    },\n  },\n  {\n    name: \"compile_and_run\",\n    description: \"Compile and run a C++ file\",\n    inputSchema: {\n      type: \"object\",\n      properties: {\n        path: { type: \"string\" },\n      },\n      required: [\"path\"],\n    },\n  }\n];\n\n\/\/ Create MCP server instance\nconst server = new Server(\n  {\n    name: \"cpp-ai-proxy\",\n    version: \"1.0.0\",\n  },\n  {\n    capabilities: {\n      tools: {},\n    },\n  }\n);\n\n\/\/ Handle tool listing requests\nserver.setRequestHandler(ListToolsRequestSchema, async () => {\n  console.error(\"\ud83d\udccb Listing tools...\");\n  return {\n    tools: tools\n  };\n});\n\n\/\/ Handle tool execution requests\nserver.setRequestHandler(CallToolRequestSchema, async (request) => {\n  console.error(`\ud83d\udd27 Tool called: ${request.params.name}`);\n  const { name, arguments: args } = request.params;\n  \n  if (name === \"write_file_proxy\") {\n    const { path: filePath, content, mode = \"overwrite\" } = args;\n    const absPath = path.resolve(filePath);\n    \n    try {\n      \/\/ Check if file exists and handle based on mode\n      if (fs.existsSync(absPath) &amp;&amp; mode === \"error\") {\n        return {\n          content: [{ type: \"text\", text: `\u274c File exists: ${absPath}` }]\n        };\n      }\n      \n      \/\/ Create directory if it doesn't exist\n      const dir = path.dirname(absPath);\n      if (!fs.existsSync(dir)) {\n        fs.mkdirSync(dir, { recursive: true });\n      }\n      \n      \/\/ Write or append content based on mode\n      if (fs.existsSync(absPath) &amp;&amp; mode === \"append\") {\n        fs.appendFileSync(absPath, content, \"utf8\");\n      } else {\n        fs.writeFileSync(absPath, content, \"utf8\");\n      }\n      \n      return {\n        content: [{ type: \"text\", text: `\u2705 File written: ${absPath}` }]\n      };\n    } catch (error) {\n      return {\n        content: [{ type: \"text\", text: `\u274c Error: ${error.message}` }]\n      };\n    }\n  }\n  \n  if (name === \"compile_and_run\") {\n    const { path: filePath } = args;\n    const absPath = path.resolve(filePath);\n    \n    try {\n      \/\/ Check if source file exists\n      if (!fs.existsSync(absPath)) {\n        return {\n          content: [{ type: \"text\", text: `\u274c File not found: ${absPath}` }]\n        };\n      }\n      \n      \/\/ Compile C++ code\n      const exePath = absPath.replace(\/\\.cpp$\/, \"\");\n      console.error(`\ud83d\udee0\ufe0f Compiling: ${absPath}`);\n      execSync(`g++ \"${absPath}\" -o \"${exePath}\"`, { stdio: 'pipe' });\n      \n      \/\/ Execute the compiled program\n      console.error(`\ud83d\ude80 Running: ${exePath}`);\n      const output = execSync(`\"${exePath}\"`, { encoding: \"utf8\", stdio: 'pipe' });\n      \n      return {\n        content: [{ type: \"text\", text: `\u2705 Output:\\n${output}` }]\n      };\n    } catch (error) {\n      \/\/ Extract meaningful error information\n      const errorOutput = error.stderr ? error.stderr.toString() : error.message;\n      return {\n        content: [{ type: \"text\", text: `\u274c Compilation or execution failed:\\n${errorOutput}` }]\n      };\n    }\n  }\n  \n  \/\/ Handle unknown tools\n  throw new Error(`Unknown tool: ${name}`);\n});\n\n\/\/ Global error handler for the server\nserver.onerror = (error) => {\n  console.error('\u274c Server error:', error);\n};\n\n\/\/ Connection close handler\nserver.onclose = () => {\n  console.error('\ud83d\udd0c Server connection closed');\n};\n\n\/\/ Main server startup function\nasync function main() {\n  try {\n    console.error(\"\ud83d\udce1 Connecting to transport...\");\n    const transport = new StdioServerTransport();\n    await server.connect(transport);\n    console.error(\"\u2705 C++ MCP Server running and connected!\");\n  } catch (error) {\n    console.error('\ud83d\udca5 Failed to start server:', error);\n    process.exit(1);\n  }\n}\n\n\/\/ Start the server\nmain().catch(console.error);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u914d\u7f6e VSCode \u8207 Continue \u63d2\u4ef6<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u5728\u5275\u5efa\u7684\u76ee\u9304\u4e2d\u5982 cpp-mcp\/.continue\/mcpServers \u65b0\u5efa <strong>new-mcp-server.yaml<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">name: New MCP server\nversion: 0.0.1\nschema: v1\nmcpServers:\n  - name: New MCP server\n    command: npx\n    args:\n      - -y\n      - node\n      - Your\/cpp-mcp\/server.js<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5c08\u6848\u7d50\u69cb\">\u5c08\u6848\u7d50\u69cb<\/h2>\n\n\n\n<p>C++ MCP Server \u5c08\u6848\u7d50\u69cb\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">cpp-mcp\/\n\u251c\u2500\u2500 .continue\/          # VSCode Continue \u63d2\u4ef6\u914d\u7f6e\u76ee\u9304\n\u251c\u2500\u2500 node_modules\/       # Node.js \u4f9d\u8cf4\u5305\uff08\u81ea\u52d5\u751f\u6210\uff09\n\u251c\u2500\u2500 package.json        # \u5c08\u6848\u914d\u7f6e\u548c\u4f9d\u8cf4\u5b9a\u7fa9\n\u251c\u2500\u2500 package-lock.json   # \u4f9d\u8cf4\u7248\u672c\u9396\u5b9a\u6587\u4ef6\n\u251c\u2500\u2500 server.js           # MCP \u4f3a\u670d\u5668\u4e3b\u7a0b\u5f0f\n\u251c\u2500\u2500 test                # \u7de8\u8b6f\u5f8c\u7684\u53ef\u57f7\u884c\u6587\u4ef6\n\u2514\u2500\u2500 test.cpp           # C++ \u6e2c\u8a66\u6e90\u78bc\u6587\u4ef6<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6e2c\u8a66\u4f60\u7684-mcp-server-1\">\u6e2c\u8a66 C++ MCP<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u555f\u52d5\u4f3a\u670d\u5668<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">node server.js<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5728 VSCode \u4e2d\u6e2c\u8a66<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<p>\u6253\u958b Continue \u804a\u5929\u9762\u677f\uff0c\u5617\u8a66\u4ee5\u4e0b\u6307\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">\u8acb\u5e6b\u6211\u5275\u5efa\u4e00\u500b\u7c21\u55ae\u7684 Hello World C++ \u7a0b\u5e8f\uff0c\u7136\u5f8c\u7de8\u8b6f\u4e26\u904b\u884c\u5b83<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>AI \u5c07\u6703\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">1. \u81ea\u52d5\u5275\u5efa C++ \u6e90\u78bc\u6587\u4ef6\n2. \u8abf\u7528\u00a0compile_cpp\u00a0\u5de5\u5177\u9032\u884c\u7de8\u8b6f\n3. \u4f7f\u7528\u00a0run_executable\u00a0\u5de5\u5177\u904b\u884c\u7a0b\u5e8f\n4. \u8fd4\u56de\u5b8c\u6574\u7684\u57f7\u884c\u7d50\u679c<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u8aaa\">\u8aaa\u660e <code>server.js<\/code> <\/h2>\n\n\n\n<p>\u4e00\u500b\u8b93 AI \u80fd\u5920<strong>\u5be6\u969b\u64cd\u4f5c\u6587\u4ef6\u548c\u904b\u884c C++ \u4ee3\u78bc<\/strong>\u7684\u6a4b\u6a11\u7a0b\u5f0f\u3002<\/p>\n\n\n\n<p><strong>\u5169\u500b\u4e3b\u8981\u529f\u80fd\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5beb\u6a94\u6848\u5de5\u5177<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">write_file_proxy({\n    path: \"test.cpp\",\n    content: \"C++ code\",\n    mode: \"overwrite\" \/\/ overwrite\/append\/error\n})<\/code><\/pre>\n\n\n\n<p>\u5275\u5efa\u6216\u4fee\u6539\u6587\u4ef6\uff0c\u81ea\u52d5\u5efa\u7acb\u8cc7\u6599\u593e\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7de8\u8b6f\u57f7\u884c\u5de5\u5177<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">compile_and_run({\n    path: \"test.cpp\"\n})<\/code><\/pre>\n\n\n\n<p>\u81ea\u52d5\u7de8\u8b6f C++ \u4e26\u904b\u884c\uff0c\u8fd4\u56de\u57f7\u884c\u7d50\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">\/\/ AI \u53ef\u4ee5\u9019\u6a23\u4f7f\u7528\u6211\uff1a\n1. \"\u8acb\u5275\u5efa\u4e00\u500b hello.cpp \u6587\u4ef6\uff0c\u5167\u5bb9\u662f Hello World \u7a0b\u5e8f\"\n   \u2192 \u8abf\u7528 write_file_proxy \u5de5\u5177\n\n2. \"\u8acb\u7de8\u8b6f\u4e26\u904b\u884c hello.cpp\"\n   \u2192 \u8abf\u7528 compile_and_run \u5de5\u5177\n\n3. \u7372\u5f97\u7d50\u679c\uff1a\"\u2705 Output: Hello World!\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7d50\u8ad6-1\">\u7d50\u8ad6<\/h2>\n\n\n\n<p><strong>MCP Server<\/strong> \u7684\u51fa\u73fe\uff0c\u8b93 AI \u4e0d\u518d\u53ea\u662f\u88ab\u52d5\u7684\u4ee3\u78bc\u751f\u6210\u5668\uff0c\u800c\u662f\u771f\u6b63\u80fd\u300c\u53c3\u8207\u300d\u958b\u767c\u6d41\u7a0b\u7684\u667a\u80fd\u5925\u4f34\u3002\u5c0d C++ \u958b\u767c\u8005\u800c\u8a00\uff0c\u5b83\u4e0d\u50c5\u80fd\u7406\u89e3\u7a0b\u5f0f\u8a9e\u610f\uff0c\u66f4\u80fd\u5be6\u969b\u64cd\u4f5c\u7de8\u8b6f\u5668\u3001\u57f7\u884c\u6e2c\u8a66\u3001\u5206\u6790\u932f\u8aa4\uff0c\u8b93\u958b\u767c\u5f9e\u5c0d\u8a71\u8d70\u5411\u884c\u52d5\u3002<\/p>\n\n\n\n<p>\u900f\u904e\u81ea\u5efa MCP \u4f3a\u670d\u5668\u4e26\u6574\u5408 VS Code \u7684 Continue \u63d2\u4ef6\uff0cAI \u52a9\u624b\u7d42\u65bc\u80fd\u76f4\u63a5\u8207\u4f60\u7684\u5c08\u6848\u74b0\u5883\u4e92\u52d5\u3002\u5f9e\u7de8\u8b6f\u3001\u8abf\u8a66\u5230\u5206\u6790\u932f\u8aa4\uff0c\u5168\u7a0b\u81ea\u52d5\u5316\u8207\u5373\u6642\u56de\u994b\uff0c\u8b93\u958b\u767c\u9ad4\u9a57\u66f4\u6d41\u66a2\u3001\u66f4\u8cbc\u8fd1\u771f\u5be6\u5de5\u7a0b\u5834\u666f\u3002<\/p>\n\n\n\n<p>\u9019\u53ea\u662f\u958b\u59cb\u3002\u672a\u4f86\u4f60\u53ef\u4ee5\u64f4\u5145 MCP \u4f3a\u670d\u5668\uff0c\u6574\u5408\u66f4\u591a\u5de5\u5177\u5982\u55ae\u5143\u6e2c\u8a66\u3001\u975c\u614b\u5206\u6790\u6216\u6027\u80fd\u76e3\u63a7\uff0c<br>\u8b93 AI \u6210\u70ba\u5718\u968a\u958b\u767c\u4e2d\u7684\u6838\u5fc3\u52a9\u529b\uff0c\u4e00\u4f4d\u6c38\u4e0d\u75b2\u5026\u7684 C++ \u5925\u4f34\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator alignwide has-text-color has-palette-color-1-color has-alpha-channel-opacity has-palette-color-1-background-color has-background is-style-wide\"\/>\n","protected":false},"excerpt":{"rendered":"<p>MCP Server \u2014 \u96d6\u7136\u807d\u8d77\u4f86\u5f88\u6280\u8853\u6027\uff0c\u4f46\u5b83\u6b63\u5728\u6084\u6084\u6539\u8b8a\u6211\u5011\u8207 AI \u7684\u4e92\u52d5\u65b9\u5f0f\u3002\u56de\u60f3\u4f60\u7b2c\u4e00\u6b21\u4f7f\u7528 AI [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4059,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93],"tags":[92,27,21,91,44,9,86,11],"class_list":["post-4047","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","tag-ai","tag-c","tag-ide","tag-ollama","tag-programming-language","tag-python","tag-rtos","tag-tutorial"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/4047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/comments?post=4047"}],"version-history":[{"count":19,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/4047\/revisions"}],"predecessor-version":[{"id":4076,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/4047\/revisions\/4076"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/media\/4059"}],"wp:attachment":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/media?parent=4047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/categories?post=4047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/tags?post=4047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}