You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Copilot无法正确调用自定义MCP工具问题求助

GitHub Copilot无法正确调用自定义MCP工具问题求助

问题背景

我正在用TypeScript开发一个简单的MCP(Model Context Protocol)服务器,核心需求是:在GitHub Copilot聊天窗口输入hello后,能触发我定义的hello工具,返回预期的“Hello, World!”响应。

我的实现代码

服务器核心代码(src/index.ts)

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import * as dotenv from "dotenv";

dotenv.config();

const server = new McpServer({
  name: "hello-world-mcp-server",
  version: "1.0.0",
  capabilities: {
    tools: {
      hello: {
        description: "Gibt Hello, World! zurück",
        parameters: {
          type: "object",
          properties: {},
          required: []
        },
        handler: async (params: {}, context: any) => {
          return {
            role: "assistant",
            content: "Hello, World!"
          };
        }
      }
    }
  }
});

async function startServer() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
}

startServer().catch(console.error);

MCP配置文件

{
  "servers": {
    "hello-world-mcp-server": {
      "type": "stdio",
      "command": "npx",
      "args": ["ts-node", "src/index.ts"],
      "cwd": "C:/Users/admin/InternshipTasks/hello-world-mcp-server"
    }
  }
}

遇到的问题

服务器能正常启动,在Copilot聊天中触发工具后,没有返回预期的“Hello, World!”,Copilot只返回了'mcp/hello'这个标识,完全看不到我在handler里定义的响应内容。

我已经尝试过的方案

  • 调整content的格式:试过直接传字符串,也试过传数组形式的内容(比如[{ type: "text", text: "Hello, World!" }])
  • 在handler函数里添加console.log,确认handler确实被触发了(日志能正常输出)
  • 两种运行方式对比:直接用ts-node src/index.ts启动,和先通过tsc编译成JS再启动
  • 完全重启GitHub Copilot客户端,排除缓存或进程残留的问题

求助

有没有朋友遇到过类似的问题?为什么Copilot不返回我在handler里定义的响应内容,反而只返回工具标识mcp/hello?应该怎么调整代码或配置才能让它正确返回“Hello, World!”?


内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 08:09:52